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; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 26 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 27 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 28 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 29 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 30 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 31 | 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] | 32 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 33 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 34 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 35 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 36 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 37 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 38 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 40 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 41 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 42 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 43 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 44 | import android.compat.annotation.ChangeId; |
| 45 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 46 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 47 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 48 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.content.Context; |
| 50 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 51 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 52 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 53 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.net.Uri; |
| 55 | import android.os.AsyncResult; |
| 56 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 57 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 59 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 61 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 62 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 63 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.Looper; |
| 65 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 66 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 67 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 68 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 69 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 70 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 71 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 72 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 73 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 74 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 76 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 78 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 79 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 80 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 81 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 82 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 83 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 84 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 85 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 86 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 87 | import android.telephony.AccessNetworkConstants; |
| 88 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 89 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 90 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 91 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 92 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 93 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 94 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 95 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 96 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 97 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 98 | import android.telephony.CellIdentityCdma; |
| 99 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 101 | import android.telephony.CellInfoGsm; |
| 102 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 103 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 104 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 105 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 106 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 107 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 108 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 109 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 110 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 112 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 113 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 114 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 115 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 117 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 118 | import android.telephony.SignalStrengthUpdateRequest; |
| 119 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 120 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 121 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 122 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 123 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 124 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 125 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 126 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 127 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 128 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 129 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 130 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 131 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 132 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 133 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 134 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 135 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 136 | import android.telephony.gba.GbaAuthRequest; |
| 137 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 138 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 139 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 140 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 141 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 142 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 145 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 146 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 147 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 150 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 151 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 152 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 153 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 154 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 156 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 157 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 158 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 159 | import android.telephony.satellite.NtnSignalStrength; |
| 160 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 162 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 163 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 164 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 165 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 167 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 168 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 169 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 170 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 171 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 172 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 173 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 174 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 175 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 190 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 207 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 208 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 210 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.SmsPermissions; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 213 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 216 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 217 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 220 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 221 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 222 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 223 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 224 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 225 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 227 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 229 | import com.android.internal.telephony.uicc.IccIoResult; |
| 230 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 231 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 232 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 233 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 234 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 235 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 236 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 238 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 239 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 240 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 241 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 242 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 243 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 244 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 245 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 246 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 247 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 248 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 249 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 250 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 251 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 252 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 253 | import com.android.services.telephony.TelecomAccountRegistry; |
| 254 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 255 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 256 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 257 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 258 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 259 | import java.io.IOException; |
| 260 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 261 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 262 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 263 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 264 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 265 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 266 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 267 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 268 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 269 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 270 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 271 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 272 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 273 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 274 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 275 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 276 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 277 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 278 | |
| 279 | /** |
| 280 | * Implementation of the ITelephony interface. |
| 281 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 282 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 283 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 284 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 285 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 286 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 287 | |
| 288 | // Message codes used with mMainThreadHandler |
| 289 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 290 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 291 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 292 | private static final int CMD_OPEN_CHANNEL = 9; |
| 293 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 294 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 295 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 296 | private static final int CMD_NV_READ_ITEM = 13; |
| 297 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 298 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 299 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 300 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 301 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 302 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 303 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 304 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 305 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 306 | private static final int CMD_SEND_ENVELOPE = 25; |
| 307 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 308 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 309 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 310 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 311 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 312 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 313 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 314 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 315 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 316 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 317 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 318 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 319 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 320 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 321 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 322 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 323 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 324 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 325 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 326 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 327 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 328 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 329 | private static final int CMD_SWITCH_SLOTS = 50; |
| 330 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 331 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 332 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 333 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 334 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 335 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 336 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 337 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 338 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 339 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 340 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 341 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 342 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 343 | private static final int CMD_MODEM_REBOOT = 64; |
| 344 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 345 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 346 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 347 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 348 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 349 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 350 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 351 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 352 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 353 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 354 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 355 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 356 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 357 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 358 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 359 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 360 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 361 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 362 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 363 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 364 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 365 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 366 | private static final int CMD_GET_CALL_WAITING = 87; |
| 367 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 368 | private static final int CMD_SET_CALL_WAITING = 89; |
| 369 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 370 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 371 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 372 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 373 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 374 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 375 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 376 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 377 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 378 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 379 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 380 | private static final int CMD_SET_SIM_POWER = 101; |
| 381 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 382 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 383 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 384 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 385 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 386 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 387 | 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] | 388 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 389 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 390 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 391 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 392 | private static final int CMD_ENABLE_VONR = 113; |
| 393 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 394 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 395 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 396 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 397 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 398 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 399 | // Parameters of select command. |
| 400 | private static final int SELECT_COMMAND = 0xA4; |
| 401 | private static final int SELECT_P1 = 0x04; |
| 402 | private static final int SELECT_P2 = 0; |
| 403 | private static final int SELECT_P3 = 0x10; |
| 404 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 405 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 406 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 407 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 408 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 409 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | /** The singleton instance. */ |
| 411 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 412 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 413 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 414 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 415 | private FeatureFlags mFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 416 | private final CallManager mCM; |
| 417 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 418 | |
| 419 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 420 | private final UserManager mUserManager; |
| 421 | private final AppOpsManager mAppOps; |
| 422 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 423 | private final SharedPreferences mTelephonySharedPreferences; |
| 424 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 425 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 426 | private PackageManager mPackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 428 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 429 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 430 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 431 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 432 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 433 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 434 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 435 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 436 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 437 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 438 | // String to store multi SIM allowed |
| 439 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 440 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 441 | // The AID of ISD-R. |
| 442 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 443 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 444 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 445 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 446 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 447 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 448 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 449 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 450 | 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] | 451 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 452 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 453 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 454 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 455 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 456 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 457 | */ |
| 458 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 459 | "reset_network_erase_modem_config_enabled"; |
| 460 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 461 | 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] | 462 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 463 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 464 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 465 | /** |
| 466 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 467 | * one ICCID active at the same time. |
| 468 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 469 | * |
| 470 | * @hide |
| 471 | */ |
| 472 | @ChangeId |
| 473 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 474 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 475 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 476 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 477 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 478 | * operation fails. |
| 479 | */ |
| 480 | @ChangeId |
| 481 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 482 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 483 | |
| 484 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 485 | * A request object to use for transmitting data to an ICC. |
| 486 | */ |
| 487 | private static final class IccAPDUArgument { |
| 488 | public int channel, cla, command, p1, p2, p3; |
| 489 | public String data; |
| 490 | |
| 491 | public IccAPDUArgument(int channel, int cla, int command, |
| 492 | int p1, int p2, int p3, String data) { |
| 493 | this.channel = channel; |
| 494 | this.cla = cla; |
| 495 | this.command = command; |
| 496 | this.p1 = p1; |
| 497 | this.p2 = p2; |
| 498 | this.p3 = p3; |
| 499 | this.data = data; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 504 | * A request object to use for transmitting data to an ICC. |
| 505 | */ |
| 506 | private static final class ManualNetworkSelectionArgument { |
| 507 | public OperatorInfo operatorInfo; |
| 508 | public boolean persistSelection; |
| 509 | |
| 510 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 511 | this.operatorInfo = operatorInfo; |
| 512 | this.persistSelection = persistSelection; |
| 513 | } |
| 514 | } |
| 515 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 516 | private static final class PurchasePremiumCapabilityArgument { |
| 517 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 518 | public @NonNull IIntegerConsumer callback; |
| 519 | |
| 520 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 521 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 522 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 523 | this.callback = callback; |
| 524 | } |
| 525 | } |
| 526 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 527 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 528 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 529 | * request after sending. The main thread will notify the request when it is complete. |
| 530 | */ |
| 531 | private static final class MainThreadRequest { |
| 532 | /** The argument to use for the request */ |
| 533 | public Object argument; |
| 534 | /** The result of the request that is run on the main thread */ |
| 535 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 536 | // The subscriber id that this request applies to. Defaults to |
| 537 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 538 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 540 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 541 | public Phone phone; |
| 542 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 543 | public WorkSource workSource; |
| 544 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 545 | public MainThreadRequest(Object argument) { |
| 546 | this.argument = argument; |
| 547 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 548 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 549 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 550 | this.argument = argument; |
| 551 | if (phone != null) { |
| 552 | this.phone = phone; |
| 553 | } |
| 554 | this.workSource = workSource; |
| 555 | } |
| 556 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 557 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 558 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 559 | if (subId != null) { |
| 560 | this.subId = subId; |
| 561 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 562 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 566 | private static final class IncomingThirdPartyCallArgs { |
| 567 | public final ComponentName component; |
| 568 | public final String callId; |
| 569 | public final String callerDisplayName; |
| 570 | |
| 571 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 572 | String callerDisplayName) { |
| 573 | this.component = component; |
| 574 | this.callId = callId; |
| 575 | this.callerDisplayName = callerDisplayName; |
| 576 | } |
| 577 | } |
| 578 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 579 | /** |
| 580 | * A handler that processes messages on the main thread in the phone process. Since many |
| 581 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 582 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 583 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 584 | * on, which will be notified when the operation completes and will contain the result of the |
| 585 | * request. |
| 586 | * |
| 587 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 588 | * note that request.result must be set to something non-null for the calling thread to |
| 589 | * unblock. |
| 590 | */ |
| 591 | private final class MainThreadHandler extends Handler { |
| 592 | @Override |
| 593 | public void handleMessage(Message msg) { |
| 594 | MainThreadRequest request; |
| 595 | Message onCompleted; |
| 596 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 597 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 598 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 599 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 600 | |
| 601 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | case CMD_HANDLE_USSD_REQUEST: { |
| 603 | request = (MainThreadRequest) msg.obj; |
| 604 | final Phone phone = getPhoneFromRequest(request); |
| 605 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 606 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 607 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 608 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 609 | if (!isUssdApiAllowed(request.subId)) { |
| 610 | // Carrier does not support use of this API, return failure. |
| 611 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 612 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 613 | Bundle returnData = new Bundle(); |
| 614 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 615 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 616 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | request.result = true; |
| 618 | notifyRequester(request); |
| 619 | return; |
| 620 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 621 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 622 | try { |
| 623 | request.result = phone != null |
| 624 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 625 | } catch (CallStateException cse) { |
| 626 | request.result = false; |
| 627 | } |
| 628 | // Wake up the requesting thread |
| 629 | notifyRequester(request); |
| 630 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 633 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 634 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 635 | final Phone phone = getPhoneFromRequest(request); |
| 636 | request.result = phone != null ? |
| 637 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 638 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 639 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 640 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 641 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 642 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 643 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 647 | uiccPort = getUiccPortFromRequest(request); |
| 648 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 649 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 650 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 651 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 652 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 653 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 654 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 655 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 656 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 657 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 658 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 659 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | break; |
| 661 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 662 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | ar = (AsyncResult) msg.obj; |
| 664 | request = (MainThreadRequest) ar.userObj; |
| 665 | if (ar.exception == null && ar.result != null) { |
| 666 | request.result = ar.result; |
| 667 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 668 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | if (ar.result == null) { |
| 670 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 671 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 673 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | } else { |
| 675 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 676 | } |
| 677 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 678 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | break; |
| 680 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 682 | request = (MainThreadRequest) msg.obj; |
| 683 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 684 | uiccPort = getUiccPortFromRequest(request); |
| 685 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 686 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 687 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 688 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 689 | } else { |
| 690 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 691 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 692 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 693 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 694 | iccArgument.p2, |
| 695 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 696 | } |
| 697 | break; |
| 698 | |
| 699 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 700 | ar = (AsyncResult) msg.obj; |
| 701 | request = (MainThreadRequest) ar.userObj; |
| 702 | if (ar.exception == null && ar.result != null) { |
| 703 | request.result = ar.result; |
| 704 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 705 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | if (ar.result == null) { |
| 707 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 708 | } else if (ar.exception instanceof CommandException) { |
| 709 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 710 | ar.exception); |
| 711 | } else { |
| 712 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 713 | } |
| 714 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 715 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 716 | break; |
| 717 | |
| 718 | case CMD_EXCHANGE_SIM_IO: |
| 719 | request = (MainThreadRequest) msg.obj; |
| 720 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 721 | uiccPort = getUiccPortFromRequest(request); |
| 722 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 723 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 724 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 725 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 726 | } else { |
| 727 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 728 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 729 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 730 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 731 | iccArgument.data, onCompleted); |
| 732 | } |
| 733 | break; |
| 734 | |
| 735 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 736 | ar = (AsyncResult) msg.obj; |
| 737 | request = (MainThreadRequest) ar.userObj; |
| 738 | if (ar.exception == null && ar.result != null) { |
| 739 | request.result = ar.result; |
| 740 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 741 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 742 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 744 | break; |
| 745 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 746 | case CMD_SEND_ENVELOPE: |
| 747 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 748 | uiccPort = getUiccPortFromRequest(request); |
| 749 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 750 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 751 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 753 | } else { |
| 754 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 755 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 756 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 757 | break; |
| 758 | |
| 759 | case EVENT_SEND_ENVELOPE_DONE: |
| 760 | ar = (AsyncResult) msg.obj; |
| 761 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 762 | if (ar.exception == null && ar.result != null) { |
| 763 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 764 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 765 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 766 | if (ar.result == null) { |
| 767 | loge("sendEnvelopeWithStatus: Empty response"); |
| 768 | } else if (ar.exception instanceof CommandException) { |
| 769 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 770 | ar.exception); |
| 771 | } else { |
| 772 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 773 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 774 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 775 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 776 | break; |
| 777 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 778 | case CMD_OPEN_CHANNEL: |
| 779 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 780 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 781 | IccLogicalChannelRequest openChannelRequest = |
| 782 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 783 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 784 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 785 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 786 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 787 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 788 | } else { |
| 789 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 790 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 791 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 792 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 793 | break; |
| 794 | |
| 795 | case EVENT_OPEN_CHANNEL_DONE: |
| 796 | ar = (AsyncResult) msg.obj; |
| 797 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 798 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 799 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 800 | int[] result = (int[]) ar.result; |
| 801 | int channelId = result[0]; |
| 802 | byte[] selectResponse = null; |
| 803 | if (result.length > 1) { |
| 804 | selectResponse = new byte[result.length - 1]; |
| 805 | for (int i = 1; i < result.length; ++i) { |
| 806 | selectResponse[i - 1] = (byte) result[i]; |
| 807 | } |
| 808 | } |
| 809 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 810 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 811 | |
| 812 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 813 | if (uiccPort == null) { |
| 814 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 815 | } else { |
| 816 | IccLogicalChannelRequest channelRequest = |
| 817 | (IccLogicalChannelRequest) request.argument; |
| 818 | channelRequest.channel = channelId; |
| 819 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 820 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 821 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 822 | if (ar.result == null) { |
| 823 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 824 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 825 | if (ar.exception != null) { |
| 826 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 827 | } |
| 828 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 829 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 830 | if (ar.exception instanceof CommandException) { |
| 831 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 832 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 833 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 834 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 835 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 836 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 840 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 841 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 842 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 843 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 844 | break; |
| 845 | |
| 846 | case CMD_CLOSE_CHANNEL: |
| 847 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 848 | uiccPort = getUiccPortFromRequest(request); |
| 849 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 850 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 851 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 852 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 853 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 854 | } else { |
| 855 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 856 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 857 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 858 | break; |
| 859 | |
| 860 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 861 | ar = (AsyncResult) msg.obj; |
| 862 | request = (MainThreadRequest) ar.userObj; |
| 863 | if (ar.exception == null) { |
| 864 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 865 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 866 | if (uiccPort == null) { |
| 867 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 868 | } else { |
| 869 | final int channelId = (Integer) request.argument; |
| 870 | uiccPort.onLogicalChannelClosed(channelId); |
| 871 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 872 | } else { |
| 873 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 874 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 875 | if (ar.exception instanceof CommandException) { |
| 876 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 877 | CommandException.Error error = |
| 878 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 879 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 880 | // should only throw exceptions from the binder threads. |
| 881 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 882 | "iccCloseLogicalChannel: invalid argument "); |
| 883 | } |
| 884 | } else { |
| 885 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 886 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 887 | request.result = (exception != null) ? exception : |
| 888 | new IllegalStateException( |
| 889 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 890 | } |
| 891 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 892 | break; |
| 893 | |
| 894 | case CMD_NV_READ_ITEM: |
| 895 | request = (MainThreadRequest) msg.obj; |
| 896 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 897 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 898 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 899 | break; |
| 900 | |
| 901 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 902 | ar = (AsyncResult) msg.obj; |
| 903 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 904 | if (ar.exception == null && ar.result != null) { |
| 905 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 906 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 907 | request.result = ""; |
| 908 | if (ar.result == null) { |
| 909 | loge("nvReadItem: Empty response"); |
| 910 | } else if (ar.exception instanceof CommandException) { |
| 911 | loge("nvReadItem: CommandException: " + |
| 912 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 913 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 914 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 915 | } |
| 916 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 917 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 918 | break; |
| 919 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 920 | case CMD_NV_WRITE_ITEM: |
| 921 | request = (MainThreadRequest) msg.obj; |
| 922 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 923 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 924 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 925 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case EVENT_NV_WRITE_ITEM_DONE: |
| 929 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 930 | break; |
| 931 | |
| 932 | case CMD_NV_WRITE_CDMA_PRL: |
| 933 | request = (MainThreadRequest) msg.obj; |
| 934 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 935 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 936 | break; |
| 937 | |
| 938 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 939 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 940 | break; |
| 941 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 942 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 943 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 944 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 945 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 946 | break; |
| 947 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 948 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 949 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 950 | break; |
| 951 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 952 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 953 | request = (MainThreadRequest) msg.obj; |
| 954 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 955 | request); |
| 956 | Phone phone = getPhoneFromRequest(request); |
| 957 | if (phone != null) { |
| 958 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 959 | } else { |
| 960 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 961 | request.result = false; |
| 962 | notifyRequester(request); |
| 963 | } |
| 964 | break; |
| 965 | } |
| 966 | |
| 967 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 968 | ar = (AsyncResult) msg.obj; |
| 969 | request = (MainThreadRequest) ar.userObj; |
| 970 | if (ar.exception == null && ar.result != null) { |
| 971 | request.result = ar.result; |
| 972 | } else { |
| 973 | // request.result must be set to something non-null |
| 974 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 975 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 976 | request.result = ar.result; |
| 977 | } else { |
| 978 | request.result = false; |
| 979 | } |
| 980 | if (ar.result == null) { |
| 981 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 982 | } else if (ar.exception instanceof CommandException) { |
| 983 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 984 | + ar.exception); |
| 985 | } else { |
| 986 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 987 | } |
| 988 | } |
| 989 | notifyRequester(request); |
| 990 | break; |
| 991 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 992 | case CMD_IS_VONR_ENABLED: { |
| 993 | request = (MainThreadRequest) msg.obj; |
| 994 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 995 | request); |
| 996 | Phone phone = getPhoneFromRequest(request); |
| 997 | if (phone != null) { |
| 998 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 999 | } else { |
| 1000 | loge("isVoNrEnabled: No phone object"); |
| 1001 | request.result = false; |
| 1002 | notifyRequester(request); |
| 1003 | } |
| 1004 | break; |
| 1005 | } |
| 1006 | |
| 1007 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1008 | ar = (AsyncResult) msg.obj; |
| 1009 | request = (MainThreadRequest) ar.userObj; |
| 1010 | if (ar.exception == null && ar.result != null) { |
| 1011 | request.result = ar.result; |
| 1012 | } else { |
| 1013 | // request.result must be set to something non-null |
| 1014 | // for the calling thread to unblock |
| 1015 | if (ar.result != null) { |
| 1016 | request.result = ar.result; |
| 1017 | } else { |
| 1018 | request.result = false; |
| 1019 | } |
| 1020 | if (ar.result == null) { |
| 1021 | loge("isVoNrEnabled: Empty response"); |
| 1022 | } else if (ar.exception instanceof CommandException) { |
| 1023 | loge("isVoNrEnabled: CommandException: " |
| 1024 | + ar.exception); |
| 1025 | } else { |
| 1026 | loge("isVoNrEnabled: Unknown exception"); |
| 1027 | } |
| 1028 | } |
| 1029 | notifyRequester(request); |
| 1030 | break; |
| 1031 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1032 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1033 | request = (MainThreadRequest) msg.obj; |
| 1034 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1035 | Phone phone = getPhoneFromRequest(request); |
| 1036 | if (phone != null) { |
| 1037 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1038 | request.workSource); |
| 1039 | } else { |
| 1040 | loge("enableNrDualConnectivity: No phone object"); |
| 1041 | request.result = |
| 1042 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1043 | notifyRequester(request); |
| 1044 | } |
| 1045 | break; |
| 1046 | } |
| 1047 | |
| 1048 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1049 | ar = (AsyncResult) msg.obj; |
| 1050 | request = (MainThreadRequest) ar.userObj; |
| 1051 | if (ar.exception == null) { |
| 1052 | request.result = |
| 1053 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1054 | } else { |
| 1055 | request.result = |
| 1056 | TelephonyManager |
| 1057 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1058 | if (ar.exception instanceof CommandException) { |
| 1059 | CommandException.Error error = |
| 1060 | ((CommandException) (ar.exception)).getCommandError(); |
| 1061 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1062 | request.result = |
| 1063 | TelephonyManager |
| 1064 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1065 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1066 | request.result = |
| 1067 | TelephonyManager |
| 1068 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1069 | } |
| 1070 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1071 | + ar.exception); |
| 1072 | } else { |
| 1073 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1074 | } |
| 1075 | } |
| 1076 | notifyRequester(request); |
| 1077 | break; |
| 1078 | } |
| 1079 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1080 | case CMD_ENABLE_VONR: { |
| 1081 | request = (MainThreadRequest) msg.obj; |
| 1082 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1083 | Phone phone = getPhoneFromRequest(request); |
| 1084 | if (phone != null) { |
| 1085 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1086 | request.workSource); |
| 1087 | } else { |
| 1088 | loge("setVoNrEnabled: No phone object"); |
| 1089 | request.result = |
| 1090 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1091 | notifyRequester(request); |
| 1092 | } |
| 1093 | break; |
| 1094 | } |
| 1095 | |
| 1096 | case EVENT_ENABLE_VONR_DONE: { |
| 1097 | ar = (AsyncResult) msg.obj; |
| 1098 | request = (MainThreadRequest) ar.userObj; |
| 1099 | if (ar.exception == null) { |
| 1100 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1101 | } else { |
| 1102 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1103 | if (ar.exception instanceof CommandException) { |
| 1104 | CommandException.Error error = |
| 1105 | ((CommandException) (ar.exception)).getCommandError(); |
| 1106 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1107 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1108 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1109 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1110 | } else { |
| 1111 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1112 | } |
| 1113 | loge("setVoNrEnabled" + ": CommandException: " |
| 1114 | + ar.exception); |
| 1115 | } else { |
| 1116 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1117 | } |
| 1118 | } |
| 1119 | notifyRequester(request); |
| 1120 | break; |
| 1121 | } |
| 1122 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1123 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1124 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1125 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1126 | request); |
| 1127 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1128 | break; |
| 1129 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1130 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1131 | ar = (AsyncResult) msg.obj; |
| 1132 | request = (MainThreadRequest) ar.userObj; |
| 1133 | if (ar.exception == null && ar.result != null) { |
| 1134 | request.result = ar.result; // Integer |
| 1135 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1136 | // request.result must be set to something non-null |
| 1137 | // for the calling thread to unblock |
| 1138 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1139 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1140 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1141 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1142 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1143 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1144 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1145 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1146 | } |
| 1147 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1148 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1149 | break; |
| 1150 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1151 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1152 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1153 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1154 | request); |
| 1155 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1156 | (Pair<Integer, Long>) request.argument; |
| 1157 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1158 | reasonWithNetworkTypes.first, |
| 1159 | reasonWithNetworkTypes.second, |
| 1160 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1161 | break; |
| 1162 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1163 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1164 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1165 | break; |
| 1166 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1167 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1168 | request = (MainThreadRequest) msg.obj; |
| 1169 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1170 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1171 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1172 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1173 | break; |
| 1174 | |
| 1175 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1176 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1177 | break; |
| 1178 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1179 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1180 | request = (MainThreadRequest) msg.obj; |
| 1181 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1182 | request); |
| 1183 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1184 | break; |
| 1185 | |
| 1186 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1187 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1188 | break; |
| 1189 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1190 | case CMD_PERFORM_NETWORK_SCAN: |
| 1191 | request = (MainThreadRequest) msg.obj; |
| 1192 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1193 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1194 | break; |
| 1195 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1196 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1197 | request = (MainThreadRequest) msg.obj; |
| 1198 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1199 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1200 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1201 | request.argument; |
| 1202 | int callForwardingReason = args.first; |
| 1203 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1204 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1205 | } |
| 1206 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | ar = (AsyncResult) msg.obj; |
| 1208 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1210 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1211 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1212 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1215 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1216 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1217 | // any service for voice call. |
| 1218 | if ((callForwardInfo.serviceClass |
| 1219 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1220 | callForwardingInfo = new CallForwardingInfo( |
| 1221 | callForwardInfo.status |
| 1222 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | callForwardInfo.reason, |
| 1224 | callForwardInfo.number, |
| 1225 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | break; |
| 1227 | } |
| 1228 | } |
| 1229 | // Didn't find a call forward info for voice call. |
| 1230 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1232 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1234 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1235 | } else { |
| 1236 | if (ar.result == null) { |
| 1237 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1238 | } |
| 1239 | if (ar.exception != null) { |
| 1240 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1241 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1242 | int errorCode = TelephonyManager |
| 1243 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1244 | if (ar.exception instanceof CommandException) { |
| 1245 | CommandException.Error error = |
| 1246 | ((CommandException) (ar.exception)).getCommandError(); |
| 1247 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1248 | errorCode = TelephonyManager |
| 1249 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1251 | errorCode = TelephonyManager |
| 1252 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | } |
| 1254 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | request = (MainThreadRequest) msg.obj; |
| 1262 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1266 | request.argument).first; |
| 1267 | request.phone.setCallForwardingOption( |
| 1268 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1269 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1270 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1271 | callForwardingInfoToSet.getReason(), |
| 1272 | callForwardingInfoToSet.getNumber(), |
| 1273 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1274 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1278 | ar = (AsyncResult) msg.obj; |
| 1279 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | Consumer<Integer> callback = |
| 1281 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1282 | request.argument).second; |
| 1283 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1285 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1286 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1287 | if (ar.exception instanceof CommandException) { |
| 1288 | CommandException.Error error = |
| 1289 | ((CommandException) (ar.exception)).getCommandError(); |
| 1290 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1291 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1292 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1294 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1295 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | callback.accept(errorCode); |
| 1299 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1300 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1302 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1304 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | request = (MainThreadRequest) msg.obj; |
| 1307 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1308 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1309 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1311 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1313 | ar = (AsyncResult) msg.obj; |
| 1314 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1315 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1316 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1318 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1319 | // Service Class is a bit mask per 3gpp 27.007. |
| 1320 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1321 | if (callForwardResults.length > 1 |
| 1322 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1323 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1324 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1325 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1326 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1327 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1328 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | } |
| 1330 | } else { |
| 1331 | if (ar.result == null) { |
| 1332 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1333 | } |
| 1334 | if (ar.exception != null) { |
| 1335 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1336 | } |
| 1337 | if (ar.exception instanceof CommandException) { |
| 1338 | CommandException.Error error = |
| 1339 | ((CommandException) (ar.exception)).getCommandError(); |
| 1340 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1341 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1343 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1344 | callWaitingStatus = |
| 1345 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1349 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1351 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1352 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1353 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1354 | request = (MainThreadRequest) msg.obj; |
| 1355 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1356 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1357 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1358 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1359 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1361 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1362 | ar = (AsyncResult) msg.obj; |
| 1363 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1364 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1365 | Consumer<Integer> callback = |
| 1366 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1367 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1368 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1369 | if (ar.exception instanceof CommandException) { |
| 1370 | CommandException.Error error = |
| 1371 | ((CommandException) (ar.exception)).getCommandError(); |
| 1372 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1373 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1374 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1375 | callback.accept( |
| 1376 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1377 | } else { |
| 1378 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1379 | } |
| 1380 | } else { |
| 1381 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1382 | } |
| 1383 | } else { |
| 1384 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1385 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1386 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1387 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1388 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1389 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1390 | ar = (AsyncResult) msg.obj; |
| 1391 | request = (MainThreadRequest) ar.userObj; |
| 1392 | CellNetworkScanResult cellScanResult; |
| 1393 | if (ar.exception == null && ar.result != null) { |
| 1394 | cellScanResult = new CellNetworkScanResult( |
| 1395 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1396 | (List<OperatorInfo>) ar.result); |
| 1397 | } else { |
| 1398 | if (ar.result == null) { |
| 1399 | loge("getCellNetworkScanResults: Empty response"); |
| 1400 | } |
| 1401 | if (ar.exception != null) { |
| 1402 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1403 | } |
| 1404 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1405 | if (ar.exception instanceof CommandException) { |
| 1406 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1407 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1408 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1409 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1410 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1411 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1412 | } |
| 1413 | } |
| 1414 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1415 | } |
| 1416 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1417 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1418 | break; |
| 1419 | |
| 1420 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1421 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1422 | ManualNetworkSelectionArgument selArg = |
| 1423 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1424 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1425 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1426 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1427 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1428 | break; |
| 1429 | |
| 1430 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1431 | ar = (AsyncResult) msg.obj; |
| 1432 | request = (MainThreadRequest) ar.userObj; |
| 1433 | if (ar.exception == null) { |
| 1434 | request.result = true; |
| 1435 | } else { |
| 1436 | request.result = false; |
| 1437 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1438 | } |
| 1439 | notifyRequester(request); |
| 1440 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1441 | break; |
| 1442 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1443 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1444 | request = (MainThreadRequest) msg.obj; |
| 1445 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1446 | if (defaultPhone != null) { |
| 1447 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1448 | } else { |
| 1449 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1450 | Bundle bundle = new Bundle(); |
| 1451 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1452 | new ModemActivityInfo(0, 0, 0, |
| 1453 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1454 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1455 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1456 | break; |
| 1457 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1458 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1459 | ar = (AsyncResult) msg.obj; |
| 1460 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1461 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1462 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1463 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1464 | if (mLastModemActivityInfo == null) { |
| 1465 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1466 | mLastModemActivitySpecificInfo[0] = |
| 1467 | new ActivityStatsTechSpecificInfo( |
| 1468 | 0, |
| 1469 | 0, |
| 1470 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1471 | 0); |
| 1472 | mLastModemActivityInfo = |
| 1473 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1474 | } |
| 1475 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1476 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1477 | // Update the last modem activity info and the result of the request. |
| 1478 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1479 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1480 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1481 | } else { |
| 1482 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1483 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1484 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1485 | // We don't want to return mLastModemActivityInfo which is updated |
| 1486 | // inside mergeModemActivityInfo() |
| 1487 | ret = new ModemActivityInfo( |
| 1488 | mLastModemActivityInfo.getTimestampMillis(), |
| 1489 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1490 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1491 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1492 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1493 | } else { |
| 1494 | if (ar.result == null) { |
| 1495 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1496 | error = TelephonyManager.ModemActivityInfoException |
| 1497 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1498 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1499 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1500 | error = TelephonyManager.ModemActivityInfoException |
| 1501 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1502 | } else { |
| 1503 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1504 | error = TelephonyManager.ModemActivityInfoException |
| 1505 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1506 | } |
| 1507 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1508 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1509 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1510 | bundle.putParcelable( |
| 1511 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1512 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1513 | } else { |
| 1514 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1515 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1516 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1517 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1518 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1519 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1520 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1521 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1522 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1523 | CarrierRestrictionRules argument = |
| 1524 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1525 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1526 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1527 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1528 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1529 | |
| 1530 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1531 | ar = (AsyncResult) msg.obj; |
| 1532 | request = (MainThreadRequest) ar.userObj; |
| 1533 | if (ar.exception == null && ar.result != null) { |
| 1534 | request.result = ar.result; |
| 1535 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1536 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1537 | if (ar.exception instanceof CommandException) { |
| 1538 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1539 | CommandException.Error error = |
| 1540 | ((CommandException) (ar.exception)).getCommandError(); |
| 1541 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1542 | request.result = |
| 1543 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1544 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1545 | } else { |
| 1546 | loge("setAllowedCarriers: Unknown exception"); |
| 1547 | } |
| 1548 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1549 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1550 | break; |
| 1551 | |
| 1552 | case CMD_GET_ALLOWED_CARRIERS: |
| 1553 | request = (MainThreadRequest) msg.obj; |
| 1554 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1555 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1556 | break; |
| 1557 | |
| 1558 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1559 | ar = (AsyncResult) msg.obj; |
| 1560 | request = (MainThreadRequest) ar.userObj; |
| 1561 | if (ar.exception == null && ar.result != null) { |
| 1562 | request.result = ar.result; |
| 1563 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1564 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1565 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1566 | if (ar.result == null) { |
| 1567 | loge("getAllowedCarriers: Empty response"); |
| 1568 | } else if (ar.exception instanceof CommandException) { |
| 1569 | loge("getAllowedCarriers: CommandException: " + |
| 1570 | ar.exception); |
| 1571 | } else { |
| 1572 | loge("getAllowedCarriers: Unknown exception"); |
| 1573 | } |
| 1574 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1575 | if (request.argument != null) { |
| 1576 | // This is for the implementation of carrierRestrictionStatus. |
| 1577 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1578 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1579 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1580 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1581 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1582 | CarrierRestrictionRules carrierRestrictionRules = |
| 1583 | (CarrierRestrictionRules) ar.result; |
| 1584 | int carrierId = -1; |
| 1585 | try { |
| 1586 | CarrierIdentifier carrierIdentifier = |
| 1587 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1588 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1589 | carrierIdentifier); |
| 1590 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1591 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1592 | } |
| 1593 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1594 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1595 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1596 | lockStatus = TelephonyManager |
| 1597 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1598 | } |
| 1599 | } else { |
| 1600 | Rlog.e(LOG_TAG, |
| 1601 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1602 | } |
| 1603 | callback.accept(lockStatus); |
| 1604 | } else { |
| 1605 | // This is for the implementation of getAllowedCarriers. |
| 1606 | notifyRequester(request); |
| 1607 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1608 | break; |
| 1609 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1610 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1611 | ar = (AsyncResult) msg.obj; |
| 1612 | request = (MainThreadRequest) ar.userObj; |
| 1613 | if (ar.exception == null && ar.result != null) { |
| 1614 | request.result = ar.result; |
| 1615 | } else { |
| 1616 | request.result = new IllegalArgumentException( |
| 1617 | "Failed to retrieve Forbidden Plmns"); |
| 1618 | if (ar.result == null) { |
| 1619 | loge("getForbiddenPlmns: Empty response"); |
| 1620 | } else { |
| 1621 | loge("getForbiddenPlmns: Unknown exception"); |
| 1622 | } |
| 1623 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1624 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1625 | break; |
| 1626 | |
| 1627 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1628 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1629 | uiccPort = getUiccPortFromRequest(request); |
| 1630 | if (uiccPort == null) { |
| 1631 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1632 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1633 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1634 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1635 | break; |
| 1636 | } |
| 1637 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1638 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1639 | if (uiccApp == null) { |
| 1640 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1641 | + appType); |
| 1642 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1643 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1644 | break; |
| 1645 | } else { |
| 1646 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1647 | + " specified type -- " + appType); |
| 1648 | } |
| 1649 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1650 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1651 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1652 | break; |
| 1653 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1654 | case CMD_SWITCH_SLOTS: |
| 1655 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1656 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1657 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1658 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1659 | break; |
| 1660 | |
| 1661 | case EVENT_SWITCH_SLOTS_DONE: |
| 1662 | ar = (AsyncResult) msg.obj; |
| 1663 | request = (MainThreadRequest) ar.userObj; |
| 1664 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1665 | notifyRequester(request); |
| 1666 | break; |
| 1667 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1668 | request = (MainThreadRequest) msg.obj; |
| 1669 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1670 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1671 | break; |
| 1672 | |
| 1673 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1674 | ar = (AsyncResult) msg.obj; |
| 1675 | request = (MainThreadRequest) ar.userObj; |
| 1676 | if (ar.exception != null) { |
| 1677 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1678 | } else { |
| 1679 | int mode = ((int[]) ar.result)[0]; |
| 1680 | if (mode == 0) { |
| 1681 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1682 | } else { |
| 1683 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1684 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1685 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1686 | notifyRequester(request); |
| 1687 | break; |
| 1688 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1689 | request = (MainThreadRequest) msg.obj; |
| 1690 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1691 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1692 | break; |
| 1693 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1694 | ar = (AsyncResult) msg.obj; |
| 1695 | request = (MainThreadRequest) ar.userObj; |
| 1696 | if (ar.exception != null) { |
| 1697 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1698 | } else { |
| 1699 | request.result = ((int[]) ar.result)[0]; |
| 1700 | } |
| 1701 | notifyRequester(request); |
| 1702 | break; |
| 1703 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1704 | request = (MainThreadRequest) msg.obj; |
| 1705 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1706 | int mode = (int) request.argument; |
| 1707 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1708 | break; |
| 1709 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1710 | ar = (AsyncResult) msg.obj; |
| 1711 | request = (MainThreadRequest) ar.userObj; |
| 1712 | request.result = ar.exception == null; |
| 1713 | notifyRequester(request); |
| 1714 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1715 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1716 | request = (MainThreadRequest) msg.obj; |
| 1717 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1718 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1719 | break; |
| 1720 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1721 | ar = (AsyncResult) msg.obj; |
| 1722 | request = (MainThreadRequest) ar.userObj; |
| 1723 | if (ar.exception != null) { |
| 1724 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1725 | } else { |
| 1726 | request.result = ((int[]) ar.result)[0]; |
| 1727 | } |
| 1728 | notifyRequester(request); |
| 1729 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1730 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1731 | request = (MainThreadRequest) msg.obj; |
| 1732 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1733 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1734 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1735 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1736 | break; |
| 1737 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1738 | ar = (AsyncResult) msg.obj; |
| 1739 | request = (MainThreadRequest) ar.userObj; |
| 1740 | request.result = ar.exception == null; |
| 1741 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1742 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1743 | case CMD_GET_ALL_CELL_INFO: |
| 1744 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1745 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1746 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1748 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1749 | ar = (AsyncResult) msg.obj; |
| 1750 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1751 | // If a timeout occurs, the response will be null |
| 1752 | request.result = (ar.exception == null && ar.result != null) |
| 1753 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1754 | synchronized (request) { |
| 1755 | request.notifyAll(); |
| 1756 | } |
| 1757 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1758 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1759 | request = (MainThreadRequest) msg.obj; |
| 1760 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1761 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1762 | break; |
| 1763 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1764 | ar = (AsyncResult) msg.obj; |
| 1765 | request = (MainThreadRequest) ar.userObj; |
| 1766 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1767 | try { |
| 1768 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1769 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1770 | cb.onError( |
| 1771 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1772 | ar.exception.getClass().getName(), |
| 1773 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1774 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1775 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1776 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1777 | } else { |
| 1778 | // use the result as returned |
| 1779 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1780 | } |
| 1781 | } catch (RemoteException re) { |
| 1782 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1783 | } |
| 1784 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1785 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1786 | request = (MainThreadRequest) msg.obj; |
| 1787 | WorkSource ws = (WorkSource) request.argument; |
| 1788 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1789 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1790 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1791 | } |
| 1792 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1793 | ar = (AsyncResult) msg.obj; |
| 1794 | request = (MainThreadRequest) ar.userObj; |
| 1795 | if (ar.exception == null) { |
| 1796 | request.result = ar.result; |
| 1797 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1798 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1799 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1800 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | synchronized (request) { |
| 1804 | request.notifyAll(); |
| 1805 | } |
| 1806 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1807 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1808 | case CMD_MODEM_REBOOT: |
| 1809 | request = (MainThreadRequest) msg.obj; |
| 1810 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1811 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1812 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1813 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1814 | handleNullReturnEvent(msg, "rebootModem"); |
| 1815 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1816 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1817 | request = (MainThreadRequest) msg.obj; |
| 1818 | boolean enable = (boolean) request.argument; |
| 1819 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1820 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1821 | PhoneConfigurationManager.getInstance() |
| 1822 | .enablePhone(request.phone, enable, onCompleted); |
| 1823 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1824 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1825 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1826 | ar = (AsyncResult) msg.obj; |
| 1827 | request = (MainThreadRequest) ar.userObj; |
| 1828 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1829 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1830 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1831 | if ((boolean) request.result) { |
| 1832 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1833 | updateModemStateMetrics(); |
| 1834 | } else { |
| 1835 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1836 | + ar.exception); |
| 1837 | } |
| 1838 | notifyRequester(request); |
| 1839 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1840 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1841 | case CMD_GET_MODEM_STATUS: |
| 1842 | request = (MainThreadRequest) msg.obj; |
| 1843 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1844 | PhoneConfigurationManager.getInstance() |
| 1845 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1846 | break; |
| 1847 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1848 | ar = (AsyncResult) msg.obj; |
| 1849 | request = (MainThreadRequest) ar.userObj; |
| 1850 | int id = request.phone.getPhoneId(); |
| 1851 | if (ar.exception == null && ar.result != null) { |
| 1852 | request.result = ar.result; |
| 1853 | //update the cache as modem status has changed |
| 1854 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1855 | (boolean) request.result); |
| 1856 | } else { |
| 1857 | // Return true if modem status cannot be retrieved. For most cases, |
| 1858 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1859 | // and disable modem are not supported. Modem is always on. |
| 1860 | // TODO: this should be fixed in R to support a third |
| 1861 | // status UNKNOWN b/131631629 |
| 1862 | request.result = true; |
| 1863 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1864 | + ar.exception); |
| 1865 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1866 | notifyRequester(request); |
| 1867 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1868 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1869 | request = (MainThreadRequest) msg.obj; |
| 1870 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1871 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1872 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1873 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1874 | break; |
| 1875 | } |
| 1876 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1877 | ar = (AsyncResult) msg.obj; |
| 1878 | request = (MainThreadRequest) ar.userObj; |
| 1879 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1880 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1881 | args.second.accept(ar.exception == null); |
| 1882 | notifyRequester(request); |
| 1883 | break; |
| 1884 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1885 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1886 | request = (MainThreadRequest) msg.obj; |
| 1887 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1888 | Phone phone = getPhoneFromRequest(request); |
| 1889 | if (phone != null) { |
| 1890 | phone.getSystemSelectionChannels(onCompleted); |
| 1891 | } else { |
| 1892 | loge("getSystemSelectionChannels: No phone object"); |
| 1893 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1894 | notifyRequester(request); |
| 1895 | } |
| 1896 | break; |
| 1897 | } |
| 1898 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1899 | ar = (AsyncResult) msg.obj; |
| 1900 | request = (MainThreadRequest) ar.userObj; |
| 1901 | if (ar.exception == null && ar.result != null) { |
| 1902 | request.result = ar.result; |
| 1903 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1904 | request.result = new IllegalStateException( |
| 1905 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1906 | if (ar.result == null) { |
| 1907 | loge("getSystemSelectionChannels: Empty response"); |
| 1908 | } else { |
| 1909 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1910 | } |
| 1911 | } |
| 1912 | notifyRequester(request); |
| 1913 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1914 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1915 | ar = (AsyncResult) msg.obj; |
| 1916 | request = (MainThreadRequest) ar.userObj; |
| 1917 | if (ar.exception == null && ar.result != null) { |
| 1918 | request.result = ar.result; |
| 1919 | } else { |
| 1920 | request.result = -1; |
| 1921 | loge("Failed to set Forbidden Plmns"); |
| 1922 | if (ar.result == null) { |
| 1923 | loge("setForbidenPlmns: Empty response"); |
| 1924 | } else if (ar.exception != null) { |
| 1925 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1926 | request.result = -1; |
| 1927 | } else { |
| 1928 | loge("setForbiddenPlmns: Unknown exception"); |
| 1929 | } |
| 1930 | } |
| 1931 | notifyRequester(request); |
| 1932 | break; |
| 1933 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1934 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1935 | uiccPort = getUiccPortFromRequest(request); |
| 1936 | if (uiccPort == null) { |
| 1937 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1938 | request.result = -1; |
| 1939 | notifyRequester(request); |
| 1940 | break; |
| 1941 | } |
| 1942 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1943 | (Pair<Integer, List<String>>) request.argument; |
| 1944 | appType = setFplmnsArgs.first; |
| 1945 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1946 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1947 | if (uiccApp == null) { |
| 1948 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1949 | request.result = -1; |
| 1950 | loge("Failed to get UICC App"); |
| 1951 | notifyRequester(request); |
| 1952 | } else { |
| 1953 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1954 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1955 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1956 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1957 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1958 | case CMD_ERASE_MODEM_CONFIG: |
| 1959 | request = (MainThreadRequest) msg.obj; |
| 1960 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1961 | defaultPhone.eraseModemConfig(onCompleted); |
| 1962 | break; |
| 1963 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1964 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1965 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1966 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1967 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1968 | request = (MainThreadRequest) msg.obj; |
| 1969 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1970 | notifyRequester(request); |
| 1971 | break; |
| 1972 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1973 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1974 | request = (MainThreadRequest) msg.obj; |
| 1975 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1976 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1977 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1978 | changed.first, changed.second, onCompleted); |
| 1979 | break; |
| 1980 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1981 | ar = (AsyncResult) msg.obj; |
| 1982 | request = (MainThreadRequest) ar.userObj; |
| 1983 | if (ar.exception == null) { |
| 1984 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1985 | // If the operation is successful, update the PIN storage |
| 1986 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1987 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1988 | UiccController.getInstance().getPinStorage() |
| 1989 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1990 | } else { |
| 1991 | request.result = msg.arg1; |
| 1992 | } |
| 1993 | notifyRequester(request); |
| 1994 | break; |
| 1995 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1996 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1997 | request = (MainThreadRequest) msg.obj; |
| 1998 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1999 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2000 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2001 | enabled.first, enabled.second, onCompleted); |
| 2002 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2003 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2004 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2005 | ar = (AsyncResult) msg.obj; |
| 2006 | request = (MainThreadRequest) ar.userObj; |
| 2007 | if (ar.exception == null) { |
| 2008 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2009 | // If the operation is successful, update the PIN storage |
| 2010 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2011 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2012 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2013 | UiccController.getInstance().getPinStorage() |
| 2014 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2015 | } else { |
| 2016 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2017 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2018 | } else { |
| 2019 | request.result = msg.arg1; |
| 2020 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2021 | |
| 2022 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2023 | notifyRequester(request); |
| 2024 | break; |
| 2025 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2026 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2027 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2028 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2029 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2030 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2031 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2032 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2033 | |
| 2034 | case CMD_SET_DATA_THROTTLING: { |
| 2035 | request = (MainThreadRequest) msg.obj; |
| 2036 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2037 | DataThrottlingRequest dataThrottlingRequest = |
| 2038 | (DataThrottlingRequest) request.argument; |
| 2039 | Phone phone = getPhoneFromRequest(request); |
| 2040 | if (phone != null) { |
| 2041 | phone.setDataThrottling(onCompleted, |
| 2042 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2043 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2044 | } else { |
| 2045 | loge("setDataThrottling: No phone object"); |
| 2046 | request.result = |
| 2047 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2048 | notifyRequester(request); |
| 2049 | } |
| 2050 | |
| 2051 | break; |
| 2052 | } |
| 2053 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2054 | ar = (AsyncResult) msg.obj; |
| 2055 | request = (MainThreadRequest) ar.userObj; |
| 2056 | |
| 2057 | if (ar.exception == null) { |
| 2058 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2059 | } else if (ar.exception instanceof CommandException) { |
| 2060 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2061 | CommandException.Error error = |
| 2062 | ((CommandException) (ar.exception)).getCommandError(); |
| 2063 | |
| 2064 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2065 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2066 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2067 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2068 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2069 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2070 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2071 | } else { |
| 2072 | request.result = |
| 2073 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2074 | } |
| 2075 | } else { |
| 2076 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2077 | } |
| 2078 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2079 | notifyRequester(request); |
| 2080 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2081 | |
| 2082 | case CMD_SET_SIM_POWER: { |
| 2083 | request = (MainThreadRequest) msg.obj; |
| 2084 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2085 | request = (MainThreadRequest) msg.obj; |
| 2086 | int stateToSet = |
| 2087 | ((Pair<Integer, IIntegerConsumer>) |
| 2088 | request.argument).first; |
| 2089 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2090 | break; |
| 2091 | } |
| 2092 | case EVENT_SET_SIM_POWER_DONE: { |
| 2093 | ar = (AsyncResult) msg.obj; |
| 2094 | request = (MainThreadRequest) ar.userObj; |
| 2095 | IIntegerConsumer callback = |
| 2096 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2097 | if (ar.exception != null) { |
| 2098 | loge("setSimPower exception: " + ar.exception); |
| 2099 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2100 | .RESULT_ERROR_UNKNOWN; |
| 2101 | if (ar.exception instanceof CommandException) { |
| 2102 | CommandException.Error error = |
| 2103 | ((CommandException) (ar.exception)).getCommandError(); |
| 2104 | if (error == CommandException.Error.SIM_ERR) { |
| 2105 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2106 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2107 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2108 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2109 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2110 | } else { |
| 2111 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2112 | } |
| 2113 | } |
| 2114 | try { |
| 2115 | callback.accept(errorCode); |
| 2116 | } catch (RemoteException e) { |
| 2117 | // Ignore if the remote process is no longer available to call back. |
| 2118 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2119 | } |
| 2120 | } else { |
| 2121 | try { |
| 2122 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2123 | } catch (RemoteException e) { |
| 2124 | // Ignore if the remote process is no longer available to call back. |
| 2125 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2126 | } |
| 2127 | } |
| 2128 | break; |
| 2129 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2130 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2131 | request = (MainThreadRequest) msg.obj; |
| 2132 | |
| 2133 | final Phone phone = getPhoneFromRequest(request); |
| 2134 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2135 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2136 | notifyRequester(request); |
| 2137 | break; |
| 2138 | } |
| 2139 | |
| 2140 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2141 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2142 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2143 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2144 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2145 | request.subId, pair.first /*callingUid*/, |
| 2146 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2147 | break; |
| 2148 | } |
| 2149 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2150 | ar = (AsyncResult) msg.obj; |
| 2151 | request = (MainThreadRequest) ar.userObj; |
| 2152 | // request.result will be the exception of ar if present, true otherwise. |
| 2153 | // Be cautious not to leave result null which will wait() forever |
| 2154 | request.result = ar.exception != null ? ar.exception : true; |
| 2155 | notifyRequester(request); |
| 2156 | break; |
| 2157 | } |
| 2158 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2159 | request = (MainThreadRequest) msg.obj; |
| 2160 | |
| 2161 | Phone phone = getPhoneFromRequest(request); |
| 2162 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2163 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2164 | notifyRequester(request); |
| 2165 | break; |
| 2166 | } |
| 2167 | |
| 2168 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2169 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2170 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2171 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2172 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2173 | request.subId, pair.first /*callingUid*/, |
| 2174 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2175 | break; |
| 2176 | } |
| 2177 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2178 | ar = (AsyncResult) msg.obj; |
| 2179 | request = (MainThreadRequest) ar.userObj; |
| 2180 | request.result = ar.exception != null ? ar.exception : true; |
| 2181 | notifyRequester(request); |
| 2182 | break; |
| 2183 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2184 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2185 | case CMD_GET_SLICING_CONFIG: { |
| 2186 | request = (MainThreadRequest) msg.obj; |
| 2187 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2188 | request.phone.getSlicingConfig(onCompleted); |
| 2189 | break; |
| 2190 | } |
| 2191 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2192 | ar = (AsyncResult) msg.obj; |
| 2193 | request = (MainThreadRequest) ar.userObj; |
| 2194 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2195 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2196 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2197 | Bundle bundle = new Bundle(); |
| 2198 | int resultCode = 0; |
| 2199 | if (ar.exception != null) { |
| 2200 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2201 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2202 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2203 | } else if (ar.result == null) { |
| 2204 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2205 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2206 | } else { |
| 2207 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2208 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2209 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2213 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2214 | } |
| 2215 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2216 | result.send(resultCode, bundle); |
| 2217 | notifyRequester(request); |
| 2218 | break; |
| 2219 | } |
| 2220 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2221 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2222 | request = (MainThreadRequest) msg.obj; |
| 2223 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2224 | PurchasePremiumCapabilityArgument arg = |
| 2225 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2226 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2227 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2228 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2229 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2230 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2231 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2232 | ar = (AsyncResult) msg.obj; |
| 2233 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2234 | PurchasePremiumCapabilityArgument arg = |
| 2235 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2236 | try { |
| 2237 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2238 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2239 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2240 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2241 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2242 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2243 | } catch (RemoteException e) { |
| 2244 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2245 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2246 | + " failed: " + e; |
| 2247 | if (DBG) log(logStr); |
| 2248 | AnomalyReporter.reportAnomaly( |
| 2249 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2250 | } |
| 2251 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2252 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2253 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2254 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2255 | request = (MainThreadRequest) msg.obj; |
| 2256 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2257 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2258 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2259 | notifyRequester(request); |
| 2260 | break; |
| 2261 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2262 | default: |
| 2263 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2264 | break; |
| 2265 | } |
| 2266 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2267 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2268 | private void notifyRequester(MainThreadRequest request) { |
| 2269 | synchronized (request) { |
| 2270 | request.notifyAll(); |
| 2271 | } |
| 2272 | } |
| 2273 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2274 | private void handleNullReturnEvent(Message msg, String command) { |
| 2275 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2276 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2277 | if (ar.exception == null) { |
| 2278 | request.result = true; |
| 2279 | } else { |
| 2280 | request.result = false; |
| 2281 | if (ar.exception instanceof CommandException) { |
| 2282 | loge(command + ": CommandException: " + ar.exception); |
| 2283 | } else { |
| 2284 | loge(command + ": Unknown exception"); |
| 2285 | } |
| 2286 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2287 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2288 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | /** |
| 2292 | * Posts the specified command to be executed on the main thread, |
| 2293 | * waits for the request to complete, and returns the result. |
| 2294 | * @see #sendRequestAsync |
| 2295 | */ |
| 2296 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2297 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2298 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | /** |
| 2302 | * Posts the specified command to be executed on the main thread, |
| 2303 | * waits for the request to complete, and returns the result. |
| 2304 | * @see #sendRequestAsync |
| 2305 | */ |
| 2306 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2307 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2308 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | /** |
| 2312 | * Posts the specified command to be executed on the main thread, |
| 2313 | * waits for the request to complete, and returns the result. |
| 2314 | * @see #sendRequestAsync |
| 2315 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2316 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2317 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * Posts the specified command to be executed on the main thread, |
| 2322 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2323 | * if not timeout or null otherwise. |
| 2324 | * @see #sendRequestAsync |
| 2325 | */ |
| 2326 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2327 | long timeoutInMs) { |
| 2328 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | /** |
| 2332 | * Posts the specified command to be executed on the main thread, |
| 2333 | * waits for the request to complete, and returns the result. |
| 2334 | * @see #sendRequestAsync |
| 2335 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2336 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2337 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * Posts the specified command to be executed on the main thread, |
| 2342 | * waits for the request to complete, and returns the result. |
| 2343 | * @see #sendRequestAsync |
| 2344 | */ |
| 2345 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2346 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2347 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2351 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2352 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2353 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2354 | * @see #sendRequestAsync |
| 2355 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2356 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2357 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2359 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2360 | } |
| 2361 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2362 | MainThreadRequest request = null; |
| 2363 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2364 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2365 | } else if (phone != null) { |
| 2366 | request = new MainThreadRequest(argument, phone, workSource); |
| 2367 | } else { |
| 2368 | request = new MainThreadRequest(argument, subId, workSource); |
| 2369 | } |
| 2370 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2372 | msg.sendToTarget(); |
| 2373 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2374 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2376 | if (timeoutInMs >= 0) { |
| 2377 | // Wait for at least timeoutInMs before returning null request result |
| 2378 | long now = SystemClock.elapsedRealtime(); |
| 2379 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2380 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2381 | try { |
| 2382 | request.wait(deadline - now); |
| 2383 | } catch (InterruptedException e) { |
| 2384 | // Do nothing, go back and check if request is completed or timeout |
| 2385 | } finally { |
| 2386 | now = SystemClock.elapsedRealtime(); |
| 2387 | } |
| 2388 | } |
| 2389 | } else { |
| 2390 | // Wait for the request to complete |
| 2391 | while (request.result == null) { |
| 2392 | try { |
| 2393 | request.wait(); |
| 2394 | } catch (InterruptedException e) { |
| 2395 | // Do nothing, go back and wait until the request is complete |
| 2396 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2400 | if (request.result == null) { |
| 2401 | Log.wtf(LOG_TAG, |
| 2402 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2403 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2404 | return request.result; |
| 2405 | } |
| 2406 | |
| 2407 | /** |
| 2408 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2409 | * Posts the specified command to be executed on the main thread, and |
| 2410 | * returns immediately. |
| 2411 | * @see #sendRequest |
| 2412 | */ |
| 2413 | private void sendRequestAsync(int command) { |
| 2414 | mMainThreadHandler.sendEmptyMessage(command); |
| 2415 | } |
| 2416 | |
| 2417 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2418 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2419 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2420 | */ |
| 2421 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2422 | sendRequestAsync(command, argument, null, null); |
| 2423 | } |
| 2424 | |
| 2425 | /** |
| 2426 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2427 | * @see {@link #sendRequest(int,Object)} |
| 2428 | */ |
| 2429 | private void sendRequestAsync( |
| 2430 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2431 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2432 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2433 | msg.sendToTarget(); |
| 2434 | } |
| 2435 | |
| 2436 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2437 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2438 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2439 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2440 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | synchronized (PhoneInterfaceManager.class) { |
| 2442 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2443 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2444 | } else { |
| 2445 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2446 | } |
| 2447 | return sInstance; |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2452 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2454 | mFeatureFlags = featureFlags; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2456 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2457 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2458 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2460 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2461 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2462 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2463 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2464 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2465 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2466 | mPackageManager = app.getPackageManager(); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2467 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2469 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2472 | @VisibleForTesting |
| 2473 | public SharedPreferences getSharedPreferences() { |
| 2474 | return mTelephonySharedPreferences; |
| 2475 | } |
| 2476 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2477 | /** |
| 2478 | * Get the default phone for this device. |
| 2479 | */ |
| 2480 | @VisibleForTesting |
| 2481 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2482 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2483 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2484 | } |
| 2485 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | private void publish() { |
| 2487 | if (DBG) log("publish: " + this); |
| 2488 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2489 | TelephonyFrameworkInitializer |
| 2490 | .getTelephonyServiceManager() |
| 2491 | .getTelephonyServiceRegisterer() |
| 2492 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2495 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2496 | if (request.phone != null) { |
| 2497 | return request.phone; |
| 2498 | } else { |
| 2499 | return getPhoneFromSubId(request.subId); |
| 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | private Phone getPhoneFromSubId(int subId) { |
| 2504 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2505 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2506 | } |
| 2507 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2508 | /** |
| 2509 | * Get phone object associated with a subscription. |
| 2510 | * Return default phone if phone object associated with subscription is null |
| 2511 | * @param subId - subscriptionId |
| 2512 | * @return phone object associated with a subscription or default phone if null. |
| 2513 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2514 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2515 | Phone phone = getPhoneFromSubId(subId); |
| 2516 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2517 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2518 | phone = getDefaultPhone(); |
| 2519 | } |
| 2520 | return phone; |
| 2521 | } |
| 2522 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2523 | @Nullable |
| 2524 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2525 | Phone phone = getPhoneFromRequest(request); |
| 2526 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2527 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2528 | } |
| 2529 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2530 | /** |
| 2531 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2532 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2533 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2534 | * @return The Phone associated the sub Id |
| 2535 | */ |
| 2536 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2537 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2539 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2540 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2541 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2542 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2543 | } |
| 2544 | |
| 2545 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2546 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2547 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2550 | private boolean isImsAvailableOnDevice() { |
| 2551 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2552 | if (pm == null) { |
| 2553 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2554 | // so do not throw error and allow. |
| 2555 | return true; |
| 2556 | } |
| 2557 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2558 | } |
| 2559 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2560 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2561 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2562 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2563 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2564 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2567 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | if (DBG) log("dial: " + number); |
| 2569 | // No permission check needed here: This is just a wrapper around the |
| 2570 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2571 | // the UI before it does anything. |
| 2572 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | final long identity = Binder.clearCallingIdentity(); |
| 2574 | try { |
| 2575 | String url = createTelUrl(number); |
| 2576 | if (url == null) { |
| 2577 | return; |
| 2578 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2579 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2580 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2581 | PhoneConstants.State state = mCM.getState(subId); |
| 2582 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2583 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2584 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2585 | mApp.startActivity(intent); |
| 2586 | } |
| 2587 | } finally { |
| 2588 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2593 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2596 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2597 | if (DBG) log("call: " + number); |
| 2598 | |
| 2599 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2600 | // need to do a permission check since we're calling startActivity() |
| 2601 | // from the context of the phone app. |
| 2602 | enforceCallPermission(); |
| 2603 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2604 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | != AppOpsManager.MODE_ALLOWED) { |
| 2606 | return; |
| 2607 | } |
| 2608 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2609 | enforceTelephonyFeatureWithException(callingPackage, |
| 2610 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2611 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
| 2614 | String url = createTelUrl(number); |
| 2615 | if (url == null) { |
| 2616 | return; |
| 2617 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | boolean isValid = false; |
| 2620 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2621 | if (slist != null) { |
| 2622 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2623 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2624 | isValid = true; |
| 2625 | break; |
| 2626 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2627 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 | if (!isValid) { |
| 2630 | return; |
| 2631 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2632 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2633 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2634 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2635 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2636 | mApp.startActivity(intent); |
| 2637 | } finally { |
| 2638 | Binder.restoreCallingIdentity(identity); |
| 2639 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2642 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2643 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2644 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2645 | } |
| 2646 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2647 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2648 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2649 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2650 | } |
| 2651 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2652 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2653 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2655 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2656 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2657 | "supplyPinReportResultForSubscriber"); |
| 2658 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | final long identity = Binder.clearCallingIdentity(); |
| 2660 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2661 | Phone phone = getPhone(subId); |
| 2662 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | checkSimPin.start(); |
| 2664 | return checkSimPin.unlockSim(null, pin); |
| 2665 | } finally { |
| 2666 | Binder.restoreCallingIdentity(identity); |
| 2667 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2670 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2673 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2674 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2675 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | final long identity = Binder.clearCallingIdentity(); |
| 2677 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2678 | Phone phone = getPhone(subId); |
| 2679 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2680 | checkSimPuk.start(); |
| 2681 | return checkSimPuk.unlockSim(puk, pin); |
| 2682 | } finally { |
| 2683 | Binder.restoreCallingIdentity(identity); |
| 2684 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2688 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2689 | * a synchronous one. |
| 2690 | */ |
| 2691 | private static class UnlockSim extends Thread { |
| 2692 | |
| 2693 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2694 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | |
| 2696 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2697 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2698 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2699 | |
| 2700 | // For replies from SimCard interface |
| 2701 | private Handler mHandler; |
| 2702 | |
| 2703 | // For async handler to identify request type |
| 2704 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2705 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2706 | UnlockSim(int phoneId, IccCard simCard) { |
| 2707 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | mSimCard = simCard; |
| 2709 | } |
| 2710 | |
| 2711 | @Override |
| 2712 | public void run() { |
| 2713 | Looper.prepare(); |
| 2714 | synchronized (UnlockSim.this) { |
| 2715 | mHandler = new Handler() { |
| 2716 | @Override |
| 2717 | public void handleMessage(Message msg) { |
| 2718 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2719 | switch (msg.what) { |
| 2720 | case SUPPLY_PIN_COMPLETE: |
| 2721 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2722 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2723 | mRetryCount = msg.arg1; |
| 2724 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2725 | CommandException.Error error = null; |
| 2726 | if (ar.exception instanceof CommandException) { |
| 2727 | error = ((CommandException) (ar.exception)) |
| 2728 | .getCommandError(); |
| 2729 | } |
| 2730 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2731 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2732 | } else if (error == CommandException.Error.ABORTED) { |
| 2733 | /* When UiccCardApp dispose, handle message and return |
| 2734 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2735 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2736 | } else { |
| 2737 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2738 | } |
| 2739 | } else { |
| 2740 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2741 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | mDone = true; |
| 2743 | UnlockSim.this.notifyAll(); |
| 2744 | } |
| 2745 | break; |
| 2746 | } |
| 2747 | } |
| 2748 | }; |
| 2749 | UnlockSim.this.notifyAll(); |
| 2750 | } |
| 2751 | Looper.loop(); |
| 2752 | } |
| 2753 | |
| 2754 | /* |
| 2755 | * Use PIN or PUK to unlock SIM card |
| 2756 | * |
| 2757 | * If PUK is null, unlock SIM card with PIN |
| 2758 | * |
| 2759 | * 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] | 2760 | * |
| 2761 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2762 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2763 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2764 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2765 | |
| 2766 | while (mHandler == null) { |
| 2767 | try { |
| 2768 | wait(); |
| 2769 | } catch (InterruptedException e) { |
| 2770 | Thread.currentThread().interrupt(); |
| 2771 | } |
| 2772 | } |
| 2773 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2774 | |
| 2775 | if (puk == null) { |
| 2776 | mSimCard.supplyPin(pin, callback); |
| 2777 | } else { |
| 2778 | mSimCard.supplyPuk(puk, pin, callback); |
| 2779 | } |
| 2780 | |
| 2781 | while (!mDone) { |
| 2782 | try { |
| 2783 | Log.d(LOG_TAG, "wait for done"); |
| 2784 | wait(); |
| 2785 | } catch (InterruptedException e) { |
| 2786 | // Restore the interrupted status |
| 2787 | Thread.currentThread().interrupt(); |
| 2788 | } |
| 2789 | } |
| 2790 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2791 | int[] resultArray = new int[2]; |
| 2792 | resultArray[0] = mResult; |
| 2793 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2794 | |
| 2795 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2796 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2797 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2798 | // This instance is no longer reused, so quit its thread's looper. |
| 2799 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2800 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2801 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2802 | } |
| 2803 | } |
| 2804 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2805 | /** |
| 2806 | * This method has been removed due to privacy and stability concerns. |
| 2807 | */ |
| 2808 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2809 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2810 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2811 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2814 | @Override |
| 2815 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2816 | mApp.getSystemService(AppOpsManager.class) |
| 2817 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2818 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2819 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2820 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2821 | // Callers targeting S have no business invoking this method. |
| 2822 | return; |
| 2823 | } |
| 2824 | |
| 2825 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2826 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2827 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2828 | .setCallingPackage(callingPackage) |
| 2829 | .setCallingFeatureId(null) |
| 2830 | .setCallingPid(Binder.getCallingPid()) |
| 2831 | .setCallingUid(Binder.getCallingUid()) |
| 2832 | .setMethod("updateServiceLocation") |
| 2833 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2834 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2835 | .build()); |
| 2836 | // Apps that lack location permission have no business calling this method; |
| 2837 | // however, because no permission was declared in the public API, denials must |
| 2838 | // all be "soft". |
| 2839 | switch (locationResult) { |
| 2840 | case DENIED_HARD: /* fall through */ |
| 2841 | case DENIED_SOFT: |
| 2842 | return; |
| 2843 | } |
| 2844 | |
| 2845 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2846 | final long identity = Binder.clearCallingIdentity(); |
| 2847 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2848 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2849 | } finally { |
| 2850 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2851 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2854 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2855 | @Override |
| 2856 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2857 | return isRadioOnWithFeature(callingPackage, null); |
| 2858 | } |
| 2859 | |
| 2860 | |
| 2861 | @Override |
| 2862 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2863 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2864 | callingFeatureId); |
| 2865 | } |
| 2866 | |
| 2867 | @Deprecated |
| 2868 | @Override |
| 2869 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2870 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2873 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2874 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2875 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2876 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2877 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2878 | return false; |
| 2879 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2880 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2881 | enforceTelephonyFeatureWithException(callingPackage, |
| 2882 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2883 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2884 | final long identity = Binder.clearCallingIdentity(); |
| 2885 | try { |
| 2886 | return isRadioOnForSubscriber(subId); |
| 2887 | } finally { |
| 2888 | Binder.restoreCallingIdentity(identity); |
| 2889 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2893 | final long identity = Binder.clearCallingIdentity(); |
| 2894 | try { |
| 2895 | final Phone phone = getPhone(subId); |
| 2896 | if (phone != null) { |
| 2897 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2898 | } else { |
| 2899 | return false; |
| 2900 | } |
| 2901 | } finally { |
| 2902 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2903 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2907 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2908 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2909 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2910 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2911 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2912 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2913 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2914 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2915 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2916 | final long identity = Binder.clearCallingIdentity(); |
| 2917 | try { |
| 2918 | final Phone phone = getPhone(subId); |
| 2919 | if (phone != null) { |
| 2920 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2921 | } |
| 2922 | } finally { |
| 2923 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2924 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2928 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2931 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2932 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2933 | |
| 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | final Phone phone = getPhone(subId); |
| 2937 | if (phone == null) { |
| 2938 | return false; |
| 2939 | } |
| 2940 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2941 | toggleRadioOnOffForSubscriber(subId); |
| 2942 | } |
| 2943 | return true; |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2946 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2947 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2948 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2949 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2950 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2951 | |
| 2952 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2953 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2954 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2955 | /* |
| 2956 | * If any of the Radios are available, it will need to be |
| 2957 | * shutdown. So return true if any Radio is available. |
| 2958 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2959 | final long identity = Binder.clearCallingIdentity(); |
| 2960 | try { |
| 2961 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2962 | Phone phone = PhoneFactory.getPhone(i); |
| 2963 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2964 | } |
| 2965 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2966 | return false; |
| 2967 | } finally { |
| 2968 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2969 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2972 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2973 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2974 | enforceModifyPermission(); |
| 2975 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2976 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2977 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 2978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2982 | logv("Shutting down Phone " + i); |
| 2983 | shutdownRadioUsingPhoneId(i); |
| 2984 | } |
| 2985 | } finally { |
| 2986 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2991 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2992 | if (phone != null && phone.isRadioAvailable()) { |
| 2993 | phone.shutdownRadio(); |
| 2994 | } |
| 2995 | } |
| 2996 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2997 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2998 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2999 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3000 | if (!turnOn) { |
| 3001 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3002 | } |
| 3003 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3004 | final long identity = Binder.clearCallingIdentity(); |
| 3005 | try { |
| 3006 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3007 | if (defaultPhone != null) { |
| 3008 | defaultPhone.setRadioPower(turnOn); |
| 3009 | return true; |
| 3010 | } else { |
| 3011 | loge("There's no default phone."); |
| 3012 | return false; |
| 3013 | } |
| 3014 | } finally { |
| 3015 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3016 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3017 | } |
| 3018 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3019 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3020 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3021 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3022 | if (!turnOn) { |
| 3023 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3024 | + ",callingPackage=" + getCurrentPackageName()); |
| 3025 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3026 | final long identity = Binder.clearCallingIdentity(); |
| 3027 | try { |
| 3028 | final Phone phone = getPhone(subId); |
| 3029 | if (phone != null) { |
| 3030 | phone.setRadioPower(turnOn); |
| 3031 | return true; |
| 3032 | } else { |
| 3033 | return false; |
| 3034 | } |
| 3035 | } finally { |
| 3036 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3037 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3040 | /** |
| 3041 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3042 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3043 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3044 | * powering it off, and these radio off votes will be cleared. |
| 3045 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3046 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3047 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3048 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3049 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3050 | * check its vote. |
| 3051 | * |
| 3052 | * @param subId The subscription ID. |
| 3053 | * @param reason The reason for powering off radio. |
| 3054 | * @return true on success and false on failure. |
| 3055 | */ |
| 3056 | public boolean requestRadioPowerOffForReason(int subId, |
| 3057 | @TelephonyManager.RadioPowerReason int reason) { |
| 3058 | enforceModifyPermission(); |
| 3059 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3060 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3061 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3062 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3063 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3064 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3065 | final long identity = Binder.clearCallingIdentity(); |
| 3066 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3067 | boolean result = false; |
| 3068 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3069 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3070 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3071 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3072 | if (!result) { |
| 3073 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3074 | } |
| 3075 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3076 | } finally { |
| 3077 | Binder.restoreCallingIdentity(identity); |
| 3078 | } |
| 3079 | } |
| 3080 | |
| 3081 | /** |
| 3082 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3083 | * {@link requestRadioPowerOffForReason}. |
| 3084 | * |
| 3085 | * @param subId The subscription ID. |
| 3086 | * @param reason The reason for powering off radio. |
| 3087 | * @return true on success and false on failure. |
| 3088 | */ |
| 3089 | public boolean clearRadioPowerOffForReason(int subId, |
| 3090 | @TelephonyManager.RadioPowerReason int reason) { |
| 3091 | enforceModifyPermission(); |
| 3092 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3093 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3094 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3095 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3096 | final long identity = Binder.clearCallingIdentity(); |
| 3097 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3098 | boolean result = false; |
| 3099 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3100 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3101 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3102 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3103 | if (!result) { |
| 3104 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3105 | } |
| 3106 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3107 | } finally { |
| 3108 | Binder.restoreCallingIdentity(identity); |
| 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | /** |
| 3113 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3114 | * |
| 3115 | * @param subId The subscription ID. |
| 3116 | * @param callingPackage The package making the call. |
| 3117 | * @param callingFeatureId The feature in the package. |
| 3118 | * @return List of reasons for powering off radio. |
| 3119 | */ |
| 3120 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3121 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3122 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3123 | enforceTelephonyFeatureWithException(callingPackage, |
| 3124 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3125 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3126 | final long identity = Binder.clearCallingIdentity(); |
| 3127 | List result = new ArrayList(); |
| 3128 | try { |
| 3129 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3130 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3131 | return result; |
| 3132 | } |
| 3133 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3134 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3135 | if (phone != null) { |
| 3136 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3137 | } else { |
| 3138 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3139 | } |
| 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
| 3142 | } |
| 3143 | return result; |
| 3144 | } |
| 3145 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3146 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3147 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3148 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3149 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3150 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3151 | enforceTelephonyFeatureWithException(callingPackage, |
| 3152 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3153 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3154 | final long identity = Binder.clearCallingIdentity(); |
| 3155 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3156 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3157 | final Phone phone = getPhone(subId); |
| 3158 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3159 | phone.getDataSettingsManager().setDataEnabled( |
| 3160 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3161 | return true; |
| 3162 | } else { |
| 3163 | return false; |
| 3164 | } |
| 3165 | } finally { |
| 3166 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3167 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3170 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3171 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3172 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3173 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3174 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3175 | enforceTelephonyFeatureWithException(callingPackage, |
| 3176 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3177 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3178 | final long identity = Binder.clearCallingIdentity(); |
| 3179 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3180 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3181 | final Phone phone = getPhone(subId); |
| 3182 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3183 | phone.getDataSettingsManager().setDataEnabled( |
| 3184 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3185 | return true; |
| 3186 | } else { |
| 3187 | return false; |
| 3188 | } |
| 3189 | } finally { |
| 3190 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3191 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3194 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3195 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3196 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3197 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3198 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3199 | final long identity = Binder.clearCallingIdentity(); |
| 3200 | try { |
| 3201 | final Phone phone = getPhone(subId); |
| 3202 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3203 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3204 | } else { |
| 3205 | return false; |
| 3206 | } |
| 3207 | } finally { |
| 3208 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3213 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3216 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3217 | enforceCallPermission(); |
| 3218 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3219 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3220 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3222 | final long identity = Binder.clearCallingIdentity(); |
| 3223 | try { |
| 3224 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3225 | return; |
| 3226 | } |
| 3227 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3228 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
| 3231 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3232 | }; |
| 3233 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3234 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3235 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3236 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3237 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3238 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3239 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3240 | final long identity = Binder.clearCallingIdentity(); |
| 3241 | try { |
| 3242 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3243 | return false; |
| 3244 | } |
| 3245 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3246 | } finally { |
| 3247 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3248 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3251 | /** |
| 3252 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3253 | * tag on getCallState Binder call. |
| 3254 | */ |
| 3255 | @Deprecated |
| 3256 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3257 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3258 | if (CompatChanges.isChangeEnabled( |
| 3259 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3260 | Binder.getCallingUid())) { |
| 3261 | // Do not allow this API to be called on API version 31+, it should only be |
| 3262 | // called on old apps using this Binder call directly. |
| 3263 | throw new SecurityException("This method can only be used for applications " |
| 3264 | + "targeting API version 30 or less."); |
| 3265 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3266 | final long identity = Binder.clearCallingIdentity(); |
| 3267 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3268 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3269 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3270 | } finally { |
| 3271 | Binder.restoreCallingIdentity(identity); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | @Override |
| 3276 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3277 | if (CompatChanges.isChangeEnabled( |
| 3278 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3279 | Binder.getCallingUid())) { |
| 3280 | // Check READ_PHONE_STATE for API version 31+ |
| 3281 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3282 | featureId, "getCallStateForSubscription")) { |
| 3283 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3284 | + "targeting API level 31+."); |
| 3285 | } |
| 3286 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3287 | |
| 3288 | enforceTelephonyFeatureWithException(callingPackage, |
| 3289 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3290 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3291 | final long identity = Binder.clearCallingIdentity(); |
| 3292 | try { |
| 3293 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3294 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3295 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3296 | } finally { |
| 3297 | Binder.restoreCallingIdentity(identity); |
| 3298 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3301 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3302 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3303 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | @Override |
| 3307 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3308 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3309 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3313 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3315 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3316 | } else { |
| 3317 | return PhoneConstantConversions.convertDataState( |
| 3318 | PhoneConstants.DataState.DISCONNECTED); |
| 3319 | } |
| 3320 | } finally { |
| 3321 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3322 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3323 | } |
| 3324 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3325 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3326 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3327 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3331 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3332 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3333 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3335 | final long identity = Binder.clearCallingIdentity(); |
| 3336 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3337 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3338 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3339 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3340 | } else { |
| 3341 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3342 | } |
| 3343 | } finally { |
| 3344 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3345 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3349 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3350 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3351 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3352 | |
| 3353 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3354 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3355 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3356 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3357 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3358 | .setCallingPid(Binder.getCallingPid()) |
| 3359 | .setCallingUid(Binder.getCallingUid()) |
| 3360 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3361 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3362 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3363 | .build()); |
| 3364 | switch (locationResult) { |
| 3365 | case DENIED_HARD: |
| 3366 | throw new SecurityException("Not allowed to access cell location"); |
| 3367 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3368 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3369 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3372 | enforceTelephonyFeatureWithException(callingPackage, |
| 3373 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3374 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3375 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3376 | final long identity = Binder.clearCallingIdentity(); |
| 3377 | try { |
| 3378 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3379 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3380 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
| 3383 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3386 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3387 | public String getNetworkCountryIsoForPhone(int phoneId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3388 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3389 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3390 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3391 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3392 | // registered cell info, so return a NULL country instead. |
| 3393 | final long identity = Binder.clearCallingIdentity(); |
| 3394 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3395 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3396 | // Get default phone in this case. |
| 3397 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3398 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3399 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3400 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3401 | if (phone == null) return ""; |
| 3402 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3403 | if (sst == null) return ""; |
| 3404 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3405 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3406 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(identity); |
| 3409 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3412 | /** |
| 3413 | * This method was removed due to potential issues caused by performing partial |
| 3414 | * updates of service state, and lack of a credible use case. |
| 3415 | * |
| 3416 | * This has the ability to break the telephony implementation by disabling notification of |
| 3417 | * changes in device connectivity. DO NOT USE THIS! |
| 3418 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3419 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3420 | public void enableLocationUpdates() { |
| 3421 | mApp.enforceCallingOrSelfPermission( |
| 3422 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3425 | /** |
| 3426 | * This method was removed due to potential issues caused by performing partial |
| 3427 | * updates of service state, and lack of a credible use case. |
| 3428 | * |
| 3429 | * This has the ability to break the telephony implementation by disabling notification of |
| 3430 | * changes in device connectivity. DO NOT USE THIS! |
| 3431 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3432 | @Override |
| 3433 | public void disableLocationUpdates() { |
| 3434 | mApp.enforceCallingOrSelfPermission( |
| 3435 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | @Override |
| 3439 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3440 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3441 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3442 | try { |
| 3443 | mApp.getSystemService(AppOpsManager.class) |
| 3444 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3445 | } catch (SecurityException e) { |
| 3446 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3447 | throw e; |
| 3448 | } |
| 3449 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3450 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3451 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3452 | throw new SecurityException( |
| 3453 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3454 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3455 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3456 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3457 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3458 | return null; |
| 3459 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3460 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3461 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3462 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3463 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3464 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3465 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3466 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3467 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3468 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3469 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3470 | for (CellInfo ci : info) { |
| 3471 | if (ci instanceof CellInfoGsm) { |
| 3472 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3473 | } else if (ci instanceof CellInfoWcdma) { |
| 3474 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3475 | } |
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 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3480 | private List<CellInfo> getCachedCellInfo() { |
| 3481 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3482 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3483 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3484 | if (info != null) cellInfos.addAll(info); |
| 3485 | } |
| 3486 | return cellInfos; |
| 3487 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3488 | |
| 3489 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3490 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3491 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3492 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3493 | |
| 3494 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3495 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3496 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3497 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3498 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3499 | .setCallingPid(Binder.getCallingPid()) |
| 3500 | .setCallingUid(Binder.getCallingUid()) |
| 3501 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3502 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3503 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3504 | .build()); |
| 3505 | switch (locationResult) { |
| 3506 | case DENIED_HARD: |
| 3507 | throw new SecurityException("Not allowed to access cell info"); |
| 3508 | case DENIED_SOFT: |
| 3509 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3510 | } |
| 3511 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3512 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3513 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3514 | return getCachedCellInfo(); |
| 3515 | } |
| 3516 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3517 | enforceTelephonyFeatureWithException(callingPackage, |
| 3518 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3519 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3520 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3521 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3522 | final long identity = Binder.clearCallingIdentity(); |
| 3523 | try { |
| 3524 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3525 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3526 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3527 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | if (info != null) cellInfos.addAll(info); |
| 3529 | } |
| 3530 | return cellInfos; |
| 3531 | } finally { |
| 3532 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3536 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3537 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3538 | String callingFeatureId) { |
| 3539 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3540 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3544 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3545 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3546 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3547 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3550 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3551 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3552 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3553 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3554 | |
| 3555 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3556 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3557 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3558 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3559 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3560 | .setCallingPid(Binder.getCallingPid()) |
| 3561 | .setCallingUid(Binder.getCallingUid()) |
| 3562 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3563 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3564 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3565 | .build()); |
| 3566 | switch (locationResult) { |
| 3567 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3568 | if (TelephonyPermissions |
| 3569 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3570 | // Safetynet logging for b/154934934 |
| 3571 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3572 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3573 | throw new SecurityException("Not allowed to access cell info"); |
| 3574 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3575 | if (TelephonyPermissions |
| 3576 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3577 | // Safetynet logging for b/154934934 |
| 3578 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3579 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3580 | try { |
| 3581 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3582 | } catch (RemoteException re) { |
| 3583 | // Drop without consequences |
| 3584 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3585 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3588 | enforceTelephonyFeatureWithException(callingPackage, |
| 3589 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3590 | |
| 3591 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3592 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3593 | |
| 3594 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3595 | } |
| 3596 | |
| 3597 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3598 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3599 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3600 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3601 | |
| 3602 | final long identity = Binder.clearCallingIdentity(); |
| 3603 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3604 | Phone phone = getPhone(subId); |
| 3605 | if (phone == null) { |
| 3606 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3607 | } else { |
| 3608 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3609 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(identity); |
| 3612 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3613 | } |
| 3614 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3615 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3616 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3617 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3618 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3619 | return null; |
| 3620 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3621 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3622 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3623 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3624 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3625 | return null; |
| 3626 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3627 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3628 | enforceTelephonyFeatureWithException(callingPackage, |
| 3629 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3630 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3631 | final long identity = Binder.clearCallingIdentity(); |
| 3632 | try { |
| 3633 | return phone.getImei(); |
| 3634 | } finally { |
| 3635 | Binder.restoreCallingIdentity(identity); |
| 3636 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3640 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3641 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3642 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3643 | callingFeatureId, "getPrimaryImei")) { |
| 3644 | throw new SecurityException("Caller does not have permission"); |
| 3645 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3646 | |
| 3647 | enforceTelephonyFeatureWithException(callingPackage, |
| 3648 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3649 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3650 | final long identity = Binder.clearCallingIdentity(); |
| 3651 | try { |
| 3652 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3653 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3654 | return phone.getImei(); |
| 3655 | } |
| 3656 | } |
| 3657 | throw new UnsupportedOperationException("Operation not supported"); |
| 3658 | } finally { |
| 3659 | Binder.restoreCallingIdentity(identity); |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3664 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3665 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3666 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3667 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3668 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3669 | String tac = null; |
| 3670 | if (phone != null) { |
| 3671 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3672 | try { |
| 3673 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3674 | } catch (IndexOutOfBoundsException e) { |
| 3675 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3676 | return null; |
| 3677 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3678 | } |
| 3679 | return tac; |
| 3680 | } |
| 3681 | |
| 3682 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3683 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3684 | try { |
| 3685 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3686 | } catch (SecurityException se) { |
| 3687 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3688 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3689 | + Binder.getCallingUid()); |
| 3690 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3691 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3692 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3693 | return null; |
| 3694 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3695 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3696 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3697 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3698 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3699 | return null; |
| 3700 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3701 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3702 | enforceTelephonyFeatureWithException(callingPackage, |
| 3703 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3704 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3705 | final long identity = Binder.clearCallingIdentity(); |
| 3706 | try { |
| 3707 | return phone.getMeid(); |
| 3708 | } finally { |
| 3709 | Binder.restoreCallingIdentity(identity); |
| 3710 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3714 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3715 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3716 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3717 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3718 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3719 | String manufacturerCode = null; |
| 3720 | if (phone != null) { |
| 3721 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3722 | try { |
| 3723 | manufacturerCode = |
| 3724 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3725 | } catch (IndexOutOfBoundsException e) { |
| 3726 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3727 | return null; |
| 3728 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3729 | } |
| 3730 | return manufacturerCode; |
| 3731 | } |
| 3732 | |
| 3733 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3734 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3735 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3736 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3737 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3738 | return null; |
| 3739 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3740 | int subId = phone.getSubId(); |
| 3741 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3742 | mApp, subId, callingPackage, callingFeatureId, |
| 3743 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3744 | return null; |
| 3745 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3747 | enforceTelephonyFeatureWithException(callingPackage, |
| 3748 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | final long identity = Binder.clearCallingIdentity(); |
| 3751 | try { |
| 3752 | return phone.getDeviceSvn(); |
| 3753 | } finally { |
| 3754 | Binder.restoreCallingIdentity(identity); |
| 3755 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3758 | @Override |
| 3759 | public int getSubscriptionCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3760 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3761 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3763 | final long identity = Binder.clearCallingIdentity(); |
| 3764 | try { |
| 3765 | final Phone phone = getPhone(subId); |
| 3766 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3767 | } finally { |
| 3768 | Binder.restoreCallingIdentity(identity); |
| 3769 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | @Override |
| 3773 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3774 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3775 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3776 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3777 | final long identity = Binder.clearCallingIdentity(); |
| 3778 | try { |
| 3779 | final Phone phone = getPhone(subId); |
| 3780 | return phone == null ? null : phone.getCarrierName(); |
| 3781 | } finally { |
| 3782 | Binder.restoreCallingIdentity(identity); |
| 3783 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3784 | } |
| 3785 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3786 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3787 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3788 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3789 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3790 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3791 | final long identity = Binder.clearCallingIdentity(); |
| 3792 | try { |
| 3793 | final Phone phone = getPhone(subId); |
| 3794 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3795 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3796 | } finally { |
| 3797 | Binder.restoreCallingIdentity(identity); |
| 3798 | } |
| 3799 | } |
| 3800 | |
| 3801 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3802 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3803 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3804 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3805 | "getSubscriptionSpecificCarrierName"); |
| 3806 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3807 | final long identity = Binder.clearCallingIdentity(); |
| 3808 | try { |
| 3809 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3810 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3811 | } finally { |
| 3812 | Binder.restoreCallingIdentity(identity); |
| 3813 | } |
| 3814 | } |
| 3815 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3816 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3817 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3818 | if (!isSubscriptionMccMnc) { |
| 3819 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3820 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3821 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3822 | if (phone == null) { |
| 3823 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3824 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3825 | |
| 3826 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3827 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3828 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3829 | final long identity = Binder.clearCallingIdentity(); |
| 3830 | try { |
| 3831 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3832 | } finally { |
| 3833 | Binder.restoreCallingIdentity(identity); |
| 3834 | } |
| 3835 | } |
| 3836 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3837 | // |
| 3838 | // Internal helper methods. |
| 3839 | // |
| 3840 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3841 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3842 | * Make sure the caller is the calling package itself |
| 3843 | * |
| 3844 | * @throws SecurityException if the caller is not the calling package |
| 3845 | */ |
| 3846 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3847 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3848 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3849 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3850 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3851 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3852 | } catch (PackageManager.NameNotFoundException e) { |
| 3853 | // packageUid is -1 |
| 3854 | } |
| 3855 | if (packageUid != callingUid) { |
| 3856 | throw new SecurityException(message + ": Package " + callingPackage |
| 3857 | + " does not belong to " + callingUid); |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3862 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3863 | * |
| 3864 | * @throws SecurityException if the caller does not have the required permission |
| 3865 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3866 | @VisibleForTesting |
| 3867 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3868 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3869 | } |
| 3870 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3871 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3872 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3873 | * |
| 3874 | * @throws SecurityException if the caller does not have the required permission |
| 3875 | */ |
| 3876 | @VisibleForTesting |
| 3877 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3878 | enforceReadPermission(null); |
| 3879 | } |
| 3880 | |
| 3881 | /** |
| 3882 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3883 | * |
| 3884 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3885 | */ |
| 3886 | @VisibleForTesting |
| 3887 | public void enforceReadPermission(String msg) { |
| 3888 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3889 | } |
| 3890 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3891 | private void enforceActiveEmergencySessionPermission() { |
| 3892 | mApp.enforceCallingOrSelfPermission( |
| 3893 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3894 | } |
| 3895 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3896 | /** |
| 3897 | * Make sure the caller has the CALL_PHONE permission. |
| 3898 | * |
| 3899 | * @throws SecurityException if the caller does not have the required permission |
| 3900 | */ |
| 3901 | private void enforceCallPermission() { |
| 3902 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3903 | } |
| 3904 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3905 | private void enforceSettingsPermission() { |
| 3906 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3909 | private void enforceRebootPermission() { |
| 3910 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3911 | } |
| 3912 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3913 | /** |
| 3914 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3915 | * @param message - log message to print. |
| 3916 | * @throws SecurityException if the caller does not have the required permission |
| 3917 | */ |
| 3918 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3919 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3920 | } |
| 3921 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3922 | private String createTelUrl(String number) { |
| 3923 | if (TextUtils.isEmpty(number)) { |
| 3924 | return null; |
| 3925 | } |
| 3926 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3927 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3928 | } |
| 3929 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3930 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3931 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3932 | } |
| 3933 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3934 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3935 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3938 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3939 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3942 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3943 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3944 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3947 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3948 | public int getActivePhoneTypeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3949 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3950 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 3951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3955 | if (phone == null) { |
| 3956 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3957 | } else { |
| 3958 | return phone.getPhoneType(); |
| 3959 | } |
| 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3962 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | /** |
| 3966 | * Returns the CDMA ERI icon index to display |
| 3967 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3968 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3969 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3970 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3971 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3972 | } |
| 3973 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3974 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3975 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3976 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3977 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3978 | mApp, subId, callingPackage, callingFeatureId, |
| 3979 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3980 | return -1; |
| 3981 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3982 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3983 | enforceTelephonyFeatureWithException(callingPackage, |
| 3984 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 3985 | "getCdmaEriIconIndexForSubscriber"); |
| 3986 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3987 | final long identity = Binder.clearCallingIdentity(); |
| 3988 | try { |
| 3989 | final Phone phone = getPhone(subId); |
| 3990 | if (phone != null) { |
| 3991 | return phone.getCdmaEriIconIndex(); |
| 3992 | } else { |
| 3993 | return -1; |
| 3994 | } |
| 3995 | } finally { |
| 3996 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3997 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
| 4000 | /** |
| 4001 | * Returns the CDMA ERI icon mode, |
| 4002 | * 0 - ON |
| 4003 | * 1 - FLASHING |
| 4004 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4005 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4006 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4007 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4008 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4009 | } |
| 4010 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4011 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4012 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4013 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4014 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4015 | mApp, subId, callingPackage, callingFeatureId, |
| 4016 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4017 | return -1; |
| 4018 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4019 | |
| 4020 | final long identity = Binder.clearCallingIdentity(); |
| 4021 | try { |
| 4022 | final Phone phone = getPhone(subId); |
| 4023 | if (phone != null) { |
| 4024 | return phone.getCdmaEriIconMode(); |
| 4025 | } else { |
| 4026 | return -1; |
| 4027 | } |
| 4028 | } finally { |
| 4029 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4030 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | /** |
| 4034 | * Returns the CDMA ERI text, |
| 4035 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4036 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4037 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4038 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4039 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4040 | } |
| 4041 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4042 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4043 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4044 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4045 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4046 | mApp, subId, callingPackage, callingFeatureId, |
| 4047 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4048 | return null; |
| 4049 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | final Phone phone = getPhone(subId); |
| 4054 | if (phone != null) { |
| 4055 | return phone.getCdmaEriText(); |
| 4056 | } else { |
| 4057 | return null; |
| 4058 | } |
| 4059 | } finally { |
| 4060 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4061 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4065 | * Returns the CDMA MDN. |
| 4066 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4067 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4068 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4070 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4071 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4072 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4073 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4074 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4075 | final long identity = Binder.clearCallingIdentity(); |
| 4076 | try { |
| 4077 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4078 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4079 | return phone.getLine1Number(); |
| 4080 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4081 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4082 | return null; |
| 4083 | } |
| 4084 | } finally { |
| 4085 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | /** |
| 4090 | * Returns the CDMA MIN. |
| 4091 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4092 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4093 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4095 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4096 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4097 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4098 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4099 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | final long identity = Binder.clearCallingIdentity(); |
| 4101 | try { |
| 4102 | final Phone phone = getPhone(subId); |
| 4103 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4104 | return phone.getCdmaMin(); |
| 4105 | } else { |
| 4106 | return null; |
| 4107 | } |
| 4108 | } finally { |
| 4109 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4110 | } |
| 4111 | } |
| 4112 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4113 | @Override |
| 4114 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4115 | INumberVerificationCallback callback, String callingPackage) { |
| 4116 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4117 | != PERMISSION_GRANTED) { |
| 4118 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4119 | } |
| 4120 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4121 | |
| 4122 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4123 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4124 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4125 | + "calling package: " + callingPackage |
| 4126 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4127 | } |
| 4128 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4129 | enforceTelephonyFeatureWithException(callingPackage, |
| 4130 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4131 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4132 | if (range == null) { |
| 4133 | throw new NullPointerException("Range must be non-null"); |
| 4134 | } |
| 4135 | |
| 4136 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4137 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4138 | |
| 4139 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4140 | } |
| 4141 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4142 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4143 | * Returns true if CDMA provisioning needs to run. |
| 4144 | */ |
| 4145 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4146 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4147 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4148 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4149 | final long identity = Binder.clearCallingIdentity(); |
| 4150 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4151 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4152 | } finally { |
| 4153 | Binder.restoreCallingIdentity(identity); |
| 4154 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4158 | * Sets the voice mail number of a given subId. |
| 4159 | */ |
| 4160 | @Override |
| 4161 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4162 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4163 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4164 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4165 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4166 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4167 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4168 | final long identity = Binder.clearCallingIdentity(); |
| 4169 | try { |
| 4170 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4171 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4172 | return success; |
| 4173 | } finally { |
| 4174 | Binder.restoreCallingIdentity(identity); |
| 4175 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4176 | } |
| 4177 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4178 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4179 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4180 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4181 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4182 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4183 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4184 | throw new SecurityException("caller must be system dialer"); |
| 4185 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4186 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4187 | enforceTelephonyFeatureWithException(callingPackage, |
| 4188 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4190 | final long identity = Binder.clearCallingIdentity(); |
| 4191 | try { |
| 4192 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4193 | if (phoneAccountHandle == null) { |
| 4194 | return null; |
| 4195 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4196 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4197 | } finally { |
| 4198 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4199 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4203 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4204 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4205 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4206 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4207 | mApp, subId, callingPackage, callingFeatureId, |
| 4208 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4209 | return null; |
| 4210 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4211 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4212 | enforceTelephonyFeatureWithException(callingPackage, |
| 4213 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4214 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4215 | final long identity = Binder.clearCallingIdentity(); |
| 4216 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4217 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4218 | } finally { |
| 4219 | Binder.restoreCallingIdentity(identity); |
| 4220 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4224 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4225 | VisualVoicemailSmsFilterSettings settings) { |
| 4226 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4227 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4228 | enforceTelephonyFeatureWithException(callingPackage, |
| 4229 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
| 4230 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4231 | final long identity = Binder.clearCallingIdentity(); |
| 4232 | try { |
| 4233 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4234 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4235 | } finally { |
| 4236 | Binder.restoreCallingIdentity(identity); |
| 4237 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4241 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4242 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4243 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4244 | enforceTelephonyFeatureWithException(callingPackage, |
| 4245 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4246 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4247 | final long identity = Binder.clearCallingIdentity(); |
| 4248 | try { |
| 4249 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4250 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | } finally { |
| 4252 | Binder.restoreCallingIdentity(identity); |
| 4253 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4257 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4258 | String callingPackage, int subId) { |
| 4259 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | |
| 4261 | final long identity = Binder.clearCallingIdentity(); |
| 4262 | try { |
| 4263 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4264 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4265 | } finally { |
| 4266 | Binder.restoreCallingIdentity(identity); |
| 4267 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4271 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4272 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4273 | |
| 4274 | final long identity = Binder.clearCallingIdentity(); |
| 4275 | try { |
| 4276 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4277 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4278 | } finally { |
| 4279 | Binder.restoreCallingIdentity(identity); |
| 4280 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4281 | } |
| 4282 | |
| 4283 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4284 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4285 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4286 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4287 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4288 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4289 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4290 | |
| 4291 | enforceTelephonyFeatureWithException(callingPackage, |
| 4292 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4293 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4294 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4295 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4296 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4297 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4298 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4299 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4300 | * Sets the voice activation state of a given subId. |
| 4301 | */ |
| 4302 | @Override |
| 4303 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4304 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4305 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4306 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4307 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4308 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4309 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
| 4312 | final Phone phone = getPhone(subId); |
| 4313 | if (phone != null) { |
| 4314 | phone.setVoiceActivationState(activationState); |
| 4315 | } else { |
| 4316 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4317 | } |
| 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4320 | } |
| 4321 | } |
| 4322 | |
| 4323 | /** |
| 4324 | * Sets the data activation state of a given subId. |
| 4325 | */ |
| 4326 | @Override |
| 4327 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4329 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4330 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4331 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4332 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4334 | final long identity = Binder.clearCallingIdentity(); |
| 4335 | try { |
| 4336 | final Phone phone = getPhone(subId); |
| 4337 | if (phone != null) { |
| 4338 | phone.setDataActivationState(activationState); |
| 4339 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4340 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | } |
| 4342 | } finally { |
| 4343 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | /** |
| 4348 | * Returns the voice activation state of a given subId. |
| 4349 | */ |
| 4350 | @Override |
| 4351 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4352 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4353 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4354 | enforceTelephonyFeatureWithException(callingPackage, |
| 4355 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4356 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4357 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4358 | final long identity = Binder.clearCallingIdentity(); |
| 4359 | try { |
| 4360 | if (phone != null) { |
| 4361 | return phone.getVoiceActivationState(); |
| 4362 | } else { |
| 4363 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4364 | } |
| 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | /** |
| 4371 | * Returns the data activation state of a given subId. |
| 4372 | */ |
| 4373 | @Override |
| 4374 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4375 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4376 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4377 | enforceTelephonyFeatureWithException(callingPackage, |
| 4378 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4379 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4380 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 | final long identity = Binder.clearCallingIdentity(); |
| 4382 | try { |
| 4383 | if (phone != null) { |
| 4384 | return phone.getDataActivationState(); |
| 4385 | } else { |
| 4386 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4387 | } |
| 4388 | } finally { |
| 4389 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4394 | * Returns the unread count of voicemails for a subId |
| 4395 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4396 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4397 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4398 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4399 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4400 | mApp, subId, callingPackage, callingFeatureId, |
| 4401 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4402 | return 0; |
| 4403 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4404 | final long identity = Binder.clearCallingIdentity(); |
| 4405 | try { |
| 4406 | final Phone phone = getPhone(subId); |
| 4407 | if (phone != null) { |
| 4408 | return phone.getVoiceMessageCount(); |
| 4409 | } else { |
| 4410 | return 0; |
| 4411 | } |
| 4412 | } finally { |
| 4413 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4414 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4418 | * returns true, if the device is in a state where both voice and data |
| 4419 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4420 | */ |
| 4421 | @Override |
| 4422 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4423 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4424 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4425 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4426 | final long identity = Binder.clearCallingIdentity(); |
| 4427 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4428 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4429 | } finally { |
| 4430 | Binder.restoreCallingIdentity(identity); |
| 4431 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4435 | * Send the dialer code if called from the current default dialer or the caller has |
| 4436 | * carrier privilege. |
| 4437 | * @param inputCode The dialer code to send |
| 4438 | */ |
| 4439 | @Override |
| 4440 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4441 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4442 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4443 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4444 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4445 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4446 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4447 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4448 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4449 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4450 | enforceTelephonyFeatureWithException(callingPackage, |
| 4451 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4452 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4453 | final long identity = Binder.clearCallingIdentity(); |
| 4454 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4455 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4456 | } finally { |
| 4457 | Binder.restoreCallingIdentity(identity); |
| 4458 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4459 | } |
| 4460 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4461 | @Override |
| 4462 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4463 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4464 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4465 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4466 | |
| 4467 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4468 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4469 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4470 | final long identity = Binder.clearCallingIdentity(); |
| 4471 | try { |
| 4472 | if (!isActiveSubscription(subId)) { |
| 4473 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4474 | } |
| 4475 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4476 | } finally { |
| 4477 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4478 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4479 | } |
| 4480 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4481 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4482 | public boolean isInEmergencySmsMode() { |
| 4483 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4484 | |
| 4485 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4486 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4487 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4488 | final long identity = Binder.clearCallingIdentity(); |
| 4489 | try { |
| 4490 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4491 | if (phone.isInEmergencySmsMode()) { |
| 4492 | return true; |
| 4493 | } |
| 4494 | } |
| 4495 | } finally { |
| 4496 | Binder.restoreCallingIdentity(identity); |
| 4497 | } |
| 4498 | return false; |
| 4499 | } |
| 4500 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4501 | /** |
| 4502 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4503 | * @param subId The subscription to use to check the configuration. |
| 4504 | * @param c The callback that will be used to send the result. |
| 4505 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4506 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4507 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4508 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4509 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4510 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4511 | |
| 4512 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4513 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4514 | "IMS not available on device."); |
| 4515 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4516 | final long token = Binder.clearCallingIdentity(); |
| 4517 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4518 | int slotId = getSlotIndexOrException(subId); |
| 4519 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4520 | |
| 4521 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4522 | if (controller != null) { |
| 4523 | ImsManager imsManager = controller.getImsManager(subId); |
| 4524 | if (imsManager != null) { |
| 4525 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4526 | } else { |
| 4527 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4528 | } |
| 4529 | } else { |
| 4530 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4531 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4532 | } catch (ImsException e) { |
| 4533 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4534 | } finally { |
| 4535 | Binder.restoreCallingIdentity(token); |
| 4536 | } |
| 4537 | } |
| 4538 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4539 | /** |
| 4540 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4541 | * @param subId The subscription to use to check the configuration. |
| 4542 | * @param c The callback that will be used to send the result. |
| 4543 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4544 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4545 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4546 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4547 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4548 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4549 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4550 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4551 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4552 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4553 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4554 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4555 | if (controller != null) { |
| 4556 | ImsManager imsManager = controller.getImsManager(subId); |
| 4557 | if (imsManager != null) { |
| 4558 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4559 | } else { |
| 4560 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4561 | + "is inactive, ignoring unregister."); |
| 4562 | // If the ImsManager is not valid, just return, since the callback |
| 4563 | // will already have been removed internally. |
| 4564 | } |
| 4565 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4566 | } finally { |
| 4567 | Binder.restoreCallingIdentity(token); |
| 4568 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4569 | } |
| 4570 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4571 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4572 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4573 | * @param subId The subscription to use to check the configuration. |
| 4574 | * @param c The callback that will be used to send the result. |
| 4575 | */ |
| 4576 | @Override |
| 4577 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4578 | throws RemoteException { |
| 4579 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4580 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4581 | |
| 4582 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4583 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4584 | "IMS not available on device."); |
| 4585 | } |
| 4586 | final long token = Binder.clearCallingIdentity(); |
| 4587 | try { |
| 4588 | int slotId = getSlotIndexOrException(subId); |
| 4589 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4590 | |
| 4591 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4592 | if (controller != null) { |
| 4593 | ImsManager imsManager = controller.getImsManager(subId); |
| 4594 | if (imsManager != null) { |
| 4595 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4596 | } else { |
| 4597 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4598 | } |
| 4599 | } else { |
| 4600 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4601 | } |
| 4602 | } catch (ImsException e) { |
| 4603 | throw new ServiceSpecificException(e.getCode()); |
| 4604 | } finally { |
| 4605 | Binder.restoreCallingIdentity(token); |
| 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | /** |
| 4610 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4611 | * @param subId The subscription to use to check the configuration. |
| 4612 | * @param c The callback that will be used to send the result. |
| 4613 | */ |
| 4614 | @Override |
| 4615 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4616 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4617 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4618 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4619 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4620 | } |
| 4621 | final long token = Binder.clearCallingIdentity(); |
| 4622 | |
| 4623 | try { |
| 4624 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4625 | if (controller != null) { |
| 4626 | ImsManager imsManager = controller.getImsManager(subId); |
| 4627 | if (imsManager != null) { |
| 4628 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4629 | } else { |
| 4630 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4631 | + "is inactive, ignoring unregister."); |
| 4632 | // If the ImsManager is not valid, just return, since the callback |
| 4633 | // will already have been removed internally. |
| 4634 | } |
| 4635 | } |
| 4636 | } finally { |
| 4637 | Binder.restoreCallingIdentity(token); |
| 4638 | } |
| 4639 | } |
| 4640 | |
| 4641 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4642 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4643 | */ |
| 4644 | @Override |
| 4645 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4646 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4647 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4648 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4649 | "IMS not available on device."); |
| 4650 | } |
| 4651 | final long token = Binder.clearCallingIdentity(); |
| 4652 | try { |
| 4653 | Phone phone = getPhone(subId); |
| 4654 | if (phone == null) { |
| 4655 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4656 | + subId + "'"); |
| 4657 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4658 | } |
| 4659 | phone.getImsRegistrationState(regState -> { |
| 4660 | try { |
| 4661 | consumer.accept((regState == null) |
| 4662 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4663 | } catch (RemoteException e) { |
| 4664 | // Ignore if the remote process is no longer available to call back. |
| 4665 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4666 | } |
| 4667 | }); |
| 4668 | } finally { |
| 4669 | Binder.restoreCallingIdentity(token); |
| 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | /** |
| 4674 | * Get the transport type for the IMS service registration state. |
| 4675 | */ |
| 4676 | @Override |
| 4677 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4678 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4679 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4680 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4681 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4682 | "IMS not available on device."); |
| 4683 | } |
| 4684 | final long token = Binder.clearCallingIdentity(); |
| 4685 | try { |
| 4686 | Phone phone = getPhone(subId); |
| 4687 | if (phone == null) { |
| 4688 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4689 | + subId + "'"); |
| 4690 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4691 | } |
| 4692 | phone.getImsRegistrationTech(regTech -> { |
| 4693 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4694 | int regTechConverted = (regTech == null) |
| 4695 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4696 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4697 | regTechConverted); |
| 4698 | try { |
| 4699 | consumer.accept(regTechConverted); |
| 4700 | } catch (RemoteException e) { |
| 4701 | // Ignore if the remote process is no longer available to call back. |
| 4702 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4703 | } |
| 4704 | }); |
| 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(token); |
| 4707 | } |
| 4708 | } |
| 4709 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4710 | /** |
| 4711 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4712 | * @param subId The subscription to use to check the configuration. |
| 4713 | * @param c The callback that will be used to send the result. |
| 4714 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4715 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4716 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4717 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4718 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4719 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4720 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4721 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4722 | "IMS not available on device."); |
| 4723 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4724 | final long token = Binder.clearCallingIdentity(); |
| 4725 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4726 | int slotId = getSlotIndexOrException(subId); |
| 4727 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4728 | |
| 4729 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4730 | if (controller != null) { |
| 4731 | ImsManager imsManager = controller.getImsManager(subId); |
| 4732 | if (imsManager != null) { |
| 4733 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4734 | } else { |
| 4735 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4736 | } |
| 4737 | } else { |
| 4738 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4739 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4740 | } catch (ImsException e) { |
| 4741 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4742 | } finally { |
| 4743 | Binder.restoreCallingIdentity(token); |
| 4744 | } |
| 4745 | } |
| 4746 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4747 | /** |
| 4748 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4749 | * @param subId The subscription to use to check the configuration. |
| 4750 | * @param c The callback that will be used to send the result. |
| 4751 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4752 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4753 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4754 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4755 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4756 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4757 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4758 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4759 | |
| 4760 | final long token = Binder.clearCallingIdentity(); |
| 4761 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4762 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4763 | if (controller != null) { |
| 4764 | ImsManager imsManager = controller.getImsManager(subId); |
| 4765 | if (imsManager != null) { |
| 4766 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4767 | } else { |
| 4768 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4769 | + " is inactive, ignoring unregister."); |
| 4770 | // If the ImsManager is not valid, just return, since the callback |
| 4771 | // will already have been removed internally. |
| 4772 | } |
| 4773 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4774 | } finally { |
| 4775 | Binder.restoreCallingIdentity(token); |
| 4776 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4780 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4781 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4782 | |
| 4783 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4784 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4785 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4786 | final long token = Binder.clearCallingIdentity(); |
| 4787 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4788 | int slotId = getSlotIndexOrException(subId); |
| 4789 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4790 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4791 | } catch (com.android.ims.ImsException e) { |
| 4792 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4793 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4794 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4795 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4796 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4797 | } finally { |
| 4798 | Binder.restoreCallingIdentity(token); |
| 4799 | } |
| 4800 | } |
| 4801 | |
| 4802 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4803 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4804 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4805 | |
| 4806 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4807 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4808 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4809 | final long token = Binder.clearCallingIdentity(); |
| 4810 | try { |
| 4811 | Phone phone = getPhone(subId); |
| 4812 | if (phone == null) return false; |
| 4813 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4814 | } catch (com.android.ims.ImsException e) { |
| 4815 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4816 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4817 | } finally { |
| 4818 | Binder.restoreCallingIdentity(token); |
| 4819 | } |
| 4820 | } |
| 4821 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4822 | /** |
| 4823 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4824 | * subscription. |
| 4825 | * @param subId The subscription to use to check the configuration. |
| 4826 | * @param callback The callback that will be used to send the result. |
| 4827 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4828 | * @param transportType The transport type of the MmTelFeature capability. |
| 4829 | */ |
| 4830 | @Override |
| 4831 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4832 | int transportType) { |
| 4833 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4834 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4835 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4836 | "IMS not available on device."); |
| 4837 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4838 | final long token = Binder.clearCallingIdentity(); |
| 4839 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4840 | int slotId = getSlotIndex(subId); |
| 4841 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4842 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4843 | + subId + "'"); |
| 4844 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4845 | } |
| 4846 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4847 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4848 | transportType, aBoolean -> { |
| 4849 | try { |
| 4850 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4851 | } catch (RemoteException e) { |
| 4852 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4853 | + "running. Ignore"); |
| 4854 | } |
| 4855 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4856 | } catch (ImsException e) { |
| 4857 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4858 | } finally { |
| 4859 | Binder.restoreCallingIdentity(token); |
| 4860 | } |
| 4861 | } |
| 4862 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4863 | /** |
| 4864 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4865 | * @param subId The subscription to use to check the configuration. |
| 4866 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4867 | @Override |
| 4868 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4869 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4870 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4871 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4872 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4873 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4874 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4875 | final long token = Binder.clearCallingIdentity(); |
| 4876 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4877 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4878 | // 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] | 4879 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4880 | } catch (ImsException e) { |
| 4881 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4882 | } finally { |
| 4883 | Binder.restoreCallingIdentity(token); |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4888 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4889 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4890 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4891 | |
| 4892 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4893 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4894 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4895 | final long identity = Binder.clearCallingIdentity(); |
| 4896 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4897 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4898 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4899 | // 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] | 4900 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4901 | } catch (ImsException e) { |
| 4902 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4903 | } finally { |
| 4904 | Binder.restoreCallingIdentity(identity); |
| 4905 | } |
| 4906 | } |
| 4907 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4908 | /** |
| 4909 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4910 | * @param subId The subscription to use to check the configuration. |
| 4911 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4912 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4913 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4914 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4915 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4916 | |
| 4917 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4918 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4919 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4920 | final long identity = Binder.clearCallingIdentity(); |
| 4921 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4922 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4923 | // 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] | 4924 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4925 | } catch (ImsException e) { |
| 4926 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4927 | } finally { |
| 4928 | Binder.restoreCallingIdentity(identity); |
| 4929 | } |
| 4930 | } |
| 4931 | |
| 4932 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4933 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4934 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4935 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4936 | |
| 4937 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4938 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 4939 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4940 | final long identity = Binder.clearCallingIdentity(); |
| 4941 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4942 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4943 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4944 | // 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] | 4945 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4946 | } catch (ImsException e) { |
| 4947 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4948 | } finally { |
| 4949 | Binder.restoreCallingIdentity(identity); |
| 4950 | } |
| 4951 | } |
| 4952 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4953 | /** |
| 4954 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4955 | * @param subId The subscription to use to check the configuration. |
| 4956 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4957 | @Override |
| 4958 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4959 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4960 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4961 | |
| 4962 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4963 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 4964 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4965 | final long identity = Binder.clearCallingIdentity(); |
| 4966 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4967 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4968 | // 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] | 4969 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4970 | } catch (ImsException e) { |
| 4971 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4978 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4979 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4980 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4981 | |
| 4982 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4983 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 4984 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4985 | final long identity = Binder.clearCallingIdentity(); |
| 4986 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4987 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4988 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4989 | // 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] | 4990 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4991 | } catch (ImsException e) { |
| 4992 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
| 4995 | } |
| 4996 | } |
| 4997 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4998 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4999 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5000 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5001 | * @param subId The subscription to use to check the configuration. |
| 5002 | */ |
| 5003 | @Override |
| 5004 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5005 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5006 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5007 | |
| 5008 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5009 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5010 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5011 | final long identity = Binder.clearCallingIdentity(); |
| 5012 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5013 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5014 | // 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] | 5015 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5016 | } catch (ImsException e) { |
| 5017 | throw new ServiceSpecificException(e.getCode()); |
| 5018 | } finally { |
| 5019 | Binder.restoreCallingIdentity(identity); |
| 5020 | } |
| 5021 | } |
| 5022 | |
| 5023 | /** |
| 5024 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5025 | * Requires MODIFY_PHONE_STATE permission. |
| 5026 | * @param subId The subscription to use to check the configuration. |
| 5027 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5028 | * false otherwise |
| 5029 | */ |
| 5030 | @Override |
| 5031 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5033 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5034 | |
| 5035 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5036 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5037 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5038 | final long identity = Binder.clearCallingIdentity(); |
| 5039 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5040 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5041 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5042 | // 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] | 5043 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5044 | } catch (ImsException e) { |
| 5045 | throw new ServiceSpecificException(e.getCode()); |
| 5046 | } finally { |
| 5047 | Binder.restoreCallingIdentity(identity); |
| 5048 | } |
| 5049 | } |
| 5050 | |
| 5051 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5052 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5053 | * @param subId The subscription to use to check the configuration. |
| 5054 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5055 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5056 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5057 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5058 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5059 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5060 | |
| 5061 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5062 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5063 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5064 | final long identity = Binder.clearCallingIdentity(); |
| 5065 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5066 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5067 | // 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] | 5068 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5069 | } catch (ImsException e) { |
| 5070 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5071 | } finally { |
| 5072 | Binder.restoreCallingIdentity(identity); |
| 5073 | } |
| 5074 | } |
| 5075 | |
| 5076 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5077 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5078 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5079 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5080 | |
| 5081 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5082 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5083 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5084 | final long identity = Binder.clearCallingIdentity(); |
| 5085 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5086 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5087 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5088 | // 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] | 5089 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5090 | } catch (ImsException e) { |
| 5091 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5092 | } finally { |
| 5093 | Binder.restoreCallingIdentity(identity); |
| 5094 | } |
| 5095 | } |
| 5096 | |
| 5097 | @Override |
| 5098 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5100 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5101 | |
| 5102 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5103 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5104 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5105 | final long identity = Binder.clearCallingIdentity(); |
| 5106 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5107 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5108 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5109 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5110 | } catch (ImsException e) { |
| 5111 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5112 | } finally { |
| 5113 | Binder.restoreCallingIdentity(identity); |
| 5114 | } |
| 5115 | } |
| 5116 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5117 | /** |
| 5118 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5119 | * @param subId The subscription to use to check the configuration. |
| 5120 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5121 | @Override |
| 5122 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5123 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5124 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5125 | |
| 5126 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5127 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5128 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5129 | final long identity = Binder.clearCallingIdentity(); |
| 5130 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5131 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5132 | // 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] | 5133 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5134 | } catch (ImsException e) { |
| 5135 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5136 | } finally { |
| 5137 | Binder.restoreCallingIdentity(identity); |
| 5138 | } |
| 5139 | } |
| 5140 | |
| 5141 | @Override |
| 5142 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5143 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5144 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5145 | |
| 5146 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5147 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5148 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5149 | final long identity = Binder.clearCallingIdentity(); |
| 5150 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5151 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5152 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5153 | // 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] | 5154 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5155 | } catch (ImsException e) { |
| 5156 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
| 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | @Override |
| 5163 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5164 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5165 | |
| 5166 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5167 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5168 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5169 | final long identity = Binder.clearCallingIdentity(); |
| 5170 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5171 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5172 | // 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] | 5173 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5174 | } catch (ImsException e) { |
| 5175 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5176 | } finally { |
| 5177 | Binder.restoreCallingIdentity(identity); |
| 5178 | } |
| 5179 | } |
| 5180 | |
| 5181 | @Override |
| 5182 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5184 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5185 | |
| 5186 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5187 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5188 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5189 | final long identity = Binder.clearCallingIdentity(); |
| 5190 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5191 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5192 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5193 | // 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] | 5194 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5195 | } catch (ImsException e) { |
| 5196 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5197 | } finally { |
| 5198 | Binder.restoreCallingIdentity(identity); |
| 5199 | } |
| 5200 | } |
| 5201 | |
| 5202 | @Override |
| 5203 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5205 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5206 | |
| 5207 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5208 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5209 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5210 | final long identity = Binder.clearCallingIdentity(); |
| 5211 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5212 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5213 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5214 | // 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] | 5215 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5216 | } catch (ImsException e) { |
| 5217 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5218 | } finally { |
| 5219 | Binder.restoreCallingIdentity(identity); |
| 5220 | } |
| 5221 | } |
| 5222 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5223 | /** |
| 5224 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5225 | * @param subId The subscription to use to check the configuration. |
| 5226 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5227 | @Override |
| 5228 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5229 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5230 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5231 | |
| 5232 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5233 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5234 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5235 | final long identity = Binder.clearCallingIdentity(); |
| 5236 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5237 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5238 | // 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] | 5239 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5240 | } catch (ImsException e) { |
| 5241 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5242 | } finally { |
| 5243 | Binder.restoreCallingIdentity(identity); |
| 5244 | } |
| 5245 | } |
| 5246 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5247 | @Override |
| 5248 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5249 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5250 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5253 | if (!isImsAvailableOnDevice()) { |
| 5254 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5255 | "IMS not available on device."); |
| 5256 | } |
| 5257 | int slotId = getSlotIndexOrException(subId); |
| 5258 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5259 | |
| 5260 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5261 | if (controller != null) { |
| 5262 | ImsManager imsManager = controller.getImsManager(subId); |
| 5263 | if (imsManager != null) { |
| 5264 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5265 | } else { |
| 5266 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5267 | } |
| 5268 | } else { |
| 5269 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5270 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5271 | } catch (ImsException e) { |
| 5272 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5273 | } finally { |
| 5274 | Binder.restoreCallingIdentity(identity); |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | @Override |
| 5279 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5280 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5281 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5282 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5283 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5284 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5285 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5286 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5287 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5288 | if (controller != null) { |
| 5289 | ImsManager imsManager = controller.getImsManager(subId); |
| 5290 | if (imsManager != null) { |
| 5291 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5292 | } else { |
| 5293 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5294 | + " is inactive, ignoring unregister."); |
| 5295 | // If the ImsManager is not valid, just return, since the callback will already |
| 5296 | // have been removed internally. |
| 5297 | } |
| 5298 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5299 | } finally { |
| 5300 | Binder.restoreCallingIdentity(identity); |
| 5301 | } |
| 5302 | } |
| 5303 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5304 | @Override |
| 5305 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5306 | IFeatureProvisioningCallback callback) { |
| 5307 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5308 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5309 | |
| 5310 | final long identity = Binder.clearCallingIdentity(); |
| 5311 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5312 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5313 | } |
| 5314 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5315 | try { |
| 5316 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5317 | if (controller == null) { |
| 5318 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5319 | "Device does not support IMS"); |
| 5320 | } |
| 5321 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5322 | } finally { |
| 5323 | Binder.restoreCallingIdentity(identity); |
| 5324 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | @Override |
| 5328 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5329 | IFeatureProvisioningCallback callback) { |
| 5330 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5331 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5332 | |
| 5333 | final long identity = Binder.clearCallingIdentity(); |
| 5334 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5335 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5336 | } |
| 5337 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5338 | try { |
| 5339 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5340 | if (controller == null) { |
| 5341 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5342 | return; |
| 5343 | } |
| 5344 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5345 | } finally { |
| 5346 | Binder.restoreCallingIdentity(identity); |
| 5347 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5348 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5349 | |
| 5350 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5352 | message); |
| 5353 | } |
| 5354 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5355 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5356 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5357 | boolean isProvisioned) { |
| 5358 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5359 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5360 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5361 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5362 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5363 | final long identity = Binder.clearCallingIdentity(); |
| 5364 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5365 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5366 | if (controller == null) { |
| 5367 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5368 | return; |
| 5369 | } |
| 5370 | controller.setRcsProvisioningStatusForCapability( |
| 5371 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5372 | } finally { |
| 5373 | Binder.restoreCallingIdentity(identity); |
| 5374 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | |
| 5378 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5379 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5380 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5381 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5382 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5383 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5384 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5385 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5386 | final long identity = Binder.clearCallingIdentity(); |
| 5387 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5388 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5389 | if (controller == null) { |
| 5390 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5391 | |
| 5392 | // device does not support IMS, this method will return true always. |
| 5393 | return true; |
| 5394 | } |
| 5395 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5396 | } finally { |
| 5397 | Binder.restoreCallingIdentity(identity); |
| 5398 | } |
| 5399 | } |
| 5400 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5401 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5402 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5403 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5404 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5405 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5406 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5407 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5408 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5409 | final long identity = Binder.clearCallingIdentity(); |
| 5410 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5411 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5412 | if (controller == null) { |
| 5413 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5414 | return; |
| 5415 | } |
| 5416 | controller.setImsProvisioningStatusForCapability( |
| 5417 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5418 | } finally { |
| 5419 | Binder.restoreCallingIdentity(identity); |
| 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | @Override |
| 5424 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5425 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5426 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5427 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5428 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5429 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5430 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5431 | final long identity = Binder.clearCallingIdentity(); |
| 5432 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5433 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5434 | if (controller == null) { |
| 5435 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5436 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5437 | // device does not support IMS, this method will return true always. |
| 5438 | return true; |
| 5439 | } |
| 5440 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
| 5444 | } |
| 5445 | |
| 5446 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5447 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5448 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5449 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5450 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5451 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5452 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5453 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5454 | final long identity = Binder.clearCallingIdentity(); |
| 5455 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5456 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5457 | if (controller == null) { |
| 5458 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5459 | |
| 5460 | // device does not support IMS, this method will return false |
| 5461 | return false; |
| 5462 | } |
| 5463 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5464 | } finally { |
| 5465 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5466 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5470 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5471 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5472 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5473 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5474 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5475 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5476 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5477 | final long identity = Binder.clearCallingIdentity(); |
| 5478 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5479 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5480 | if (controller == null) { |
| 5481 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5482 | |
| 5483 | // device does not support IMS, this method will return false |
| 5484 | return false; |
| 5485 | } |
| 5486 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5487 | } finally { |
| 5488 | Binder.restoreCallingIdentity(identity); |
| 5489 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5490 | } |
| 5491 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5492 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5493 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5494 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5495 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5496 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5497 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5498 | mApp, subId, "getImsProvisioningInt"); |
| 5499 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5500 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5501 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5502 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5503 | final long identity = Binder.clearCallingIdentity(); |
| 5504 | try { |
| 5505 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5506 | int slotId = getSlotIndex(subId); |
| 5507 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5508 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5509 | + subId + "' for key:" + key); |
| 5510 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5511 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5512 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5513 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5514 | if (controller == null) { |
| 5515 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5516 | |
| 5517 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5518 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5519 | } |
| 5520 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5521 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5522 | return retVal; |
| 5523 | } |
| 5524 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5525 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5526 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5527 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5528 | + subId + "' for key:" + key); |
| 5529 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5530 | } finally { |
| 5531 | Binder.restoreCallingIdentity(identity); |
| 5532 | } |
| 5533 | } |
| 5534 | |
| 5535 | @Override |
| 5536 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5537 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5538 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5539 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5540 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5541 | mApp, subId, "getImsProvisioningString"); |
| 5542 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5543 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5544 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5545 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5546 | final long identity = Binder.clearCallingIdentity(); |
| 5547 | try { |
| 5548 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5549 | int slotId = getSlotIndex(subId); |
| 5550 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5551 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5552 | + subId + "' for key:" + key); |
| 5553 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5554 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5555 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5556 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5557 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5558 | + subId + "' for key:" + key); |
| 5559 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
| 5562 | } |
| 5563 | } |
| 5564 | |
| 5565 | @Override |
| 5566 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5567 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5568 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5569 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5570 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5571 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5572 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5573 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5574 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5575 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5576 | final long identity = Binder.clearCallingIdentity(); |
| 5577 | try { |
| 5578 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5579 | int slotId = getSlotIndex(subId); |
| 5580 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5581 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5582 | + subId + "' for key:" + key); |
| 5583 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5584 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5585 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5586 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5587 | if (controller == null) { |
| 5588 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5589 | |
| 5590 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5591 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5592 | } |
| 5593 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5594 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5595 | return retVal; |
| 5596 | } |
| 5597 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5598 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5599 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5600 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5601 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5602 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5603 | } finally { |
| 5604 | Binder.restoreCallingIdentity(identity); |
| 5605 | } |
| 5606 | } |
| 5607 | |
| 5608 | @Override |
| 5609 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5610 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5611 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5612 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5614 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5615 | |
| 5616 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5617 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5618 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5619 | final long identity = Binder.clearCallingIdentity(); |
| 5620 | try { |
| 5621 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5622 | int slotId = getSlotIndex(subId); |
| 5623 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5624 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5625 | + subId + "' for key:" + key); |
| 5626 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5627 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5628 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5629 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5630 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5631 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5632 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5633 | } finally { |
| 5634 | Binder.restoreCallingIdentity(identity); |
| 5635 | } |
| 5636 | } |
| 5637 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5638 | /** |
| 5639 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5640 | * for the given slot ID or no ImsResolver instance has been created. |
| 5641 | * @param slotId The slot ID that the IMS service is created for. |
| 5642 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5643 | */ |
| 5644 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5645 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5646 | ImsFeature.FEATURE_MMTEL)) { |
| 5647 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5648 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5649 | } |
| 5650 | } |
| 5651 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5652 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5653 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5654 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5655 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5656 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5657 | } |
| 5658 | return slotId; |
| 5659 | } |
| 5660 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5661 | private int getSlotIndex(int subId) { |
| 5662 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5663 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5664 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5665 | } |
| 5666 | return slotId; |
| 5667 | } |
| 5668 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5669 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5670 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5671 | */ |
| 5672 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5673 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5674 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5675 | try { |
| 5676 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5677 | } catch (SecurityException se) { |
| 5678 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5679 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5680 | + Binder.getCallingUid()); |
| 5681 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5682 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5683 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5684 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5685 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5686 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5687 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5688 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5689 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5690 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5691 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5692 | enforceTelephonyFeatureWithException(callingPackage, |
| 5693 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5694 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | final long identity = Binder.clearCallingIdentity(); |
| 5696 | try { |
| 5697 | final Phone phone = getPhone(subId); |
| 5698 | if (phone != null) { |
| 5699 | return phone.getServiceState().getDataNetworkType(); |
| 5700 | } else { |
| 5701 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5702 | } |
| 5703 | } finally { |
| 5704 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5705 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | /** |
| 5709 | * Returns the data network type |
| 5710 | */ |
| 5711 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5712 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5713 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5714 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | /** |
| 5718 | * Returns the data network type for a subId |
| 5719 | */ |
| 5720 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5721 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5722 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5723 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5724 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5725 | mApp, functionName)) { |
| 5726 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5727 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5728 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5729 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5730 | } |
| 5731 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5732 | enforceTelephonyFeatureWithException(callingPackage, |
| 5733 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5735 | final long identity = Binder.clearCallingIdentity(); |
| 5736 | try { |
| 5737 | final Phone phone = getPhone(subId); |
| 5738 | if (phone != null) { |
| 5739 | return phone.getServiceState().getDataNetworkType(); |
| 5740 | } else { |
| 5741 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5742 | } |
| 5743 | } finally { |
| 5744 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5745 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5746 | } |
| 5747 | |
| 5748 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5749 | * Returns the Voice network type for a subId |
| 5750 | */ |
| 5751 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5752 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5753 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5754 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5755 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5756 | mApp, functionName)) { |
| 5757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5758 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5759 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5760 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5761 | } |
| 5762 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5763 | enforceTelephonyFeatureWithException(callingPackage, |
| 5764 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5765 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | final long identity = Binder.clearCallingIdentity(); |
| 5767 | try { |
| 5768 | final Phone phone = getPhone(subId); |
| 5769 | if (phone != null) { |
| 5770 | return phone.getServiceState().getVoiceNetworkType(); |
| 5771 | } else { |
| 5772 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5773 | } |
| 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | /** |
| 5780 | * @return true if a ICC card is present |
| 5781 | */ |
| 5782 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5783 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5784 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5785 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5789 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5790 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5791 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5792 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5793 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5794 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5796 | final long identity = Binder.clearCallingIdentity(); |
| 5797 | try { |
| 5798 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5799 | if (phone != null) { |
| 5800 | return phone.getIccCard().hasIccCard(); |
| 5801 | } else { |
| 5802 | return false; |
| 5803 | } |
| 5804 | } finally { |
| 5805 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5806 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5807 | } |
| 5808 | |
| 5809 | /** |
| 5810 | * Return if the current radio is LTE on CDMA. This |
| 5811 | * is a tri-state return value as for a period of time |
| 5812 | * the mode may be unknown. |
| 5813 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5814 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5815 | * @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] | 5816 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5817 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5818 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5819 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5820 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5821 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5822 | } |
| 5823 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5824 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5825 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5826 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5827 | try { |
| 5828 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5829 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5830 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5831 | } |
| 5832 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5833 | enforceTelephonyFeatureWithException(callingPackage, |
| 5834 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5835 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5836 | final long identity = Binder.clearCallingIdentity(); |
| 5837 | try { |
| 5838 | final Phone phone = getPhone(subId); |
| 5839 | if (phone == null) { |
| 5840 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5841 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5842 | return TelephonyProperties.lte_on_cdma_device() |
| 5843 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5844 | } |
| 5845 | } finally { |
| 5846 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5847 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5848 | } |
| 5849 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5850 | /** |
| 5851 | * {@hide} |
| 5852 | * Returns Default subId, 0 in the case of single standby. |
| 5853 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5854 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5855 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5856 | } |
| 5857 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5858 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5859 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5862 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5863 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5864 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5865 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5866 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5867 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5868 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5869 | } |
| 5870 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5871 | /** |
| 5872 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5873 | */ |
| 5874 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5875 | final long identity = Binder.clearCallingIdentity(); |
| 5876 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5877 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5878 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5879 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5880 | } finally { |
| 5881 | Binder.restoreCallingIdentity(identity); |
| 5882 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | /** |
| 5886 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5887 | */ |
| 5888 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5889 | final long identity = Binder.clearCallingIdentity(); |
| 5890 | try { |
| 5891 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5892 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5893 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5894 | } finally { |
| 5895 | Binder.restoreCallingIdentity(identity); |
| 5896 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5897 | } |
| 5898 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5899 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5900 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5901 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5902 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5903 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5904 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5905 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5906 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5907 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5908 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5909 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5910 | } |
| 5911 | return PhoneFactory.getPhone(phoneId); |
| 5912 | } |
| 5913 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5914 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5915 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5916 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5917 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5918 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5919 | /*message=*/ "iccOpenLogicalChannel"); |
| 5920 | |
| 5921 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5922 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5923 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5924 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5925 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5926 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5927 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5928 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5929 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5930 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5931 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5932 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5933 | Phone phone; |
| 5934 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5936 | mApp, request.subId, message); |
| 5937 | phone = getPhoneFromSubId(request.subId); |
| 5938 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5939 | enforceModifyPermission(); |
| 5940 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5941 | } else { |
| 5942 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5943 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5944 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5948 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5951 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5953 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5954 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5955 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5956 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5957 | loge("The calling package is not allowed to access ISD-R."); |
| 5958 | throw new SecurityException( |
| 5959 | "The calling package is not allowed to access ISD-R."); |
| 5960 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5961 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5962 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5963 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5964 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5965 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5966 | return response; |
| 5967 | } finally { |
| 5968 | Binder.restoreCallingIdentity(identity); |
| 5969 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5973 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5974 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5975 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 5976 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5977 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5978 | /*message=*/"iccCloseLogicalChannel"); |
| 5979 | |
| 5980 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5981 | |
| 5982 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5983 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5984 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5985 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5986 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5987 | // before this feature is enabled, this API should only return false if |
| 5988 | // the operation fails instead of throwing runtime exception for |
| 5989 | // backward-compatibility. |
| 5990 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5991 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | final long identity = Binder.clearCallingIdentity(); |
| 5993 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5994 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5995 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5996 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5997 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5998 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5999 | Boolean success = false; |
| 6000 | if (result instanceof RuntimeException) { |
| 6001 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6002 | if (shouldThrowExceptionOnFailure) { |
| 6003 | throw (RuntimeException) result; |
| 6004 | } else { |
| 6005 | return false; |
| 6006 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6007 | } else if (result instanceof Boolean) { |
| 6008 | success = (Boolean) result; |
| 6009 | } else { |
| 6010 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6011 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6012 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | return success; |
| 6014 | } finally { |
| 6015 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6016 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6020 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6021 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6022 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6023 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6024 | |
| 6025 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6026 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6027 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6028 | if (DBG) { |
| 6029 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6030 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6031 | + p3 + " data=" + data); |
| 6032 | } |
| 6033 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6034 | command, p1, p2, p3, data); |
| 6035 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6036 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6037 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6038 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6039 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6040 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6041 | |
| 6042 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6043 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6044 | "iccTransmitApduLogicalChannelBySlot"); |
| 6045 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6046 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6047 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6048 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6049 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6050 | } |
| 6051 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6052 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6053 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6054 | } |
| 6055 | |
| 6056 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6057 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6058 | final long identity = Binder.clearCallingIdentity(); |
| 6059 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6060 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6061 | return ""; |
| 6062 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6063 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6064 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6065 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6066 | null /* workSource */); |
| 6067 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6068 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6069 | // Append the returned status code to the end of the response payload. |
| 6070 | String s = Integer.toHexString( |
| 6071 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6072 | if (response.payload != null) { |
| 6073 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6074 | } |
| 6075 | return s; |
| 6076 | } finally { |
| 6077 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6078 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6079 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6080 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6081 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6082 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6083 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6085 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6086 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6087 | |
| 6088 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6089 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6090 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6091 | if (DBG) { |
| 6092 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6093 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6094 | } |
| 6095 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6096 | cla, command, p1, p2, p3, data); |
| 6097 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6098 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6099 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6100 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6101 | 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] | 6102 | enforceModifyPermission(); |
| 6103 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6104 | |
| 6105 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6106 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6107 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6108 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6109 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6110 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6111 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6112 | } |
| 6113 | |
| 6114 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6115 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6116 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6117 | } |
| 6118 | |
| 6119 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6120 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6121 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6122 | final long identity = Binder.clearCallingIdentity(); |
| 6123 | try { |
| 6124 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6125 | && TextUtils.equals(ISDR_AID, data)) { |
| 6126 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6127 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6128 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | if (bestComponent == null |
| 6130 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6131 | loge("The calling package is not allowed to select ISD-R."); |
| 6132 | throw new SecurityException( |
| 6133 | "The calling package is not allowed to select ISD-R."); |
| 6134 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6135 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6136 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6138 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6139 | null /* workSource */); |
| 6140 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6141 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6142 | // Append the returned status code to the end of the response payload. |
| 6143 | String s = Integer.toHexString( |
| 6144 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6145 | if (response.payload != null) { |
| 6146 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6147 | } |
| 6148 | return s; |
| 6149 | } finally { |
| 6150 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6151 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6155 | 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] | 6156 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6158 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6159 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6160 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6161 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6163 | final long identity = Binder.clearCallingIdentity(); |
| 6164 | try { |
| 6165 | if (DBG) { |
| 6166 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6167 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6168 | } |
| 6169 | |
| 6170 | IccIoResult response = |
| 6171 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6172 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6173 | subId); |
| 6174 | |
| 6175 | if (DBG) { |
| 6176 | log("Exchange SIM_IO [R]" + response); |
| 6177 | } |
| 6178 | |
| 6179 | byte[] result = null; |
| 6180 | int length = 2; |
| 6181 | if (response.payload != null) { |
| 6182 | length = 2 + response.payload.length; |
| 6183 | result = new byte[length]; |
| 6184 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6185 | } else { |
| 6186 | result = new byte[length]; |
| 6187 | } |
| 6188 | |
| 6189 | result[length - 1] = (byte) response.sw2; |
| 6190 | result[length - 2] = (byte) response.sw1; |
| 6191 | return result; |
| 6192 | } finally { |
| 6193 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6194 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6195 | } |
| 6196 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6197 | /** |
| 6198 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6199 | * on a particular subscription |
| 6200 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6201 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6202 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6203 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6204 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6205 | return null; |
| 6206 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6207 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6208 | enforceTelephonyFeatureWithException(callingPackage, |
| 6209 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6210 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6211 | final long identity = Binder.clearCallingIdentity(); |
| 6212 | try { |
| 6213 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6214 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6215 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6216 | return null; |
| 6217 | } |
| 6218 | Object response = sendRequest( |
| 6219 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6220 | if (response instanceof String[]) { |
| 6221 | return (String[]) response; |
| 6222 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6223 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6225 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6226 | } finally { |
| 6227 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6228 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6229 | } |
| 6230 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6231 | /** |
| 6232 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6233 | * subscription. |
| 6234 | * |
| 6235 | * @param subId the id of the subscription. |
| 6236 | * @param appType the uicc app type, must be USIM or SIM. |
| 6237 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6238 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6239 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6240 | * @return number of fplmns that is successfully written to the SIM. |
| 6241 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6242 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6243 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6244 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6245 | mApp, subId, "setForbiddenPlmns"); |
| 6246 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6247 | enforceTelephonyFeatureWithException(callingPackage, |
| 6248 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6249 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6250 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6251 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6252 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6253 | } |
| 6254 | if (fplmns == null) { |
| 6255 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6256 | } |
| 6257 | for (String fplmn : fplmns) { |
| 6258 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6259 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6260 | } |
| 6261 | } |
| 6262 | final long identity = Binder.clearCallingIdentity(); |
| 6263 | try { |
| 6264 | Object response = sendRequest( |
| 6265 | CMD_SET_FORBIDDEN_PLMNS, |
| 6266 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6267 | subId); |
| 6268 | return (int) response; |
| 6269 | } finally { |
| 6270 | Binder.restoreCallingIdentity(identity); |
| 6271 | } |
| 6272 | } |
| 6273 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6274 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6275 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6276 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6277 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6278 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6279 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6280 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6281 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | final long identity = Binder.clearCallingIdentity(); |
| 6283 | try { |
| 6284 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6285 | if (response.payload == null) { |
| 6286 | return ""; |
| 6287 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6288 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | // Append the returned status code to the end of the response payload. |
| 6290 | String s = Integer.toHexString( |
| 6291 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6292 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6293 | return s; |
| 6294 | } finally { |
| 6295 | Binder.restoreCallingIdentity(identity); |
| 6296 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6297 | } |
| 6298 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6299 | /** |
| 6300 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6301 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6302 | * |
| 6303 | * @param itemID the ID of the item to read |
| 6304 | * @return the NV item as a String, or null on error. |
| 6305 | */ |
| 6306 | @Override |
| 6307 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6308 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6310 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | |
| 6312 | final long identity = Binder.clearCallingIdentity(); |
| 6313 | try { |
| 6314 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6315 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6316 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6317 | return value; |
| 6318 | } finally { |
| 6319 | Binder.restoreCallingIdentity(identity); |
| 6320 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6321 | } |
| 6322 | |
| 6323 | /** |
| 6324 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6325 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6326 | * |
| 6327 | * @param itemID the ID of the item to read |
| 6328 | * @param itemValue the value to write, as a String |
| 6329 | * @return true on success; false on any failure |
| 6330 | */ |
| 6331 | @Override |
| 6332 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6333 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6335 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6336 | |
| 6337 | final long identity = Binder.clearCallingIdentity(); |
| 6338 | try { |
| 6339 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6340 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6341 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6342 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6343 | return success; |
| 6344 | } finally { |
| 6345 | Binder.restoreCallingIdentity(identity); |
| 6346 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | /** |
| 6350 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6351 | * Used for device configuration by some CDMA operators. |
| 6352 | * |
| 6353 | * @param preferredRoamingList byte array containing the new PRL |
| 6354 | * @return true on success; false on any failure |
| 6355 | */ |
| 6356 | @Override |
| 6357 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6358 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6359 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6360 | |
| 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | try { |
| 6363 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6364 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6365 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6366 | return success; |
| 6367 | } finally { |
| 6368 | Binder.restoreCallingIdentity(identity); |
| 6369 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6370 | } |
| 6371 | |
| 6372 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6373 | * 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] | 6374 | * Used for device configuration by some CDMA operators. |
| 6375 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6376 | * @param slotIndex - device slot. |
| 6377 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6378 | * @return true on success; false on any failure |
| 6379 | */ |
| 6380 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6381 | public boolean resetModemConfig(int slotIndex) { |
| 6382 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6383 | if (phone != null) { |
| 6384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6385 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6387 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6388 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6389 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6390 | final long identity = Binder.clearCallingIdentity(); |
| 6391 | try { |
| 6392 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6393 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6394 | return success; |
| 6395 | } finally { |
| 6396 | Binder.restoreCallingIdentity(identity); |
| 6397 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6398 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6399 | return false; |
| 6400 | } |
| 6401 | |
| 6402 | /** |
| 6403 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6404 | * |
| 6405 | * @param slotIndex - device slot. |
| 6406 | * |
| 6407 | * @return true on success; false on any failure |
| 6408 | */ |
| 6409 | @Override |
| 6410 | public boolean rebootModem(int slotIndex) { |
| 6411 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6412 | if (phone != null) { |
| 6413 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6414 | mApp, phone.getSubId(), "rebootModem"); |
| 6415 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6416 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6417 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6418 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6419 | final long identity = Binder.clearCallingIdentity(); |
| 6420 | try { |
| 6421 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6422 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6423 | return success; |
| 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
| 6426 | } |
| 6427 | } |
| 6428 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6429 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6430 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6431 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6432 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6433 | * {@link #disableIms(int)}. |
| 6434 | * @param slotIndex device slot. |
| 6435 | */ |
| 6436 | public void resetIms(int slotIndex) { |
| 6437 | enforceModifyPermission(); |
| 6438 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6439 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6440 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6441 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6442 | final long identity = Binder.clearCallingIdentity(); |
| 6443 | try { |
| 6444 | if (mImsResolver == null) { |
| 6445 | // may happen if the does not support IMS. |
| 6446 | return; |
| 6447 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6448 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6449 | } finally { |
| 6450 | Binder.restoreCallingIdentity(identity); |
| 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6455 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6456 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6457 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6458 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6459 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6460 | |
| 6461 | final long identity = Binder.clearCallingIdentity(); |
| 6462 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6463 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6464 | // may happen if the device does not support IMS. |
| 6465 | return; |
| 6466 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6467 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6468 | } finally { |
| 6469 | Binder.restoreCallingIdentity(identity); |
| 6470 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6474 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6475 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6476 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6477 | public void disableIms(int slotId) { |
| 6478 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6479 | |
| 6480 | final long identity = Binder.clearCallingIdentity(); |
| 6481 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6482 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6483 | // may happen if the device does not support IMS. |
| 6484 | return; |
| 6485 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6486 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6487 | } finally { |
| 6488 | Binder.restoreCallingIdentity(identity); |
| 6489 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6493 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6494 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6495 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6496 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6497 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6498 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6499 | |
| 6500 | final long identity = Binder.clearCallingIdentity(); |
| 6501 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6502 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6503 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6504 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6505 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6506 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6507 | } finally { |
| 6508 | Binder.restoreCallingIdentity(identity); |
| 6509 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6510 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6511 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6512 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6513 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6514 | @Override |
| 6515 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6516 | enforceModifyPermission(); |
| 6517 | |
| 6518 | final long identity = Binder.clearCallingIdentity(); |
| 6519 | try { |
| 6520 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6521 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6522 | } finally { |
| 6523 | Binder.restoreCallingIdentity(identity); |
| 6524 | } |
| 6525 | } |
| 6526 | |
| 6527 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6528 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6529 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6530 | */ |
| 6531 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6532 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6533 | |
| 6534 | final long identity = Binder.clearCallingIdentity(); |
| 6535 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6536 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6537 | // may happen if the device does not support IMS. |
| 6538 | return null; |
| 6539 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6540 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(identity); |
| 6543 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6544 | } |
| 6545 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6546 | /** |
| 6547 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6548 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6549 | */ |
| 6550 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6551 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6552 | |
| 6553 | final long identity = Binder.clearCallingIdentity(); |
| 6554 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6555 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6556 | // may happen if the device does not support IMS. |
| 6557 | return null; |
| 6558 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6559 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | } finally { |
| 6561 | Binder.restoreCallingIdentity(identity); |
| 6562 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6563 | } |
| 6564 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6565 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6566 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6567 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6568 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6569 | * @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] | 6570 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6571 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6572 | * @param packageName The name of the package that the current configuration will be replaced |
| 6573 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6574 | * @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] | 6575 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6576 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6577 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6578 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6579 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6580 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6581 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6582 | final long identity = Binder.clearCallingIdentity(); |
| 6583 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6584 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6585 | // may happen if the device does not support IMS. |
| 6586 | return false; |
| 6587 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6588 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6589 | for (int featureType : featureTypes) { |
| 6590 | featureConfig.put(featureType, packageName); |
| 6591 | } |
| 6592 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6593 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 | } finally { |
| 6595 | Binder.restoreCallingIdentity(identity); |
| 6596 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6597 | } |
| 6598 | |
| 6599 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6600 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6601 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6602 | * |
| 6603 | * This should only be used for testing. |
| 6604 | * |
| 6605 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6606 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6607 | */ |
| 6608 | @Override |
| 6609 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6610 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6611 | "clearCarrierImsServiceOverride"); |
| 6612 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6613 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6614 | |
| 6615 | final long identity = Binder.clearCallingIdentity(); |
| 6616 | try { |
| 6617 | if (mImsResolver == null) { |
| 6618 | // may happen if the device does not support IMS. |
| 6619 | return false; |
| 6620 | } |
| 6621 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6622 | } finally { |
| 6623 | Binder.restoreCallingIdentity(identity); |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6628 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6629 | * |
| 6630 | * @param slotId The slot that the ImsService is associated with. |
| 6631 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6632 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6633 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6634 | * @return the package name of the ImsService configuration. |
| 6635 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6636 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6637 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6638 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6639 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6640 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6641 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6642 | final long identity = Binder.clearCallingIdentity(); |
| 6643 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6644 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6645 | // may happen if the device does not support IMS. |
| 6646 | return ""; |
| 6647 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6648 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6649 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6650 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6651 | } finally { |
| 6652 | Binder.restoreCallingIdentity(identity); |
| 6653 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6654 | } |
| 6655 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6656 | /** |
| 6657 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6658 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6659 | * @param callback A callback with an integer containing the |
| 6660 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6661 | */ |
| 6662 | @Override |
| 6663 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6664 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6665 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6666 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6667 | "IMS not available on device."); |
| 6668 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6669 | final long token = Binder.clearCallingIdentity(); |
| 6670 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6671 | int slotId = getSlotIndex(subId); |
| 6672 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6673 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6674 | + subId + "'"); |
| 6675 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6676 | } |
| 6677 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6678 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6679 | try { |
| 6680 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6681 | } catch (RemoteException e) { |
| 6682 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6683 | + "Ignore"); |
| 6684 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6685 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6686 | } catch (ImsException e) { |
| 6687 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6688 | } finally { |
| 6689 | Binder.restoreCallingIdentity(token); |
| 6690 | } |
| 6691 | } |
| 6692 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6693 | /** |
| 6694 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6695 | */ |
| 6696 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6697 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6698 | |
| 6699 | final long identity = Binder.clearCallingIdentity(); |
| 6700 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6701 | // NOTE: Before S, this method only set the default phone. |
| 6702 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6703 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6704 | phone.setImsRegistrationState(registered); |
| 6705 | } |
| 6706 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6707 | } finally { |
| 6708 | Binder.restoreCallingIdentity(identity); |
| 6709 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6713 | * Set the network selection mode to automatic. |
| 6714 | * |
| 6715 | */ |
| 6716 | @Override |
| 6717 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6718 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6719 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6720 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6721 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6722 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | final long identity = Binder.clearCallingIdentity(); |
| 6725 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6726 | if (!isActiveSubscription(subId)) { |
| 6727 | return; |
| 6728 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6729 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6730 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6731 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | } finally { |
| 6733 | Binder.restoreCallingIdentity(identity); |
| 6734 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6735 | } |
| 6736 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6737 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6738 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6739 | * |
| 6740 | * @param subId the id of the subscription. |
| 6741 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6742 | * the operator to attach to. |
| 6743 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6744 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6745 | * normal network selection next time. |
| 6746 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6747 | */ |
| 6748 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6749 | public boolean setNetworkSelectionModeManual( |
| 6750 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6751 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6752 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6753 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6754 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6755 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6756 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6757 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6758 | if (!isActiveSubscription(subId)) { |
| 6759 | return false; |
| 6760 | } |
| 6761 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6762 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6763 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6764 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6765 | if (DBG) { |
| 6766 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6767 | + " operator: " + operatorInfo); |
| 6768 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6769 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6770 | } finally { |
| 6771 | Binder.restoreCallingIdentity(identity); |
| 6772 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6773 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6774 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6775 | * Get the manual network selection |
| 6776 | * |
| 6777 | * @param subId the id of the subscription. |
| 6778 | * |
| 6779 | * @return the previously saved user selected PLMN |
| 6780 | */ |
| 6781 | @Override |
| 6782 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6783 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6784 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6785 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6786 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6787 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6788 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6789 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6790 | final long identity = Binder.clearCallingIdentity(); |
| 6791 | try { |
| 6792 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6793 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6794 | } |
| 6795 | |
| 6796 | final Phone phone = getPhone(subId); |
| 6797 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6798 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6799 | } |
| 6800 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6801 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6802 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6803 | } finally { |
| 6804 | Binder.restoreCallingIdentity(identity); |
| 6805 | } |
| 6806 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6807 | |
| 6808 | /** |
| 6809 | * Scans for available networks. |
| 6810 | */ |
| 6811 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6812 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6813 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6814 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6815 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6816 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6817 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6818 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6819 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6820 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6821 | .setCallingPid(Binder.getCallingPid()) |
| 6822 | .setCallingUid(Binder.getCallingUid()) |
| 6823 | .setMethod("getCellNetworkScanResults") |
| 6824 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6825 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6826 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6827 | .build()); |
| 6828 | switch (locationResult) { |
| 6829 | case DENIED_HARD: |
| 6830 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6831 | case DENIED_SOFT: |
| 6832 | return null; |
| 6833 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6834 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6835 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6836 | try { |
| 6837 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6838 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6839 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
| 6842 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6843 | } |
| 6844 | |
| 6845 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6846 | * Get the call forwarding info, given the call forwarding reason. |
| 6847 | */ |
| 6848 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6849 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6850 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6851 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6852 | |
| 6853 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6854 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6855 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6856 | long identity = Binder.clearCallingIdentity(); |
| 6857 | try { |
| 6858 | if (DBG) { |
| 6859 | log("getCallForwarding: subId " + subId |
| 6860 | + " callForwardingReason" + callForwardingReason); |
| 6861 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6862 | |
| 6863 | Phone phone = getPhone(subId); |
| 6864 | if (phone == null) { |
| 6865 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6866 | callback.onError( |
| 6867 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6868 | } catch (RemoteException e) { |
| 6869 | // ignore |
| 6870 | } |
| 6871 | return; |
| 6872 | } |
| 6873 | |
| 6874 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6875 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6876 | @Override |
| 6877 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6878 | try { |
| 6879 | callback.onCallForwardingInfoAvailable(info); |
| 6880 | } catch (RemoteException e) { |
| 6881 | // ignore |
| 6882 | } |
| 6883 | } |
| 6884 | |
| 6885 | @Override |
| 6886 | public void onError(int error) { |
| 6887 | try { |
| 6888 | callback.onError(error); |
| 6889 | } catch (RemoteException e) { |
| 6890 | // ignore |
| 6891 | } |
| 6892 | } |
| 6893 | }); |
| 6894 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6895 | } finally { |
| 6896 | Binder.restoreCallingIdentity(identity); |
| 6897 | } |
| 6898 | } |
| 6899 | |
| 6900 | /** |
| 6901 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6902 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6903 | */ |
| 6904 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6905 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6906 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6907 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6908 | |
| 6909 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6910 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6911 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6912 | long identity = Binder.clearCallingIdentity(); |
| 6913 | try { |
| 6914 | if (DBG) { |
| 6915 | log("setCallForwarding: subId " + subId |
| 6916 | + " callForwardingInfo" + callForwardingInfo); |
| 6917 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6918 | |
| 6919 | Phone phone = getPhone(subId); |
| 6920 | if (phone == null) { |
| 6921 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6922 | callback.accept( |
| 6923 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6924 | } catch (RemoteException e) { |
| 6925 | // ignore |
| 6926 | } |
| 6927 | return; |
| 6928 | } |
| 6929 | |
| 6930 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6931 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6932 | |
| 6933 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6934 | } finally { |
| 6935 | Binder.restoreCallingIdentity(identity); |
| 6936 | } |
| 6937 | } |
| 6938 | |
| 6939 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6940 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6941 | */ |
| 6942 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6943 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6944 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6945 | |
| 6946 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6947 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 6948 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6949 | long identity = Binder.clearCallingIdentity(); |
| 6950 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6951 | Phone phone = getPhone(subId); |
| 6952 | if (phone == null) { |
| 6953 | try { |
| 6954 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6955 | } catch (RemoteException e) { |
| 6956 | // ignore |
| 6957 | } |
| 6958 | return; |
| 6959 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6960 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6961 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6962 | boolean requireUssd = c.getBoolean( |
| 6963 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6964 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6965 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6966 | if (requireUssd) { |
| 6967 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6968 | getSubscriptionCarrierId(subId)); |
| 6969 | String newUssdCommand = ""; |
| 6970 | try { |
| 6971 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6972 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6973 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6974 | } catch (NullPointerException e) { |
| 6975 | loge("Failed to generate USSD number" + e); |
| 6976 | } |
| 6977 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6978 | mMainThreadHandler, callback, carrierXmlParser, |
| 6979 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6980 | final String ussdCommand = newUssdCommand; |
| 6981 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6982 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6983 | }); |
| 6984 | } else { |
| 6985 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6986 | callback::accept); |
| 6987 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6988 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6989 | } finally { |
| 6990 | Binder.restoreCallingIdentity(identity); |
| 6991 | } |
| 6992 | } |
| 6993 | |
| 6994 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6995 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6996 | */ |
| 6997 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6998 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6999 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7000 | |
| 7001 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7002 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7003 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7004 | long identity = Binder.clearCallingIdentity(); |
| 7005 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7006 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7007 | |
| 7008 | Phone phone = getPhone(subId); |
| 7009 | if (phone == null) { |
| 7010 | try { |
| 7011 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7012 | } catch (RemoteException e) { |
| 7013 | // ignore |
| 7014 | } |
| 7015 | return; |
| 7016 | } |
| 7017 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7018 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7019 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7020 | boolean requireUssd = c.getBoolean( |
| 7021 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7022 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7023 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7024 | if (requireUssd) { |
| 7025 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7026 | getSubscriptionCarrierId(subId)); |
| 7027 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7028 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7029 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7030 | String newUssdCommand = ""; |
| 7031 | try { |
| 7032 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7033 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7034 | .makeCommand(ssAction, null); |
| 7035 | } catch (NullPointerException e) { |
| 7036 | loge("Failed to generate USSD number" + e); |
| 7037 | } |
| 7038 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7039 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7040 | final String ussdCommand = newUssdCommand; |
| 7041 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7042 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7043 | }); |
| 7044 | } else { |
| 7045 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7046 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7047 | |
| 7048 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7049 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7050 | } finally { |
| 7051 | Binder.restoreCallingIdentity(identity); |
| 7052 | } |
| 7053 | } |
| 7054 | |
| 7055 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7056 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7057 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7058 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7059 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7060 | * location related information which will be sent if the caller already possess |
| 7061 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7062 | * @param request contains the radio access networks with bands/channels to scan |
| 7063 | * @param messenger callback messenger for scan results or errors |
| 7064 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7065 | * @return the id of the requested scan which can be used to stop the scan. |
| 7066 | */ |
| 7067 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7068 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7069 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7070 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7072 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7073 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7074 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7075 | if (!renounceFineLocationAccess) { |
| 7076 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7077 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7078 | .setCallingPackage(callingPackage) |
| 7079 | .setCallingFeatureId(callingFeatureId) |
| 7080 | .setCallingPid(Binder.getCallingPid()) |
| 7081 | .setCallingUid(Binder.getCallingUid()) |
| 7082 | .setMethod("requestNetworkScan") |
| 7083 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7084 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7085 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7086 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7087 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7088 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7089 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7090 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7091 | if (e != null) { |
| 7092 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7093 | throw e; |
| 7094 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7095 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7096 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7097 | } |
| 7098 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7099 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7100 | |
| 7101 | enforceTelephonyFeatureWithException(callingPackage, |
| 7102 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7103 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7104 | int callingUid = Binder.getCallingUid(); |
| 7105 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7106 | final long identity = Binder.clearCallingIdentity(); |
| 7107 | try { |
| 7108 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7109 | renounceFineLocationAccess, request, messenger, binder, |
| 7110 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7111 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7112 | } finally { |
| 7113 | Binder.restoreCallingIdentity(identity); |
| 7114 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7115 | } |
| 7116 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7117 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7118 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7119 | boolean hasCarrierPriv; |
| 7120 | final long identity = Binder.clearCallingIdentity(); |
| 7121 | try { |
| 7122 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7123 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7124 | } finally { |
| 7125 | Binder.restoreCallingIdentity(identity); |
| 7126 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7127 | boolean hasNetworkScanPermission = |
| 7128 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7129 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7130 | |
| 7131 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7132 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7133 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7134 | } |
| 7135 | |
| 7136 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7137 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7138 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7139 | return new SecurityException("Specific channels must not be" |
| 7140 | + " scanned without location access."); |
| 7141 | } |
| 7142 | } |
| 7143 | } |
| 7144 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7145 | return null; |
| 7146 | } |
| 7147 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7148 | /** |
| 7149 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7150 | * |
| 7151 | * @param subId id of the subscription |
| 7152 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7153 | */ |
| 7154 | @Override |
| 7155 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7156 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7157 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7158 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7159 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7160 | final long identity = Binder.clearCallingIdentity(); |
| 7161 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7162 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7163 | } finally { |
| 7164 | Binder.restoreCallingIdentity(identity); |
| 7165 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7169 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7170 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7171 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7172 | */ |
| 7173 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7174 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7175 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7176 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7177 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7178 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7179 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7180 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7181 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7182 | final long identity = Binder.clearCallingIdentity(); |
| 7183 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7184 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7185 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7186 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7187 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7188 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7189 | } finally { |
| 7190 | Binder.restoreCallingIdentity(identity); |
| 7191 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7192 | } |
| 7193 | |
| 7194 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7195 | * Get the allowed network types for certain reason. |
| 7196 | * |
| 7197 | * @param subId the id of the subscription. |
| 7198 | * @param reason the reason the allowed network type change is taking place |
| 7199 | * @return the allowed network types. |
| 7200 | */ |
| 7201 | @Override |
| 7202 | public long getAllowedNetworkTypesForReason(int subId, |
| 7203 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7204 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7205 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7206 | |
| 7207 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7208 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason"); |
| 7209 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7210 | final long identity = Binder.clearCallingIdentity(); |
| 7211 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7212 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7213 | } finally { |
| 7214 | Binder.restoreCallingIdentity(identity); |
| 7215 | } |
| 7216 | } |
| 7217 | |
| 7218 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7219 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7220 | * @param subId subscription id of the sim card |
| 7221 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7222 | * This can be passed following states |
| 7223 | * <ol> |
| 7224 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7225 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7226 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7227 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7228 | * </ol> |
| 7229 | * @return operation result. |
| 7230 | */ |
| 7231 | @Override |
| 7232 | public int setNrDualConnectivityState(int subId, |
| 7233 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7235 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7236 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7237 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7238 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7239 | } |
| 7240 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7241 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7242 | final long identity = Binder.clearCallingIdentity(); |
| 7243 | try { |
| 7244 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7245 | nrDualConnectivityState, subId, |
| 7246 | workSource); |
| 7247 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7248 | return result; |
| 7249 | } finally { |
| 7250 | Binder.restoreCallingIdentity(identity); |
| 7251 | } |
| 7252 | } |
| 7253 | |
| 7254 | /** |
| 7255 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7256 | * @return true if dual connectivity is enabled else false |
| 7257 | */ |
| 7258 | @Override |
| 7259 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7260 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7261 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7262 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7263 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7264 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7265 | return false; |
| 7266 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7267 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7268 | final long identity = Binder.clearCallingIdentity(); |
| 7269 | try { |
| 7270 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7271 | null, subId, workSource); |
| 7272 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7273 | return isEnabled; |
| 7274 | } finally { |
| 7275 | Binder.restoreCallingIdentity(identity); |
| 7276 | } |
| 7277 | } |
| 7278 | |
| 7279 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7280 | * Set the allowed network types of the device and |
| 7281 | * provide the reason triggering the allowed network change. |
| 7282 | * |
| 7283 | * @param subId the id of the subscription. |
| 7284 | * @param reason the reason the allowed network type change is taking place |
| 7285 | * @param allowedNetworkTypes the allowed network types. |
| 7286 | * @return true on success; false on any failure. |
| 7287 | */ |
| 7288 | @Override |
| 7289 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7290 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7291 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7292 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7293 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7294 | // If the caller only has carrier privileges, then they should not be able to override |
| 7295 | // any network types which were set for security reasons. |
| 7296 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7297 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7298 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7299 | throw new SecurityException( |
| 7300 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7301 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7302 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7303 | |
| 7304 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7305 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7306 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7307 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7308 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7309 | return false; |
| 7310 | } |
| 7311 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7312 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7313 | return false; |
| 7314 | } |
| 7315 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7316 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7317 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7318 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7319 | Phone phone = getPhone(subId); |
| 7320 | if (phone == null) { |
| 7321 | return false; |
| 7322 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7323 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7324 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7325 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7326 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7327 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7328 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7329 | final long identity = Binder.clearCallingIdentity(); |
| 7330 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7331 | Boolean success = (Boolean) sendRequest( |
| 7332 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7333 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7334 | |
| 7335 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7336 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7337 | } finally { |
| 7338 | Binder.restoreCallingIdentity(identity); |
| 7339 | } |
| 7340 | } |
| 7341 | |
| 7342 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7343 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7344 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7345 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7346 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7347 | * @hide |
| 7348 | */ |
| 7349 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7350 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7351 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7352 | |
| 7353 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7354 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7355 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7356 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7357 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7358 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7359 | if (phone != null) { |
| 7360 | return phone.hasMatchedTetherApnSetting(); |
| 7361 | } else { |
| 7362 | return false; |
| 7363 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7364 | } finally { |
| 7365 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7366 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7367 | } |
| 7368 | |
| 7369 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7370 | * Get the user enabled state of Mobile Data. |
| 7371 | * |
| 7372 | * TODO: remove and use isUserDataEnabled. |
| 7373 | * This can't be removed now because some vendor codes |
| 7374 | * calls through ITelephony directly while they should |
| 7375 | * use TelephonyManager. |
| 7376 | * |
| 7377 | * @return true on enabled |
| 7378 | */ |
| 7379 | @Override |
| 7380 | public boolean getDataEnabled(int subId) { |
| 7381 | return isUserDataEnabled(subId); |
| 7382 | } |
| 7383 | |
| 7384 | /** |
| 7385 | * Get whether mobile data is enabled per user setting. |
| 7386 | * |
| 7387 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7388 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7389 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7390 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7391 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7392 | * |
| 7393 | * @return {@code true} if data is enabled else {@code false} |
| 7394 | */ |
| 7395 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7396 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7397 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7398 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7399 | try { |
| 7400 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7401 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7402 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7403 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7404 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7405 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7407 | mApp, subId, functionName); |
| 7408 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7409 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7410 | |
| 7411 | final long identity = Binder.clearCallingIdentity(); |
| 7412 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7413 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7414 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7415 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7416 | if (phone != null) { |
| 7417 | boolean retVal = phone.isUserDataEnabled(); |
| 7418 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7419 | return retVal; |
| 7420 | } else { |
| 7421 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7422 | return false; |
| 7423 | } |
| 7424 | } finally { |
| 7425 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7430 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7431 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7432 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7433 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7434 | * @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] | 7435 | */ |
| 7436 | @Override |
| 7437 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7438 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7439 | try { |
| 7440 | try { |
| 7441 | mApp.enforceCallingOrSelfPermission( |
| 7442 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7443 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7444 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7445 | try { |
| 7446 | mApp.enforceCallingOrSelfPermission( |
| 7447 | android.Manifest.permission.READ_PHONE_STATE, |
| 7448 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7449 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7450 | mApp.enforceCallingOrSelfPermission( |
| 7451 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7452 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7453 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7454 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7455 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7457 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7458 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7459 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7460 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7461 | final long identity = Binder.clearCallingIdentity(); |
| 7462 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7463 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7464 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7465 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7466 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7467 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | return retVal; |
| 7469 | } else { |
| 7470 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7471 | return false; |
| 7472 | } |
| 7473 | } finally { |
| 7474 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7475 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7476 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7477 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7478 | /** |
| 7479 | * Check if data is enabled for a specific reason |
| 7480 | * @param subId Subscription index |
| 7481 | * @param reason the reason the data enable change is taking place |
| 7482 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7483 | */ |
| 7484 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7485 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7486 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7487 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7488 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7489 | try { |
| 7490 | mApp.enforceCallingOrSelfPermission( |
| 7491 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7492 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7493 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7494 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7495 | functionName); |
| 7496 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7497 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7498 | try { |
| 7499 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7500 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7501 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7503 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7504 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7507 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7508 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7509 | |
| 7510 | final long identity = Binder.clearCallingIdentity(); |
| 7511 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7512 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7513 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7514 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7515 | + " reason=" + reason); |
| 7516 | } |
| 7517 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7518 | if (phone != null) { |
| 7519 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7520 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7521 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7522 | return retVal; |
| 7523 | } else { |
| 7524 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7525 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7526 | + subId + " retVal=false"); |
| 7527 | } |
| 7528 | return false; |
| 7529 | } |
| 7530 | } finally { |
| 7531 | Binder.restoreCallingIdentity(identity); |
| 7532 | } |
| 7533 | } |
| 7534 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7535 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7536 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7537 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7538 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7539 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7540 | // No permission needed; this only lets the caller inspect their own status. |
| 7541 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7542 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7543 | |
| 7544 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7545 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7546 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7547 | |
| 7548 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7549 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7550 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7551 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7552 | } |
| 7553 | |
| 7554 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7555 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7556 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7557 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7558 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7559 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7560 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7561 | if (cpt == null) { |
| 7562 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7563 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7564 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7565 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7566 | } |
| 7567 | |
| 7568 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7569 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7570 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7571 | |
| 7572 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7573 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7574 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7575 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7576 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7577 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7578 | Phone phone = getPhone(subId); |
| 7579 | if (phone == null) { |
| 7580 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7581 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7582 | } |
| 7583 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7584 | if (cpt == null) { |
| 7585 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7586 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7587 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7588 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7589 | } |
| 7590 | |
| 7591 | @Override |
| 7592 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7593 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7594 | |
| 7595 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7596 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7597 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7598 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7599 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7600 | } |
| 7601 | |
| 7602 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7603 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7604 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7605 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7606 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7607 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7608 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7609 | if (phone == null) { |
| 7610 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7611 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7612 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7613 | if (cpt == null) { |
| 7614 | continue; |
| 7615 | } |
| 7616 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7617 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7618 | break; |
| 7619 | } |
| 7620 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7621 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7622 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7623 | |
| 7624 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7625 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7626 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7627 | |
| 7628 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7629 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7630 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7631 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7632 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7633 | if (phone == null) { |
| 7634 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7635 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7636 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7637 | if (cpt == null) { |
| 7638 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7639 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7640 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7641 | } |
| 7642 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7643 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7644 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7645 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7646 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7647 | if (phone == null) { |
| 7648 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7649 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7650 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7651 | if (cpt == null) { |
| 7652 | return Collections.emptyList(); |
| 7653 | } |
| 7654 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7655 | } |
| 7656 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7657 | @Override |
| 7658 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7659 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7660 | |
| 7661 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7662 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7663 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7664 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7665 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7666 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7667 | try { |
| 7668 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7669 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7670 | } |
| 7671 | } finally { |
| 7672 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7673 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7674 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7675 | } |
| 7676 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7677 | @Override |
| 7678 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7679 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7680 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7681 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7682 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7683 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7684 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7685 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7686 | if (phone == null) { |
| 7687 | return null; |
| 7688 | } |
| 7689 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7690 | if (cpt == null) { |
| 7691 | return null; |
| 7692 | } |
| 7693 | return cpt.getCarrierServicePackageName(); |
| 7694 | } |
| 7695 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7696 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7697 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7698 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7699 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7700 | return null; |
| 7701 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7702 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7703 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7704 | return null; |
| 7705 | } |
| 7706 | return iccId; |
| 7707 | } |
| 7708 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7709 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7710 | public void setCallComposerStatus(int subId, int status) { |
| 7711 | enforceModifyPermission(); |
| 7712 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7713 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7714 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7715 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7716 | final long identity = Binder.clearCallingIdentity(); |
| 7717 | try { |
| 7718 | Phone phone = getPhone(subId); |
| 7719 | if (phone != null) { |
| 7720 | Phone defaultPhone = phone.getImsPhone(); |
| 7721 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7722 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7723 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7724 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7725 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7726 | } |
| 7727 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7728 | } catch (ImsException e) { |
| 7729 | throw new ServiceSpecificException(e.getCode()); |
| 7730 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7731 | Binder.restoreCallingIdentity(identity); |
| 7732 | } |
| 7733 | } |
| 7734 | |
| 7735 | @Override |
| 7736 | public int getCallComposerStatus(int subId) { |
| 7737 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7738 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7739 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7740 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7741 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7742 | final long identity = Binder.clearCallingIdentity(); |
| 7743 | try { |
| 7744 | Phone phone = getPhone(subId); |
| 7745 | if (phone != null) { |
| 7746 | Phone defaultPhone = phone.getImsPhone(); |
| 7747 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7748 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7749 | return imsPhone.getCallComposerStatus(); |
| 7750 | } |
| 7751 | } |
| 7752 | } finally { |
| 7753 | Binder.restoreCallingIdentity(identity); |
| 7754 | } |
| 7755 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7756 | } |
| 7757 | |
| 7758 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7759 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7760 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7761 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7762 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7763 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7764 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7765 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7766 | "setLine1NumberForDisplayForSubscriber"); |
| 7767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7768 | final long identity = Binder.clearCallingIdentity(); |
| 7769 | try { |
| 7770 | final String iccId = getIccId(subId); |
| 7771 | final Phone phone = getPhone(subId); |
| 7772 | if (phone == null) { |
| 7773 | return false; |
| 7774 | } |
| 7775 | final String subscriberId = phone.getSubscriberId(); |
| 7776 | |
| 7777 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7778 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7779 | + subscriberId + " to " + number); |
| 7780 | } |
| 7781 | |
| 7782 | if (TextUtils.isEmpty(iccId)) { |
| 7783 | return false; |
| 7784 | } |
| 7785 | |
| 7786 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7787 | |
| 7788 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7789 | if (alphaTag == null) { |
| 7790 | editor.remove(alphaTagPrefKey); |
| 7791 | } else { |
| 7792 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7793 | } |
| 7794 | |
| 7795 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7796 | // track all merged IMSIs based on line number |
| 7797 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7798 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7799 | if (number == null) { |
| 7800 | editor.remove(numberPrefKey); |
| 7801 | editor.remove(subscriberPrefKey); |
| 7802 | } else { |
| 7803 | editor.putString(numberPrefKey, number); |
| 7804 | editor.putString(subscriberPrefKey, subscriberId); |
| 7805 | } |
| 7806 | |
| 7807 | editor.commit(); |
| 7808 | return true; |
| 7809 | } finally { |
| 7810 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7811 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7812 | } |
| 7813 | |
| 7814 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7815 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7816 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7817 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7818 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7819 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7820 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7821 | return null; |
| 7822 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7823 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7824 | enforceTelephonyFeatureWithException(callingPackage, |
| 7825 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7826 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7827 | final long identity = Binder.clearCallingIdentity(); |
| 7828 | try { |
| 7829 | String iccId = getIccId(subId); |
| 7830 | if (iccId != null) { |
| 7831 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7832 | if (DBG_MERGE) { |
| 7833 | log("getLine1NumberForDisplay returning " |
| 7834 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7835 | } |
| 7836 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7837 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7838 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7839 | return null; |
| 7840 | } finally { |
| 7841 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7842 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7843 | } |
| 7844 | |
| 7845 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7846 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7847 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7848 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7849 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7850 | return null; |
| 7851 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7852 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7853 | final long identity = Binder.clearCallingIdentity(); |
| 7854 | try { |
| 7855 | String iccId = getIccId(subId); |
| 7856 | if (iccId != null) { |
| 7857 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7858 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7859 | } |
| 7860 | return null; |
| 7861 | } finally { |
| 7862 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7863 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7864 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7865 | |
| 7866 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7867 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7868 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7869 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7870 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7871 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7872 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7873 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7874 | return null; |
| 7875 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7876 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7877 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7878 | // the process, where TelephonyManager was instantiated. |
| 7879 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7880 | final long identity = Binder.clearCallingIdentity(); |
| 7881 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7882 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7883 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7884 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7885 | |
| 7886 | // Figure out what subscribers are currently active |
| 7887 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7888 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7889 | // Only consider subs which match the current subId |
| 7890 | // This logic can be simplified. See b/131189269 for progress. |
| 7891 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7892 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7893 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7894 | |
| 7895 | // First pass, find a number override for an active subscriber |
| 7896 | String mergeNumber = null; |
| 7897 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7898 | for (String key : prefs.keySet()) { |
| 7899 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7900 | final String subscriberId = (String) prefs.get(key); |
| 7901 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7902 | final String iccId = key.substring( |
| 7903 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7904 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7905 | mergeNumber = (String) prefs.get(numberKey); |
| 7906 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7907 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7908 | + " for active subscriber " + subscriberId); |
| 7909 | } |
| 7910 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7911 | break; |
| 7912 | } |
| 7913 | } |
| 7914 | } |
| 7915 | } |
| 7916 | |
| 7917 | // Shortcut when no active merged subscribers |
| 7918 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7919 | return null; |
| 7920 | } |
| 7921 | |
| 7922 | // Second pass, find all subscribers under that line override |
| 7923 | final ArraySet<String> result = new ArraySet<>(); |
| 7924 | for (String key : prefs.keySet()) { |
| 7925 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7926 | final String number = (String) prefs.get(key); |
| 7927 | if (mergeNumber.equals(number)) { |
| 7928 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7929 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7930 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7931 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7932 | result.add(subscriberId); |
| 7933 | } |
| 7934 | } |
| 7935 | } |
| 7936 | } |
| 7937 | |
| 7938 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7939 | Arrays.sort(resultArray); |
| 7940 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7941 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7942 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7943 | } |
| 7944 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7945 | } finally { |
| 7946 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7947 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7948 | } |
| 7949 | |
| 7950 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7951 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7952 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7953 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7954 | enforceTelephonyFeatureWithException(callingPackage, |
| 7955 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 7956 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7957 | final long identity = Binder.clearCallingIdentity(); |
| 7958 | try { |
| 7959 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7960 | TelephonyManager.class); |
| 7961 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7962 | if (subscriberId == null) { |
| 7963 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7964 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7965 | + subId); |
| 7966 | } |
| 7967 | return null; |
| 7968 | } |
| 7969 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7970 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7971 | .getSubscriptionInfo(subId); |
| 7972 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7973 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7974 | if (groupUuid == null) { |
| 7975 | return new String[]{subscriberId}; |
| 7976 | } |
| 7977 | |
| 7978 | // Get all subscriberIds from the group. |
| 7979 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7980 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7981 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7982 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7983 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7984 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7985 | if (subscriberId != null) { |
| 7986 | mergedSubscriberIds.add(subscriberId); |
| 7987 | } |
| 7988 | } |
| 7989 | |
| 7990 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7991 | } finally { |
| 7992 | Binder.restoreCallingIdentity(identity); |
| 7993 | |
| 7994 | } |
| 7995 | } |
| 7996 | |
| 7997 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7998 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7999 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8000 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8001 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8002 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8003 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8004 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8005 | final long identity = Binder.clearCallingIdentity(); |
| 8006 | try { |
| 8007 | final Phone phone = getPhone(subId); |
| 8008 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8009 | } finally { |
| 8010 | Binder.restoreCallingIdentity(identity); |
| 8011 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8012 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8013 | |
| 8014 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8015 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8016 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8017 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8018 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8019 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8020 | |
| 8021 | final long identity = Binder.clearCallingIdentity(); |
| 8022 | try { |
| 8023 | final Phone phone = getPhone(subId); |
| 8024 | if (phone == null) { |
| 8025 | return false; |
| 8026 | } |
| 8027 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8028 | cdmaNonRoamingList); |
| 8029 | } finally { |
| 8030 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8031 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8032 | } |
| 8033 | |
| 8034 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8035 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8036 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8037 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8038 | if (phone == null) { |
| 8039 | return raf; |
| 8040 | } |
| 8041 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8042 | try { |
| 8043 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8044 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8045 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8046 | } catch (SecurityException e) { |
| 8047 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8048 | throw e; |
| 8049 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8050 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8051 | enforceTelephonyFeatureWithException(callingPackage, |
| 8052 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8053 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8054 | final long identity = Binder.clearCallingIdentity(); |
| 8055 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8056 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8057 | } finally { |
| 8058 | Binder.restoreCallingIdentity(identity); |
| 8059 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8060 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8061 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8062 | |
| 8063 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8064 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8065 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8066 | try { |
| 8067 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8068 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8069 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8070 | } |
| 8071 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8072 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8073 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8074 | |
| 8075 | enforceTelephonyFeatureWithException(callingPackage, |
| 8076 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8077 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8078 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8079 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8080 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8081 | throw new SecurityException("App must be the dialer role holder to" |
| 8082 | + " upload a call composer pic"); |
| 8083 | } |
| 8084 | |
| 8085 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8086 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8087 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8088 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8089 | boolean readUntilEnd = false; |
| 8090 | int totalBytesRead = 0; |
| 8091 | byte[] buffer = new byte[16 * 1024]; |
| 8092 | while (true) { |
| 8093 | int numRead; |
| 8094 | try { |
| 8095 | numRead = input.read(buffer); |
| 8096 | } catch (IOException e) { |
| 8097 | try { |
| 8098 | fd.checkError(); |
| 8099 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8100 | null); |
| 8101 | } catch (IOException e1) { |
| 8102 | // This means that the other side closed explicitly with an error. If this |
| 8103 | // happens, log and ignore. |
| 8104 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8105 | } |
| 8106 | break; |
| 8107 | } |
| 8108 | if (numRead == -1) { |
| 8109 | readUntilEnd = true; |
| 8110 | break; |
| 8111 | } |
| 8112 | totalBytesRead += numRead; |
| 8113 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8114 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8115 | try { |
| 8116 | input.close(); |
| 8117 | } catch (IOException e) { |
| 8118 | // ignore |
| 8119 | } |
| 8120 | break; |
| 8121 | } |
| 8122 | output.write(buffer, 0, numRead); |
| 8123 | } |
| 8124 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8125 | // close is above, where the picture size is too big. |
| 8126 | |
| 8127 | try { |
| 8128 | fd.checkError(); |
| 8129 | } catch (IOException e) { |
| 8130 | loge("Remote end for call composer closed with an error: " + e); |
| 8131 | return; |
| 8132 | } |
| 8133 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8134 | if (!readUntilEnd) { |
| 8135 | loge("Did not finish reading entire image; aborting"); |
| 8136 | return; |
| 8137 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8138 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8139 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8140 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8141 | new CallComposerPictureTransfer.Factory() {}, |
| 8142 | imageData, |
| 8143 | (result) -> { |
| 8144 | if (result.first != null) { |
| 8145 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8146 | Bundle outputResult = new Bundle(); |
| 8147 | outputResult.putParcelable( |
| 8148 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8149 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8150 | outputResult); |
| 8151 | } else { |
| 8152 | callback.send(result.second, null); |
| 8153 | } |
| 8154 | } |
| 8155 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8156 | }); |
| 8157 | } |
| 8158 | |
| 8159 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8160 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8161 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8162 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8163 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8164 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8165 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8166 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8167 | final long identity = Binder.clearCallingIdentity(); |
| 8168 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8169 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8170 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8171 | } finally { |
| 8172 | Binder.restoreCallingIdentity(identity); |
| 8173 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8174 | } |
| 8175 | |
| 8176 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8177 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8178 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8179 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8180 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8181 | return false; |
| 8182 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8183 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8184 | enforceTelephonyFeatureWithException(callingPackage, |
| 8185 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8186 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8187 | final long identity = Binder.clearCallingIdentity(); |
| 8188 | try { |
| 8189 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8190 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8191 | // In the long run, we may instead need to check if there exists a connection service |
| 8192 | // which can support video calling. |
| 8193 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8194 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8195 | return imsManager.isVtEnabledByPlatform() |
| 8196 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8197 | && imsManager.isVtEnabledByUser(); |
| 8198 | } finally { |
| 8199 | Binder.restoreCallingIdentity(identity); |
| 8200 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8201 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8202 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8203 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8204 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8205 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8206 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8207 | mApp, subId, callingPackage, callingFeatureId, |
| 8208 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8209 | return false; |
| 8210 | } |
| 8211 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8212 | enforceTelephonyFeatureWithException(callingPackage, |
| 8213 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8215 | final long identity = Binder.clearCallingIdentity(); |
| 8216 | try { |
| 8217 | CarrierConfigManager configManager = |
| 8218 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8219 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8220 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8221 | } finally { |
| 8222 | Binder.restoreCallingIdentity(identity); |
| 8223 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8224 | } |
| 8225 | |
| 8226 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8227 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8228 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8229 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8230 | return false; |
| 8231 | } |
| 8232 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8233 | enforceTelephonyFeatureWithException(callingPackage, |
| 8234 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8235 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8236 | final long identity = Binder.clearCallingIdentity(); |
| 8237 | try { |
| 8238 | CarrierConfigManager configManager = |
| 8239 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8240 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8241 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8242 | } finally { |
| 8243 | Binder.restoreCallingIdentity(identity); |
| 8244 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8245 | } |
| 8246 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8247 | @Override |
| 8248 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8249 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8250 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8251 | } |
| 8252 | |
| 8253 | @Override |
| 8254 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8255 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8256 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8258 | final long identity = Binder.clearCallingIdentity(); |
| 8259 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8260 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8261 | } finally { |
| 8262 | Binder.restoreCallingIdentity(identity); |
| 8263 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8264 | } |
| 8265 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8266 | /** |
| 8267 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8268 | * support for the feature and device firmware support. |
| 8269 | * |
| 8270 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8271 | */ |
| 8272 | @Override |
| 8273 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8274 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8275 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8276 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8278 | final Phone phone = getPhone(subscriptionId); |
| 8279 | if (phone == null) { |
| 8280 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8281 | return false; |
| 8282 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8283 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8284 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8285 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8286 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8287 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8288 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8289 | return isCarrierSupported && isDeviceSupported; |
| 8290 | } finally { |
| 8291 | Binder.restoreCallingIdentity(identity); |
| 8292 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8293 | } |
| 8294 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8295 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8296 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8297 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8298 | * 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] | 8299 | */ |
| 8300 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | final long identity = Binder.clearCallingIdentity(); |
| 8302 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8303 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8304 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8305 | return false; |
| 8306 | } |
| 8307 | } |
| 8308 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8309 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8310 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8311 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8312 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8313 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8314 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8315 | } finally { |
| 8316 | Binder.restoreCallingIdentity(identity); |
| 8317 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8318 | } |
| 8319 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8320 | @Deprecated |
| 8321 | @Override |
| 8322 | public String getDeviceId(String callingPackage) { |
| 8323 | return getDeviceIdWithFeature(callingPackage, null); |
| 8324 | } |
| 8325 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8326 | /** |
| 8327 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8328 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8329 | * |
| 8330 | * <p>Requires Permission: |
| 8331 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8332 | */ |
| 8333 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8334 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8335 | try { |
| 8336 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8337 | } catch (SecurityException se) { |
| 8338 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8339 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8340 | + Binder.getCallingUid()); |
| 8341 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8342 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8343 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8344 | return null; |
| 8345 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8346 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8347 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8348 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8349 | return null; |
| 8350 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8351 | |
| 8352 | final long identity = Binder.clearCallingIdentity(); |
| 8353 | try { |
| 8354 | return phone.getDeviceId(); |
| 8355 | } finally { |
| 8356 | Binder.restoreCallingIdentity(identity); |
| 8357 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8358 | } |
| 8359 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8360 | /** |
| 8361 | * {@hide} |
| 8362 | * Returns the IMS Registration Status on a particular subid |
| 8363 | * |
| 8364 | * @param subId |
| 8365 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8366 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8367 | Phone phone = getPhone(subId); |
| 8368 | if (phone != null) { |
| 8369 | return phone.isImsRegistered(); |
| 8370 | } else { |
| 8371 | return false; |
| 8372 | } |
| 8373 | } |
| 8374 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8375 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8376 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8377 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8378 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8379 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8380 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8381 | } |
| 8382 | final long identity = Binder.clearCallingIdentity(); |
| 8383 | try { |
| 8384 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8385 | } finally { |
| 8386 | Binder.restoreCallingIdentity(identity); |
| 8387 | } |
| 8388 | } |
| 8389 | |
| 8390 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8391 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8392 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8393 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8394 | mApp, |
| 8395 | subscriptionId, |
| 8396 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8397 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8398 | |
| 8399 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8400 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8401 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8402 | final long identity = Binder.clearCallingIdentity(); |
| 8403 | try { |
| 8404 | Phone phone = getPhone(subscriptionId); |
| 8405 | if (phone == null) { |
| 8406 | return null; |
| 8407 | } |
| 8408 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8409 | } finally { |
| 8410 | Binder.restoreCallingIdentity(identity); |
| 8411 | } |
| 8412 | } |
| 8413 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8414 | /** |
| 8415 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8416 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8417 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8418 | final long identity = Binder.clearCallingIdentity(); |
| 8419 | try { |
| 8420 | Phone phone = getPhone(subId); |
| 8421 | if (phone != null) { |
| 8422 | return phone.isWifiCallingEnabled(); |
| 8423 | } else { |
| 8424 | return false; |
| 8425 | } |
| 8426 | } finally { |
| 8427 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8428 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8429 | } |
| 8430 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8431 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8432 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8433 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8434 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8435 | final long identity = Binder.clearCallingIdentity(); |
| 8436 | try { |
| 8437 | Phone phone = getPhone(subId); |
| 8438 | if (phone != null) { |
| 8439 | return phone.isVideoEnabled(); |
| 8440 | } else { |
| 8441 | return false; |
| 8442 | } |
| 8443 | } finally { |
| 8444 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8445 | } |
| 8446 | } |
| 8447 | |
| 8448 | /** |
| 8449 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8450 | * defined in {@link ImsRegistrationImplBase}. |
| 8451 | */ |
| 8452 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8453 | final long identity = Binder.clearCallingIdentity(); |
| 8454 | try { |
| 8455 | Phone phone = getPhone(subId); |
| 8456 | if (phone != null) { |
| 8457 | return phone.getImsRegistrationTech(); |
| 8458 | } else { |
| 8459 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8460 | } |
| 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8463 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8464 | } |
| 8465 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8466 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8467 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8468 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8469 | |
| 8470 | enforceTelephonyFeatureWithException(callingPackage, |
| 8471 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8472 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8473 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8474 | return; |
| 8475 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8476 | Phone defaultPhone = getDefaultPhone(); |
| 8477 | if (defaultPhone != null) { |
| 8478 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8479 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8480 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8481 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8482 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8483 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8484 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8485 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8486 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8487 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8488 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8489 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8490 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8491 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8492 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8493 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8494 | // There has been issues when Sms raw table somehow stores orphan |
| 8495 | // fragments. They lead to garbled message when new fragments come |
| 8496 | // in and combined with those stale ones. In case this happens again, |
| 8497 | // user can reset all network settings which will clean up this table. |
| 8498 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8499 | // Clean up IMS settings as well here. |
| 8500 | int slotId = getSlotIndex(subId); |
| 8501 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8502 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8503 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8504 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8505 | if (defaultPhone == null) { |
| 8506 | return; |
| 8507 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8508 | // Erase modem config if erase modem on network setting is enabled. |
| 8509 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8510 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8511 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8512 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8513 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8514 | |
| 8515 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8516 | } finally { |
| 8517 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8518 | } |
| 8519 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8520 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8521 | @VisibleForTesting |
| 8522 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8523 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8524 | return; |
| 8525 | } |
| 8526 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8527 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8528 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8529 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8530 | "user=" + defaultNetworkType); |
| 8531 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8532 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8533 | defaultNetworkType, null); |
| 8534 | } |
| 8535 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8536 | private void cleanUpSmsRawTable(Context context) { |
| 8537 | ContentResolver resolver = context.getContentResolver(); |
| 8538 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8539 | resolver.delete(uri, null, null); |
| 8540 | } |
| 8541 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8542 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8543 | public String getSimLocaleForSubscriber(int subId) { |
| 8544 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8545 | |
| 8546 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8547 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8548 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8549 | final Phone phone = getPhone(subId); |
| 8550 | if (phone == null) { |
| 8551 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8552 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8553 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8554 | final long identity = Binder.clearCallingIdentity(); |
| 8555 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8556 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8557 | phone.getContext().getOpPackageName(), |
| 8558 | phone.getContext().getAttributionTag()); |
| 8559 | if (info == null) { |
| 8560 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8561 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8562 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8563 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8564 | // preferences (EF-PL and EF-LI)... |
| 8565 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8566 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8567 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8568 | if (localeFromDefaultSim != null) { |
| 8569 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8570 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8571 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8572 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8573 | } else { |
| 8574 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8575 | } |
| 8576 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8577 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8578 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8579 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8580 | // the SIM and carrier preferences does not include a country we add the country |
| 8581 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8582 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8583 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8584 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8585 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8586 | } |
| 8587 | |
| 8588 | if (DBG) log("No locale found - returning null"); |
| 8589 | return null; |
| 8590 | } finally { |
| 8591 | Binder.restoreCallingIdentity(identity); |
| 8592 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8593 | } |
| 8594 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8595 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8596 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8597 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8598 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8599 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8600 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8601 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8602 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8603 | return localeTag; |
| 8604 | } |
| 8605 | } |
| 8606 | return inputLocale.toLanguageTag(); |
| 8607 | } |
| 8608 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8609 | /** |
| 8610 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8611 | */ |
| 8612 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8613 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8614 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8615 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8616 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8617 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8618 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8619 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8620 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8621 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8622 | * representing the state of the modem. |
| 8623 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8624 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8625 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8626 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8627 | */ |
| 8628 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8629 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8630 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8631 | |
| 8632 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8633 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8634 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8635 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8636 | |
| 8637 | final long identity = Binder.clearCallingIdentity(); |
| 8638 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8639 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8640 | } finally { |
| 8641 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8642 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8643 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8644 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8645 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8646 | // less than total activity duration. |
| 8647 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8648 | if (info == null) { |
| 8649 | return false; |
| 8650 | } |
| 8651 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8652 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8653 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8654 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8655 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8656 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8657 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8658 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8659 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8660 | } |
| 8661 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8662 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8663 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8664 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8665 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8666 | |
| 8667 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8668 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8669 | } |
| 8670 | |
| 8671 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8672 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8673 | rat, |
| 8674 | freq, |
| 8675 | info.getReceiveTimeMillis(rat, freq) |
| 8676 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8677 | } |
| 8678 | |
| 8679 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8680 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8681 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8682 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8683 | |
| 8684 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8685 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8686 | } |
| 8687 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8688 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8689 | rat, |
| 8690 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8691 | } |
| 8692 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8693 | /** |
| 8694 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8695 | * @param info recent ModemActivityInfo |
| 8696 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8697 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8698 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8699 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8700 | boolean matched; |
| 8701 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8702 | matched = false; |
| 8703 | int rat = info.getSpecificInfoRat(i); |
| 8704 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8705 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8706 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8707 | //if it already exists |
| 8708 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8709 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8710 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8711 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8712 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8713 | updateLastModemActivityInfo(info, rat, freq); |
| 8714 | matched = true; |
| 8715 | } |
| 8716 | } else { |
| 8717 | updateLastModemActivityInfo(info, rat); |
| 8718 | matched = true; |
| 8719 | } |
| 8720 | } |
| 8721 | } |
| 8722 | |
| 8723 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8724 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8725 | new ActivityStatsTechSpecificInfo( |
| 8726 | rat, |
| 8727 | freq, |
| 8728 | info.getTransmitTimeMillis(rat, freq), |
| 8729 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8730 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8731 | } |
| 8732 | } |
| 8733 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8734 | mLastModemActivitySpecificInfo = |
| 8735 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8736 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8737 | |
| 8738 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8739 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8740 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8741 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8742 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8743 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8744 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8745 | |
| 8746 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8747 | new ModemActivityInfo( |
| 8748 | mLastModemActivityInfo.getTimestampMillis(), |
| 8749 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8750 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8751 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8752 | } |
| 8753 | |
| 8754 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8755 | ActivityStatsTechSpecificInfo[] info) { |
| 8756 | int infoSize = info.length; |
| 8757 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8758 | for (int i = 0; i < infoSize; i++) { |
| 8759 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8760 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8761 | info[i].getTransmitTimeMillis(), |
| 8762 | (int) info[i].getReceiveTimeMillis()); |
| 8763 | } |
| 8764 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8765 | } |
| 8766 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8767 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8768 | * Returns the service state information on specified subscription. |
| 8769 | */ |
| 8770 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8771 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8772 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8773 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8774 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8775 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8776 | return null; |
| 8777 | } |
| 8778 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8779 | enforceTelephonyFeatureWithException(callingPackage, |
| 8780 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8781 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8782 | boolean hasFinePermission = false; |
| 8783 | boolean hasCoarsePermission = false; |
| 8784 | if (!renounceFineLocationAccess) { |
| 8785 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8786 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8787 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8788 | .setCallingPackage(callingPackage) |
| 8789 | .setCallingFeatureId(callingFeatureId) |
| 8790 | .setCallingPid(Binder.getCallingPid()) |
| 8791 | .setCallingUid(Binder.getCallingUid()) |
| 8792 | .setMethod("getServiceStateForSubscriber") |
| 8793 | .setLogAsInfo(true) |
| 8794 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8795 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8796 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8797 | .build()); |
| 8798 | hasFinePermission = |
| 8799 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8800 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8801 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8802 | if (!renounceCoarseLocationAccess) { |
| 8803 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8804 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8805 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8806 | .setCallingPackage(callingPackage) |
| 8807 | .setCallingFeatureId(callingFeatureId) |
| 8808 | .setCallingPid(Binder.getCallingPid()) |
| 8809 | .setCallingUid(Binder.getCallingUid()) |
| 8810 | .setMethod("getServiceStateForSubscriber") |
| 8811 | .setLogAsInfo(true) |
| 8812 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8813 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8814 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8815 | .build()); |
| 8816 | hasCoarsePermission = |
| 8817 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8818 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8819 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8820 | final Phone phone = getPhone(subId); |
| 8821 | if (phone == null) { |
| 8822 | return null; |
| 8823 | } |
| 8824 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8825 | final long identity = Binder.clearCallingIdentity(); |
| 8826 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8827 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8828 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8829 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8830 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8831 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8832 | .getSubscriptionInfoInternal(subId); |
| 8833 | if (subInfo == null || !subInfo.isActive()) { |
| 8834 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8835 | + "subId=" + subId); |
| 8836 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8837 | } |
| 8838 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8839 | ServiceState ss = phone.getServiceState(); |
| 8840 | |
| 8841 | // Scrub out the location info in ServiceState depending on what level of access |
| 8842 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8843 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8844 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8845 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8846 | } finally { |
| 8847 | Binder.restoreCallingIdentity(identity); |
| 8848 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8849 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8850 | |
| 8851 | /** |
| 8852 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8853 | * |
| 8854 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8855 | * voicemail ringtone. |
| 8856 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8857 | * PhoneAccount. |
| 8858 | */ |
| 8859 | @Override |
| 8860 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8861 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8862 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8863 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8864 | final long identity = Binder.clearCallingIdentity(); |
| 8865 | try { |
| 8866 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8867 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8868 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8869 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8870 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8871 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8872 | } finally { |
| 8873 | Binder.restoreCallingIdentity(identity); |
| 8874 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8875 | } |
| 8876 | |
| 8877 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8878 | * Sets the per-account voicemail ringtone. |
| 8879 | * |
| 8880 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8881 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8882 | * |
| 8883 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8884 | * voicemail ringtone. |
| 8885 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8886 | * PhoneAccount. |
| 8887 | */ |
| 8888 | @Override |
| 8889 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8890 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8891 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8892 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8893 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8894 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8895 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8896 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8897 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8898 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8899 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8900 | enforceTelephonyFeatureWithException(callingPackage, |
| 8901 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 8902 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8903 | final long identity = Binder.clearCallingIdentity(); |
| 8904 | try { |
| 8905 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8906 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8907 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8908 | } |
| 8909 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8910 | } finally { |
| 8911 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8912 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8913 | } |
| 8914 | |
| 8915 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8916 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8917 | * |
| 8918 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8919 | * voicemail vibration setting. |
| 8920 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8921 | */ |
| 8922 | @Override |
| 8923 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8924 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8925 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 8926 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8927 | final long identity = Binder.clearCallingIdentity(); |
| 8928 | try { |
| 8929 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8930 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8931 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8932 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8933 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8934 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8935 | } finally { |
| 8936 | Binder.restoreCallingIdentity(identity); |
| 8937 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8938 | } |
| 8939 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8940 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8941 | * Sets the per-account voicemail vibration. |
| 8942 | * |
| 8943 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8944 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8945 | * |
| 8946 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8947 | * voicemail vibration setting. |
| 8948 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8949 | * specific PhoneAccount. |
| 8950 | */ |
| 8951 | @Override |
| 8952 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8953 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8954 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8955 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8956 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8957 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8959 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8960 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8961 | } |
| 8962 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8963 | enforceTelephonyFeatureWithException(callingPackage, |
| 8964 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 8965 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8966 | final long identity = Binder.clearCallingIdentity(); |
| 8967 | try { |
| 8968 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8969 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8970 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8971 | } |
| 8972 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8973 | } finally { |
| 8974 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8975 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8976 | } |
| 8977 | |
| 8978 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8979 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8980 | * |
| 8981 | * @throws SecurityException if the caller does not have the required permission |
| 8982 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8983 | @VisibleForTesting |
| 8984 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8985 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8986 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8987 | } |
| 8988 | |
| 8989 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8990 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8991 | * permission. |
| 8992 | * |
| 8993 | * @throws SecurityException if the caller does not have the required permission |
| 8994 | */ |
| 8995 | private void enforceSendSmsPermission() { |
| 8996 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8997 | } |
| 8998 | |
| 8999 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9000 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9001 | * users permission. |
| 9002 | * |
| 9003 | * @throws SecurityException if the caller does not have the required permission |
| 9004 | */ |
| 9005 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9006 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9007 | } |
| 9008 | |
| 9009 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9010 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9011 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9012 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9013 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9014 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9015 | final long identity = Binder.clearCallingIdentity(); |
| 9016 | try { |
| 9017 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9018 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9019 | if (componentName == null) { |
| 9020 | throw new SecurityException( |
| 9021 | "Caller not current active visual voicemail package[null]"); |
| 9022 | } |
| 9023 | String vvmPackage = componentName.getPackageName(); |
| 9024 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9025 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9026 | } |
| 9027 | } finally { |
| 9028 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9029 | } |
| 9030 | } |
| 9031 | |
| 9032 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9033 | * Return the application ID for the app type. |
| 9034 | * |
| 9035 | * @param subId the subscription ID that this request applies to. |
| 9036 | * @param appType the uicc app type. |
| 9037 | * @return Application ID for specificied app type, or null if no uicc. |
| 9038 | */ |
| 9039 | @Override |
| 9040 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9041 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9042 | |
| 9043 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9044 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9045 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9046 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9047 | |
| 9048 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9049 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9050 | if (phone == null) { |
| 9051 | return null; |
| 9052 | } |
| 9053 | String aid = null; |
| 9054 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9055 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9056 | .getApplicationByType(appType).getAid(); |
| 9057 | } catch (Exception e) { |
| 9058 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9059 | } |
| 9060 | return aid; |
| 9061 | } finally { |
| 9062 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9063 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9064 | } |
| 9065 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9066 | /** |
| 9067 | * Return the Electronic Serial Number. |
| 9068 | * |
| 9069 | * @param subId the subscription ID that this request applies to. |
| 9070 | * @return ESN or null if error. |
| 9071 | */ |
| 9072 | @Override |
| 9073 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9074 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9075 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9076 | |
| 9077 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9078 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9079 | if (phone == null) { |
| 9080 | return null; |
| 9081 | } |
| 9082 | String esn = null; |
| 9083 | try { |
| 9084 | esn = phone.getEsn(); |
| 9085 | } catch (Exception e) { |
| 9086 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9087 | } |
| 9088 | return esn; |
| 9089 | } finally { |
| 9090 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9091 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9092 | } |
| 9093 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9094 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9095 | * Return the Preferred Roaming List Version. |
| 9096 | * |
| 9097 | * @param subId the subscription ID that this request applies to. |
| 9098 | * @return PRLVersion or null if error. |
| 9099 | */ |
| 9100 | @Override |
| 9101 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9102 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9103 | |
| 9104 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9105 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9106 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9107 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9108 | |
| 9109 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9110 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9111 | if (phone == null) { |
| 9112 | return null; |
| 9113 | } |
| 9114 | String cdmaPrlVersion = null; |
| 9115 | try { |
| 9116 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9117 | } catch (Exception e) { |
| 9118 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9119 | } |
| 9120 | return cdmaPrlVersion; |
| 9121 | } finally { |
| 9122 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9123 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9124 | } |
| 9125 | |
| 9126 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9127 | * Get snapshot of Telephony histograms |
| 9128 | * @return List of Telephony histograms |
| 9129 | * @hide |
| 9130 | */ |
| 9131 | @Override |
| 9132 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9133 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9134 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9135 | |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
| 9137 | try { |
| 9138 | return RIL.getTelephonyRILTimingHistograms(); |
| 9139 | } finally { |
| 9140 | Binder.restoreCallingIdentity(identity); |
| 9141 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9142 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9143 | |
| 9144 | /** |
| 9145 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9146 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9147 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9148 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9149 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9150 | * @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] | 9151 | */ |
| 9152 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9153 | @TelephonyManager.SetCarrierRestrictionResult |
| 9154 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9155 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9156 | |
| 9157 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9158 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9159 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9160 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9161 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9162 | if (carrierRestrictionRules == null) { |
| 9163 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9164 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9166 | final long identity = Binder.clearCallingIdentity(); |
| 9167 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9168 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9169 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9170 | } finally { |
| 9171 | Binder.restoreCallingIdentity(identity); |
| 9172 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9173 | } |
| 9174 | |
| 9175 | /** |
| 9176 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9177 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9178 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9179 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9180 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9181 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9182 | */ |
| 9183 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9184 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9185 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9186 | |
| 9187 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9188 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9189 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9190 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9191 | |
| 9192 | final long identity = Binder.clearCallingIdentity(); |
| 9193 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9194 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9195 | if (response instanceof CarrierRestrictionRules) { |
| 9196 | return (CarrierRestrictionRules) response; |
| 9197 | } |
| 9198 | // Response is an Exception of some kind, |
| 9199 | // which is signalled to the user as a NULL retval |
| 9200 | return null; |
| 9201 | } catch (Exception e) { |
| 9202 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9203 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9204 | } finally { |
| 9205 | Binder.restoreCallingIdentity(identity); |
| 9206 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9207 | } |
| 9208 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9209 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9210 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9211 | * through the callback. |
| 9212 | * |
| 9213 | * @param callback The callback that will be used to send the result. |
| 9214 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9215 | * the caller is not allowlisted. |
| 9216 | */ |
| 9217 | @Override |
| 9218 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9219 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9220 | |
| 9221 | enforceTelephonyFeatureWithException(packageName, |
| 9222 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9223 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9224 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 9225 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 9226 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9227 | throw new SecurityException("Not an authorized caller"); |
| 9228 | } |
| 9229 | final long identity = Binder.clearCallingIdentity(); |
| 9230 | try { |
| 9231 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 9232 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 9233 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9234 | } finally { |
| 9235 | Binder.restoreCallingIdentity(identity); |
| 9236 | } |
| 9237 | } |
| 9238 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9239 | @Override |
| 9240 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9241 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9242 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9243 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9244 | } |
| 9245 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9246 | @VisibleForTesting |
| 9247 | public int validateCallerAndGetCarrierId(String packageName) { |
| 9248 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9249 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 9250 | } |
| 9251 | |
| 9252 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9253 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9254 | * @param subId the subscription ID that this action applies to. |
| 9255 | * @param enabled control enable or disable radio. |
| 9256 | * {@hide} |
| 9257 | */ |
| 9258 | @Override |
| 9259 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9260 | enforceModifyPermission(); |
| 9261 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9262 | |
| 9263 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9264 | if (phone == null) { |
| 9265 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9266 | return; |
| 9267 | } |
| 9268 | try { |
| 9269 | phone.carrierActionSetRadioEnabled(enabled); |
| 9270 | } catch (Exception e) { |
| 9271 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9272 | } finally { |
| 9273 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9274 | } |
| 9275 | } |
| 9276 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9277 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9278 | * Enable or disable Voice over NR (VoNR) |
| 9279 | * @param subId the subscription ID that this action applies to. |
| 9280 | * @param enabled enable or disable VoNR. |
| 9281 | * @return operation result. |
| 9282 | */ |
| 9283 | @Override |
| 9284 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9285 | enforceModifyPermission(); |
| 9286 | final Phone phone = getPhone(subId); |
| 9287 | |
| 9288 | final long identity = Binder.clearCallingIdentity(); |
| 9289 | if (phone == null) { |
| 9290 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9291 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9292 | } |
| 9293 | |
| 9294 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9295 | try { |
| 9296 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9297 | workSource); |
| 9298 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9299 | |
| 9300 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9301 | if (DBG) { |
| 9302 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9303 | } |
| 9304 | SubscriptionManager.setSubscriptionProperty( |
| 9305 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9306 | (enabled ? "1" : "0")); |
| 9307 | } |
| 9308 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9309 | return result; |
| 9310 | } finally { |
| 9311 | Binder.restoreCallingIdentity(identity); |
| 9312 | } |
| 9313 | } |
| 9314 | |
| 9315 | /** |
| 9316 | * Is voice over NR enabled |
| 9317 | * @return true if VoNR is enabled else false |
| 9318 | */ |
| 9319 | @Override |
| 9320 | public boolean isVoNrEnabled(int subId) { |
| 9321 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9322 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9323 | final long identity = Binder.clearCallingIdentity(); |
| 9324 | try { |
| 9325 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9326 | null, subId, workSource); |
| 9327 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9328 | return isEnabled; |
| 9329 | } finally { |
| 9330 | Binder.restoreCallingIdentity(identity); |
| 9331 | } |
| 9332 | } |
| 9333 | |
| 9334 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9335 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9336 | * network status based on which carrier apps could apply actions accordingly, |
| 9337 | * enable/disable default url handler for example. |
| 9338 | * |
| 9339 | * @param subId the subscription ID that this action applies to. |
| 9340 | * @param report control start/stop reporting the default network status. |
| 9341 | * {@hide} |
| 9342 | */ |
| 9343 | @Override |
| 9344 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9345 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9346 | |
| 9347 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9348 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9349 | "carrierActionReportDefaultNetworkStatus"); |
| 9350 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9351 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9352 | |
| 9353 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9354 | if (phone == null) { |
| 9355 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9356 | return; |
| 9357 | } |
| 9358 | try { |
| 9359 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9360 | } catch (Exception e) { |
| 9361 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9362 | } finally { |
| 9363 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9364 | } |
| 9365 | } |
| 9366 | |
| 9367 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9368 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9369 | * @param subId the subscription ID that this action applies to. |
| 9370 | * {@hide} |
| 9371 | */ |
| 9372 | @Override |
| 9373 | public void carrierActionResetAll(int subId) { |
| 9374 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9375 | |
| 9376 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9377 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9378 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9379 | final Phone phone = getPhone(subId); |
| 9380 | if (phone == null) { |
| 9381 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9382 | return; |
| 9383 | } |
| 9384 | try { |
| 9385 | phone.carrierActionResetAll(); |
| 9386 | } catch (Exception e) { |
| 9387 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9388 | } |
| 9389 | } |
| 9390 | |
| 9391 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9392 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9393 | * bug report is being generated. |
| 9394 | */ |
| 9395 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9396 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9397 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9398 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9399 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9400 | + Binder.getCallingPid() |
| 9401 | + ", uid=" + Binder.getCallingUid() |
| 9402 | + "without permission " |
| 9403 | + android.Manifest.permission.DUMP); |
| 9404 | return; |
| 9405 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9406 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9407 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9408 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9409 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9410 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9411 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9412 | @NonNull String[] args) { |
| 9413 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9414 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9415 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9416 | } |
| 9417 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9418 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9419 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9420 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9421 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9422 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9423 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9424 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9425 | */ |
| 9426 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9427 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9428 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9429 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9430 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9431 | try { |
| 9432 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9433 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9434 | } catch (SecurityException se) { |
| 9435 | enforceModifyPermission(); |
| 9436 | } |
| 9437 | } else { |
| 9438 | enforceModifyPermission(); |
| 9439 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9440 | |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 9441 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9442 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 9443 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(), |
| 9444 | callingPackage, null, null); |
| 9445 | } |
| 9446 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9447 | enforceTelephonyFeatureWithException(callingPackage, |
| 9448 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9449 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9450 | final long identity = Binder.clearCallingIdentity(); |
| 9451 | try { |
| 9452 | Phone phone = getPhone(subId); |
| 9453 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9454 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9455 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9456 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9457 | phone.getDataSettingsManager().setDataEnabled( |
| 9458 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9459 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9460 | } |
| 9461 | } finally { |
| 9462 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9463 | } |
| 9464 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9465 | |
| 9466 | /** |
| 9467 | * Get Client request stats |
| 9468 | * @return List of Client Request Stats |
| 9469 | * @hide |
| 9470 | */ |
| 9471 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9472 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9473 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9474 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9475 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9476 | return null; |
| 9477 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9478 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9479 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9480 | final long identity = Binder.clearCallingIdentity(); |
| 9481 | try { |
| 9482 | if (phone != null) { |
| 9483 | return phone.getClientRequestStats(); |
| 9484 | } |
| 9485 | |
| 9486 | return null; |
| 9487 | } finally { |
| 9488 | Binder.restoreCallingIdentity(identity); |
| 9489 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9490 | } |
| 9491 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9492 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9493 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9494 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9495 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9496 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9497 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9498 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9499 | // commands that plumb through the RIL as root, like so: |
| 9500 | // $ adb root |
| 9501 | // $ adb shell cmd phone ... |
| 9502 | packageName = "root"; |
| 9503 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9504 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9505 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9506 | |
| 9507 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9508 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9509 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9510 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9511 | * @param state State of SIM (power down, power up, pass through) |
| 9512 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9513 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9514 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9515 | * |
| 9516 | **/ |
| 9517 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9518 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9519 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9520 | |
| 9521 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9522 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9523 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9524 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9525 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9526 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9527 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9528 | final long identity = Binder.clearCallingIdentity(); |
| 9529 | try { |
| 9530 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9531 | phone.setSimPowerState(state, null, workSource); |
| 9532 | } |
| 9533 | } finally { |
| 9534 | Binder.restoreCallingIdentity(identity); |
| 9535 | } |
| 9536 | } |
| 9537 | |
| 9538 | /** |
| 9539 | * Set SIM card power state. |
| 9540 | * |
| 9541 | * @param slotIndex SIM slot id. |
| 9542 | * @param state State of SIM (power down, power up, pass through) |
| 9543 | * @param callback callback to trigger after success or failure |
| 9544 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9545 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9546 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9547 | * |
| 9548 | **/ |
| 9549 | @Override |
| 9550 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9551 | IIntegerConsumer callback) { |
| 9552 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9553 | |
| 9554 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9555 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9556 | "setSimPowerStateForSlotWithCallback"); |
| 9557 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9558 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9559 | |
| 9560 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9561 | |
| 9562 | final long identity = Binder.clearCallingIdentity(); |
| 9563 | try { |
| 9564 | if (phone != null) { |
| 9565 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9566 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9567 | } |
| 9568 | } finally { |
| 9569 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9570 | } |
| 9571 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9572 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9573 | private boolean isUssdApiAllowed(int subId) { |
| 9574 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9575 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9576 | if (configManager == null) { |
| 9577 | return false; |
| 9578 | } |
| 9579 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9580 | if (pb == null) { |
| 9581 | return false; |
| 9582 | } |
| 9583 | return pb.getBoolean( |
| 9584 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9585 | } |
| 9586 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9587 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9588 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9589 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9590 | * @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] | 9591 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9592 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9593 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9594 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9595 | |
| 9596 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9597 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9598 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9599 | final long identity = Binder.clearCallingIdentity(); |
| 9600 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9601 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9602 | } finally { |
| 9603 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9604 | } |
| 9605 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9606 | |
| 9607 | /** |
| 9608 | * Get the current signal strength information for the given subscription. |
| 9609 | * Because this information is not updated when the device is in a low power state |
| 9610 | * it should not be relied-upon to be current. |
| 9611 | * @param subId Subscription index |
| 9612 | * @return the most recent cached signal strength info from the modem |
| 9613 | */ |
| 9614 | @Override |
| 9615 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9616 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9617 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9619 | final long identity = Binder.clearCallingIdentity(); |
| 9620 | try { |
| 9621 | Phone p = getPhone(subId); |
| 9622 | if (p == null) { |
| 9623 | return null; |
| 9624 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9625 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9626 | return p.getSignalStrength(); |
| 9627 | } finally { |
| 9628 | Binder.restoreCallingIdentity(identity); |
| 9629 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9630 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9631 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9632 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9633 | * Get the current modem radio state for the given slot. |
| 9634 | * @param slotIndex slot index. |
| 9635 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9636 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9637 | * @return the current radio power state from the modem |
| 9638 | */ |
| 9639 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9640 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9641 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9642 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9643 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9644 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9645 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9646 | } |
| 9647 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9648 | enforceTelephonyFeatureWithException(callingPackage, |
| 9649 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9650 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9651 | final long identity = Binder.clearCallingIdentity(); |
| 9652 | try { |
| 9653 | return phone.getRadioPowerState(); |
| 9654 | } finally { |
| 9655 | Binder.restoreCallingIdentity(identity); |
| 9656 | } |
| 9657 | } |
| 9658 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9659 | } |
| 9660 | |
| 9661 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9662 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9663 | * |
| 9664 | * <p>Requires one of the following permissions: |
| 9665 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9666 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9667 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9668 | * privileges. |
| 9669 | * |
| 9670 | * @param subId subscription id |
| 9671 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9672 | * {@code false}. |
| 9673 | */ |
| 9674 | @Override |
| 9675 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9676 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9677 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9678 | try { |
| 9679 | mApp.enforceCallingOrSelfPermission( |
| 9680 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9681 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9682 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9683 | mApp.enforceCallingOrSelfPermission( |
| 9684 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9685 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9686 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9687 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9688 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9689 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9690 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9691 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9692 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9693 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9694 | boolean isEnabled = false; |
| 9695 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9696 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9697 | Phone phone = getPhone(subId); |
| 9698 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9699 | } finally { |
| 9700 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9701 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9702 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9703 | } |
| 9704 | |
| 9705 | |
| 9706 | /** |
| 9707 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9708 | * |
| 9709 | * <p> Requires permission: |
| 9710 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9711 | * privileges. |
| 9712 | * |
| 9713 | * @param subId subscription id |
| 9714 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9715 | */ |
| 9716 | @Override |
| 9717 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9718 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9719 | mApp, subId, "setDataRoamingEnabled"); |
| 9720 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9721 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9722 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9723 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9724 | final long identity = Binder.clearCallingIdentity(); |
| 9725 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9726 | Phone phone = getPhone(subId); |
| 9727 | if (phone != null) { |
| 9728 | phone.setDataRoamingEnabled(isEnabled); |
| 9729 | } |
| 9730 | } finally { |
| 9731 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9732 | } |
| 9733 | } |
| 9734 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9735 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9736 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9737 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9738 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9739 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9740 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9741 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9742 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9743 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9744 | boolean isAllowed = true; |
| 9745 | final long identity = Binder.clearCallingIdentity(); |
| 9746 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9747 | Phone phone = getPhone(subId); |
| 9748 | if (phone != null) { |
| 9749 | isAllowed = phone.isCspPlmnEnabled(); |
| 9750 | } |
| 9751 | } finally { |
| 9752 | Binder.restoreCallingIdentity(identity); |
| 9753 | } |
| 9754 | return isAllowed; |
| 9755 | } |
| 9756 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9757 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9758 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9759 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9760 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9761 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9762 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9763 | if (phone == null) { |
| 9764 | return false; |
| 9765 | } |
| 9766 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9767 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9768 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9769 | } |
| 9770 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9771 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9772 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9773 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9774 | mApp.getSystemService(AppOpsManager.class) |
| 9775 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9776 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9777 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9778 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9779 | try { |
| 9780 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9781 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9782 | } catch (SecurityException e) { |
| 9783 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9784 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9785 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9786 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9787 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9788 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9789 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9790 | |
| 9791 | enforceTelephonyFeatureWithException(callingPackage, |
| 9792 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9793 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9794 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9795 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9796 | Binder.getCallingUid())) { |
| 9797 | isIccIdAccessRestricted = true; |
| 9798 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9799 | final long identity = Binder.clearCallingIdentity(); |
| 9800 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9801 | UiccController uiccController = UiccController.getInstance(); |
| 9802 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9803 | if (hasReadPermission) { |
| 9804 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9805 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9806 | |
| 9807 | // Remove private info if the caller doesn't have access |
| 9808 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9809 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9810 | //setting the value after compatibility check |
| 9811 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9812 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9813 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9814 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9815 | if (card == null) { |
| 9816 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9817 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9818 | continue; |
| 9819 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9820 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9821 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9822 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9823 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9824 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9825 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9826 | for (UiccPortInfo portInfo : portInfos) { |
| 9827 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9828 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9829 | if (port == null) { |
| 9830 | // assume no access if port is null |
| 9831 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9832 | continue; |
| 9833 | } |
| 9834 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9835 | uiccPortInfos.add(portInfo); |
| 9836 | } else { |
| 9837 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9838 | } |
| 9839 | } |
| 9840 | filteredInfos.add(new UiccCardInfo( |
| 9841 | cardInfo.isEuicc(), |
| 9842 | cardInfo.getCardId(), |
| 9843 | null, |
| 9844 | cardInfo.getPhysicalSlotIndex(), |
| 9845 | cardInfo.isRemovable(), |
| 9846 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9847 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9848 | } |
| 9849 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9850 | } finally { |
| 9851 | Binder.restoreCallingIdentity(identity); |
| 9852 | } |
| 9853 | } |
| 9854 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9855 | /** |
| 9856 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9857 | * generally private and require carrier privileges to view. |
| 9858 | * |
| 9859 | * @hide |
| 9860 | */ |
| 9861 | @NonNull |
| 9862 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9863 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9864 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9865 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9866 | } |
| 9867 | return new UiccCardInfo( |
| 9868 | cardInfo.isEuicc(), |
| 9869 | cardInfo.getCardId(), |
| 9870 | null, |
| 9871 | cardInfo.getPhysicalSlotIndex(), |
| 9872 | cardInfo.isRemovable(), |
| 9873 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9874 | portinfo |
| 9875 | ); |
| 9876 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9877 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9878 | /** |
| 9879 | * @hide |
| 9880 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9881 | * These values are generally private and require carrier privileges to view. |
| 9882 | */ |
| 9883 | @NonNull |
| 9884 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9885 | return new UiccPortInfo( |
| 9886 | UiccPortInfo.ICCID_REDACTED, |
| 9887 | portInfo.getPortIndex(), |
| 9888 | portInfo.getLogicalSlotIndex(), |
| 9889 | portInfo.isActive() |
| 9890 | ); |
| 9891 | } |
| 9892 | @Override |
| 9893 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9894 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9895 | mApp.getSystemService(AppOpsManager.class) |
| 9896 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9897 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9898 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9899 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9900 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9901 | // we are reading iccId which is PII data. |
| 9902 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9903 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9904 | enforceTelephonyFeatureWithException(callingPackage, |
| 9905 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 9906 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9907 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9908 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9909 | Binder.getCallingUid())) { |
| 9910 | isLogicalSlotAccessRestricted = true; |
| 9911 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9912 | final long identity = Binder.clearCallingIdentity(); |
| 9913 | try { |
| 9914 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9915 | if (slots == null || slots.length == 0) { |
| 9916 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9917 | return null; |
| 9918 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9919 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9920 | for (int i = 0; i < slots.length; i++) { |
| 9921 | UiccSlot slot = slots[i]; |
| 9922 | if (slot == null) { |
| 9923 | continue; |
| 9924 | } |
| 9925 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9926 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9927 | UiccCard card = slot.getUiccCard(); |
| 9928 | if (card != null) { |
| 9929 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9930 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9931 | cardId = slot.getEid(); |
| 9932 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9933 | // If cardId is null, use iccId of default port as cardId. |
| 9934 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9935 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9936 | } |
| 9937 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9938 | if (cardId != null) { |
| 9939 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9940 | // if cardId is an EID, it's all digits so this is fine |
| 9941 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9942 | } |
| 9943 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9944 | int cardState = 0; |
| 9945 | switch (slot.getCardState()) { |
| 9946 | case CARDSTATE_ABSENT: |
| 9947 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9948 | break; |
| 9949 | case CARDSTATE_PRESENT: |
| 9950 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9951 | break; |
| 9952 | case CARDSTATE_ERROR: |
| 9953 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9954 | break; |
| 9955 | case CARDSTATE_RESTRICTED: |
| 9956 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9957 | break; |
| 9958 | default: |
| 9959 | break; |
| 9960 | |
| 9961 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9962 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9963 | int[] portIndexes = slot.getPortList(); |
| 9964 | for (int portIdx : portIndexes) { |
| 9965 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9966 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9967 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9968 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9969 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9970 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9971 | slot.isEuicc(), |
| 9972 | cardId, |
| 9973 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9974 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9975 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9976 | //setting the value after compatibility check |
| 9977 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9978 | } |
| 9979 | return infos; |
| 9980 | } finally { |
| 9981 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9982 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9983 | } |
| 9984 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9985 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9986 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9987 | boolean hasReadPermission) { |
| 9988 | String iccId = slot.getIccId(portIndex); |
| 9989 | if (hasReadPermission) { // if has read permission |
| 9990 | return iccId; |
| 9991 | } else { |
| 9992 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9993 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9994 | // if no read permission, checking carrier privilege access |
| 9995 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9996 | return iccId; |
| 9997 | } |
| 9998 | } |
| 9999 | } |
| 10000 | // No read permission or carrier privilege access. |
| 10001 | return UiccPortInfo.ICCID_REDACTED; |
| 10002 | } |
| 10003 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10004 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10005 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10006 | public boolean switchSlots(int[] physicalSlots) { |
| 10007 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10008 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10009 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10010 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10012 | final long identity = Binder.clearCallingIdentity(); |
| 10013 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10014 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10015 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10016 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10017 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10018 | physicalSlots[i], i)); |
| 10019 | } |
| 10020 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10021 | } finally { |
| 10022 | Binder.restoreCallingIdentity(identity); |
| 10023 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10024 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10025 | |
| 10026 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10027 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10028 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10029 | enforceModifyPermission(); |
| 10030 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10031 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10032 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10033 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10034 | final long identity = Binder.clearCallingIdentity(); |
| 10035 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10036 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10037 | } finally { |
| 10038 | Binder.restoreCallingIdentity(identity); |
| 10039 | } |
| 10040 | } |
| 10041 | |
| 10042 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10043 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10044 | enforceTelephonyFeatureWithException(callingPackage, |
| 10045 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10046 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10047 | final long identity = Binder.clearCallingIdentity(); |
| 10048 | try { |
| 10049 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10050 | } finally { |
| 10051 | Binder.restoreCallingIdentity(identity); |
| 10052 | } |
| 10053 | } |
| 10054 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10055 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10056 | * A test API to reload the UICC profile. |
| 10057 | * |
| 10058 | * <p>Requires that the calling app has permission |
| 10059 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10060 | * @hide |
| 10061 | */ |
| 10062 | @Override |
| 10063 | public void refreshUiccProfile(int subId) { |
| 10064 | enforceModifyPermission(); |
| 10065 | |
| 10066 | final long identity = Binder.clearCallingIdentity(); |
| 10067 | try { |
| 10068 | Phone phone = getPhone(subId); |
| 10069 | if (phone == null) { |
| 10070 | return; |
| 10071 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10072 | UiccPort uiccPort = phone.getUiccPort(); |
| 10073 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10074 | return; |
| 10075 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10076 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10077 | if (uiccProfile == null) { |
| 10078 | return; |
| 10079 | } |
| 10080 | uiccProfile.refresh(); |
| 10081 | } finally { |
| 10082 | Binder.restoreCallingIdentity(identity); |
| 10083 | } |
| 10084 | } |
| 10085 | |
| 10086 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10087 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10088 | */ |
| 10089 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10090 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10091 | } |
| 10092 | |
| 10093 | /** |
| 10094 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 10095 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 10096 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 10097 | */ |
| 10098 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 10099 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10100 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 10101 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10102 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 10103 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 10104 | return isDataRoamingEnabled; |
| 10105 | } |
| 10106 | |
| 10107 | /** |
| 10108 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10109 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10110 | */ |
| 10111 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10112 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10113 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10114 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10115 | return list.get(phoneId); |
| 10116 | } |
| 10117 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10118 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10119 | |
| 10120 | @Override |
| 10121 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10122 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10123 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10124 | |
| 10125 | final long identity = Binder.clearCallingIdentity(); |
| 10126 | try { |
| 10127 | final Phone phone = getPhone(subId); |
| 10128 | if (phone == null) { |
| 10129 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10130 | return; |
| 10131 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10132 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10133 | if (cpt != null) { |
| 10134 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10135 | } |
| 10136 | // 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] | 10137 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10138 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10139 | if (carrierPrivilegeRules == null) { |
| 10140 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10141 | } else { |
| 10142 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10143 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10144 | } finally { |
| 10145 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10146 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10147 | } |
| 10148 | |
| 10149 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10150 | public void setCarrierServicePackageOverride( |
| 10151 | int subId, String carrierServicePackage, String callingPackage) { |
| 10152 | TelephonyPermissions.enforceShellOnly( |
| 10153 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10154 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10155 | final long identity = Binder.clearCallingIdentity(); |
| 10156 | try { |
| 10157 | final Phone phone = getPhone(subId); |
| 10158 | if (phone == null || phone.getSubId() != subId) { |
| 10159 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10160 | throw new IllegalArgumentException("No phone for subid"); |
| 10161 | } |
| 10162 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10163 | if (cpt == null) { |
| 10164 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10165 | throw new IllegalStateException("No CPT for phone"); |
| 10166 | } |
| 10167 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10168 | } finally { |
| 10169 | Binder.restoreCallingIdentity(identity); |
| 10170 | } |
| 10171 | } |
| 10172 | |
| 10173 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10174 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10175 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10176 | |
| 10177 | final long identity = Binder.clearCallingIdentity(); |
| 10178 | try { |
| 10179 | final Phone phone = getPhone(subId); |
| 10180 | if (phone == null) { |
| 10181 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10182 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10183 | } |
| 10184 | return phone.getCarrierIdListVersion(); |
| 10185 | } finally { |
| 10186 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10187 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10188 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10189 | |
| 10190 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10191 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10192 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10193 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10194 | mApp, subId, callingPackage, callingFeatureId, |
| 10195 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10196 | return -1; |
| 10197 | } |
| 10198 | |
| 10199 | final long identity = Binder.clearCallingIdentity(); |
| 10200 | try { |
| 10201 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10202 | } finally { |
| 10203 | Binder.restoreCallingIdentity(identity); |
| 10204 | } |
| 10205 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10206 | |
| 10207 | @Override |
| 10208 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10209 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10210 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10211 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10212 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10213 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10214 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10215 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10216 | final long identity = Binder.clearCallingIdentity(); |
| 10217 | try { |
| 10218 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10219 | } finally { |
| 10220 | Binder.restoreCallingIdentity(identity); |
| 10221 | } |
| 10222 | } |
| 10223 | |
| 10224 | @Override |
| 10225 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10226 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10227 | mApp, subId, "setCdmaRoamingMode"); |
| 10228 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10229 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10230 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10231 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10232 | final long identity = Binder.clearCallingIdentity(); |
| 10233 | try { |
| 10234 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10235 | } finally { |
| 10236 | Binder.restoreCallingIdentity(identity); |
| 10237 | } |
| 10238 | } |
| 10239 | |
| 10240 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10241 | public int getCdmaSubscriptionMode(int subId) { |
| 10242 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10243 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10244 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10245 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10246 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10247 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10248 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10249 | final long identity = Binder.clearCallingIdentity(); |
| 10250 | try { |
| 10251 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10252 | } finally { |
| 10253 | Binder.restoreCallingIdentity(identity); |
| 10254 | } |
| 10255 | } |
| 10256 | |
| 10257 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10258 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10260 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10261 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10262 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10263 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10264 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10265 | final long identity = Binder.clearCallingIdentity(); |
| 10266 | try { |
| 10267 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10268 | } finally { |
| 10269 | Binder.restoreCallingIdentity(identity); |
| 10270 | } |
| 10271 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10272 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10273 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10274 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10275 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10276 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10277 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10278 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10279 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10280 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10281 | |
| 10282 | enforceTelephonyFeatureWithException(callingPackage, |
| 10283 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10284 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10285 | final long identity = Binder.clearCallingIdentity(); |
| 10286 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10287 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10288 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10289 | if (phone.getEmergencyNumberTracker() != null |
| 10290 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10291 | emergencyNumberListInternal.put( |
| 10292 | phone.getSubId(), |
| 10293 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10294 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10295 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10296 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10297 | } finally { |
| 10298 | Binder.restoreCallingIdentity(identity); |
| 10299 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10300 | } |
| 10301 | |
| 10302 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10303 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10304 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10305 | if (!exactMatch) { |
| 10306 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10307 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10308 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10309 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10310 | |
| 10311 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10312 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10313 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10314 | final long identity = Binder.clearCallingIdentity(); |
| 10315 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10316 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10317 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10318 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10319 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10320 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10321 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10322 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10323 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10324 | } |
| 10325 | return false; |
| 10326 | } finally { |
| 10327 | Binder.restoreCallingIdentity(identity); |
| 10328 | } |
| 10329 | } |
| 10330 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10331 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10332 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10333 | */ |
| 10334 | @Override |
| 10335 | public void startEmergencyCallbackMode() { |
| 10336 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10337 | "startEmergencyCallbackMode"); |
| 10338 | enforceModifyPermission(); |
| 10339 | final long identity = Binder.clearCallingIdentity(); |
| 10340 | try { |
| 10341 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10342 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10343 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10344 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10345 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10346 | gsmCdmaPhone.obtainMessage( |
| 10347 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10348 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10349 | } |
| 10350 | } |
| 10351 | } finally { |
| 10352 | Binder.restoreCallingIdentity(identity); |
| 10353 | } |
| 10354 | } |
| 10355 | |
| 10356 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10357 | * Update emergency number list for test mode. |
| 10358 | */ |
| 10359 | @Override |
| 10360 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10361 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10362 | "updateEmergencyNumberListTestMode"); |
| 10363 | |
| 10364 | final long identity = Binder.clearCallingIdentity(); |
| 10365 | try { |
| 10366 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10367 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10368 | if (tracker != null) { |
| 10369 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10370 | } |
| 10371 | } |
| 10372 | } finally { |
| 10373 | Binder.restoreCallingIdentity(identity); |
| 10374 | } |
| 10375 | } |
| 10376 | |
| 10377 | /** |
| 10378 | * Get the full emergency number list for test mode. |
| 10379 | */ |
| 10380 | @Override |
| 10381 | public List<String> getEmergencyNumberListTestMode() { |
| 10382 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10383 | "getEmergencyNumberListTestMode"); |
| 10384 | |
| 10385 | final long identity = Binder.clearCallingIdentity(); |
| 10386 | try { |
| 10387 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10388 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10389 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10390 | if (tracker != null) { |
| 10391 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10392 | emergencyNumbers.add(num.getNumber()); |
| 10393 | } |
| 10394 | } |
| 10395 | } |
| 10396 | return new ArrayList<>(emergencyNumbers); |
| 10397 | } finally { |
| 10398 | Binder.restoreCallingIdentity(identity); |
| 10399 | } |
| 10400 | } |
| 10401 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10402 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10403 | public int getEmergencyNumberDbVersion(int subId) { |
| 10404 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10405 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10406 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10407 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10408 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10409 | final long identity = Binder.clearCallingIdentity(); |
| 10410 | try { |
| 10411 | final Phone phone = getPhone(subId); |
| 10412 | if (phone == null) { |
| 10413 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10414 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10415 | } |
| 10416 | return phone.getEmergencyNumberDbVersion(); |
| 10417 | } finally { |
| 10418 | Binder.restoreCallingIdentity(identity); |
| 10419 | } |
| 10420 | } |
| 10421 | |
| 10422 | @Override |
| 10423 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10424 | enforceModifyPermission(); |
| 10425 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10426 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10427 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10428 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10429 | final long identity = Binder.clearCallingIdentity(); |
| 10430 | try { |
| 10431 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10432 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10433 | if (tracker != null) { |
| 10434 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10435 | } |
| 10436 | } |
| 10437 | } finally { |
| 10438 | Binder.restoreCallingIdentity(identity); |
| 10439 | } |
| 10440 | } |
| 10441 | |
| 10442 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10443 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10444 | enforceActiveEmergencySessionPermission(); |
| 10445 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10446 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10447 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10448 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10449 | final long identity = Binder.clearCallingIdentity(); |
| 10450 | try { |
| 10451 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10452 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10453 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10454 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10455 | } |
| 10456 | } |
| 10457 | } finally { |
| 10458 | Binder.restoreCallingIdentity(identity); |
| 10459 | } |
| 10460 | } |
| 10461 | |
| 10462 | @Override |
| 10463 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10464 | enforceActiveEmergencySessionPermission(); |
| 10465 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10466 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10467 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10468 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10469 | final long identity = Binder.clearCallingIdentity(); |
| 10470 | try { |
| 10471 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10472 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10473 | if (tracker != null) { |
| 10474 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10475 | } |
| 10476 | } |
| 10477 | } finally { |
| 10478 | Binder.restoreCallingIdentity(identity); |
| 10479 | } |
| 10480 | } |
| 10481 | |
| 10482 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10483 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10484 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10485 | Phone phone = getPhone(subId); |
| 10486 | if (phone == null) { |
| 10487 | return null; |
| 10488 | } |
| 10489 | final long identity = Binder.clearCallingIdentity(); |
| 10490 | try { |
| 10491 | UiccProfile profile = UiccController.getInstance() |
| 10492 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10493 | if (profile != null) { |
| 10494 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10495 | } |
| 10496 | } finally { |
| 10497 | Binder.restoreCallingIdentity(identity); |
| 10498 | } |
| 10499 | return null; |
| 10500 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10501 | |
| 10502 | /** |
| 10503 | * Enable or disable a modem stack. |
| 10504 | */ |
| 10505 | @Override |
| 10506 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10507 | enforceModifyPermission(); |
| 10508 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10509 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10510 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10511 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10512 | final long identity = Binder.clearCallingIdentity(); |
| 10513 | try { |
| 10514 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10515 | if (phone == null) { |
| 10516 | return false; |
| 10517 | } else { |
| 10518 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10519 | } |
| 10520 | } finally { |
| 10521 | Binder.restoreCallingIdentity(identity); |
| 10522 | } |
| 10523 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10524 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10525 | /** |
| 10526 | * Whether a modem stack is enabled or not. |
| 10527 | */ |
| 10528 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10529 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10530 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10531 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10532 | if (phone == null) return false; |
| 10533 | |
| 10534 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10535 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10536 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10537 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10538 | } |
| 10539 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10540 | enforceTelephonyFeatureWithException(callingPackage, |
| 10541 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10542 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10543 | final long identity = Binder.clearCallingIdentity(); |
| 10544 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10545 | try { |
| 10546 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10547 | } catch (NoSuchElementException ex) { |
| 10548 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10549 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10550 | } finally { |
| 10551 | Binder.restoreCallingIdentity(identity); |
| 10552 | } |
| 10553 | } |
| 10554 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10555 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10556 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10557 | enforceModifyPermission(); |
| 10558 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10559 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10560 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10561 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10562 | final long identity = Binder.clearCallingIdentity(); |
| 10563 | try { |
| 10564 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10565 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10566 | .commit(); |
| 10567 | } finally { |
| 10568 | Binder.restoreCallingIdentity(identity); |
| 10569 | } |
| 10570 | } |
| 10571 | |
| 10572 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10573 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10574 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10575 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10576 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10577 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10578 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10579 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10580 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10581 | enforceTelephonyFeatureWithException(callingPackage, |
| 10582 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10583 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10584 | final long identity = Binder.clearCallingIdentity(); |
| 10585 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10586 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10587 | } finally { |
| 10588 | Binder.restoreCallingIdentity(identity); |
| 10589 | } |
| 10590 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10591 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10592 | @TelephonyManager.IsMultiSimSupportedResult |
| 10593 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10594 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10595 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10596 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10597 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10598 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10599 | } |
| 10600 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10601 | // supported by the modem, indicate that it is restricted. |
| 10602 | PhoneCapability staticCapability = |
| 10603 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10604 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10605 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10606 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10607 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10608 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10609 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10610 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10611 | } |
| 10612 | // Check if support of multiple SIMs is restricted by carrier |
| 10613 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10614 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10615 | } |
| 10616 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10617 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10618 | } |
| 10619 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10620 | /** |
| 10621 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10622 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10623 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10624 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10625 | * @param numOfSims number of active sims we want to switch to |
| 10626 | */ |
| 10627 | @Override |
| 10628 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10629 | if (numOfSims == 1) { |
| 10630 | enforceModifyPermission(); |
| 10631 | } else { |
| 10632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10633 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10634 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10635 | |
| 10636 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10637 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10638 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10639 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10640 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10641 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10642 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10643 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10644 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10645 | return; |
| 10646 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10647 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10648 | } finally { |
| 10649 | Binder.restoreCallingIdentity(identity); |
| 10650 | } |
| 10651 | } |
| 10652 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10653 | @Override |
| 10654 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10655 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10656 | |
| 10657 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10658 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10659 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10660 | Phone phone = getPhone(subId); |
| 10661 | if (phone == null) { |
| 10662 | return false; |
| 10663 | } |
| 10664 | final long identity = Binder.clearCallingIdentity(); |
| 10665 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10666 | UiccPort uiccPort = phone.getUiccPort(); |
| 10667 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10668 | return false; |
| 10669 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10670 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10671 | if (uiccProfile == null) { |
| 10672 | return false; |
| 10673 | } |
| 10674 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10675 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10676 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10677 | } |
| 10678 | return false; |
| 10679 | } finally { |
| 10680 | Binder.restoreCallingIdentity(identity); |
| 10681 | } |
| 10682 | } |
| 10683 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10684 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10685 | * Get whether making changes to modem configurations will trigger reboot. |
| 10686 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10687 | */ |
| 10688 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10689 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10690 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10691 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10692 | mApp, subId, callingPackage, callingFeatureId, |
| 10693 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10694 | return false; |
| 10695 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10696 | |
| 10697 | enforceTelephonyFeatureWithException(callingPackage, |
| 10698 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10699 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10700 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10701 | final long identity = Binder.clearCallingIdentity(); |
| 10702 | try { |
| 10703 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10704 | } finally { |
| 10705 | Binder.restoreCallingIdentity(identity); |
| 10706 | } |
| 10707 | } |
| 10708 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10709 | private void updateModemStateMetrics() { |
| 10710 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10711 | // TODO: check the state for each modem if the api is ready. |
| 10712 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10713 | } |
| 10714 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10715 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10716 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10717 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10718 | // Verify that the callingPackage belongs to the calling UID |
| 10719 | mApp.getSystemService(AppOpsManager.class) |
| 10720 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10721 | |
| 10722 | enforceTelephonyFeatureWithException(callingPackage, |
| 10723 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10724 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10725 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10726 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10727 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10728 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10729 | if (slotInfos != null) { |
| 10730 | for (int i = 0; i < slotInfos.length; i++) { |
| 10731 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10732 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10733 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10734 | portInfo.getLogicalSlotIndex())); |
| 10735 | } |
| 10736 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10737 | } |
| 10738 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10739 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10740 | } finally { |
| 10741 | Binder.restoreCallingIdentity(identity); |
| 10742 | } |
| 10743 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10744 | |
| 10745 | /** |
| 10746 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10747 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10748 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10749 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10750 | @Override |
| 10751 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10752 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10753 | } |
| 10754 | |
| 10755 | /** |
| 10756 | * Get the HAL Version of a specific service |
| 10757 | */ |
| 10758 | @Override |
| 10759 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10760 | Phone phone = getDefaultPhone(); |
| 10761 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10762 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10763 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10764 | return hv.major * 100 + hv.minor; |
| 10765 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10766 | |
| 10767 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10768 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10769 | * |
| 10770 | * @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] | 10771 | */ |
| 10772 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10773 | public @Nullable String getCurrentPackageName() { |
| 10774 | PackageManager pm = mApp.getPackageManager(); |
| 10775 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10776 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10777 | } |
| 10778 | |
| 10779 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10780 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10781 | * corresponding network requests on a subId. |
| 10782 | * |
| 10783 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10784 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10785 | * 2) APN is un-metered for this subscription, or |
| 10786 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10787 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10788 | * |
| 10789 | * @return whether data is allowed for a apn type. |
| 10790 | * |
| 10791 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10792 | */ |
| 10793 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10794 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10795 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10796 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10797 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10798 | enforceTelephonyFeatureWithException(callingPackage, |
| 10799 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10800 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10801 | // Now that all security checks passes, perform the operation as ourselves. |
| 10802 | final long identity = Binder.clearCallingIdentity(); |
| 10803 | try { |
| 10804 | Phone phone = getPhone(subId); |
| 10805 | if (phone == null) return false; |
| 10806 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10807 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10808 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10809 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10810 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10811 | phone.getServiceState().getDataRoaming()); |
| 10812 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10813 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10814 | } finally { |
| 10815 | Binder.restoreCallingIdentity(identity); |
| 10816 | } |
| 10817 | } |
| 10818 | |
| 10819 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10820 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10821 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10822 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10823 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10824 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10825 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10826 | // Now that all security checks passes, perform the operation as ourselves. |
| 10827 | final long identity = Binder.clearCallingIdentity(); |
| 10828 | try { |
| 10829 | Phone phone = getPhone(subId); |
| 10830 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10831 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10832 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10833 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10834 | } finally { |
| 10835 | Binder.restoreCallingIdentity(identity); |
| 10836 | } |
| 10837 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10838 | |
| 10839 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10840 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10841 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10842 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10843 | |
| 10844 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10845 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10846 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10847 | long token = Binder.clearCallingIdentity(); |
| 10848 | try { |
| 10849 | Phone phone = getPhone(subscriptionId); |
| 10850 | if (phone == null) { |
| 10851 | try { |
| 10852 | if (resultCallback != null) { |
| 10853 | resultCallback.accept(false); |
| 10854 | } |
| 10855 | } catch (RemoteException e) { |
| 10856 | // ignore |
| 10857 | } |
| 10858 | return; |
| 10859 | } |
| 10860 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10861 | Pair.create(specifiers, (x) -> { |
| 10862 | try { |
| 10863 | if (resultCallback != null) { |
| 10864 | resultCallback.accept(x); |
| 10865 | } |
| 10866 | } catch (RemoteException e) { |
| 10867 | // ignore |
| 10868 | } |
| 10869 | }); |
| 10870 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10871 | } finally { |
| 10872 | Binder.restoreCallingIdentity(token); |
| 10873 | } |
| 10874 | } |
| 10875 | |
| 10876 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10877 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10878 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10879 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10880 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10881 | |
| 10882 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10883 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10884 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10885 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10886 | final long identity = Binder.clearCallingIdentity(); |
| 10887 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10888 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10889 | if (result instanceof IllegalStateException) { |
| 10890 | throw (IllegalStateException) result; |
| 10891 | } |
| 10892 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10893 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10894 | return specifiers; |
| 10895 | } finally { |
| 10896 | Binder.restoreCallingIdentity(identity); |
| 10897 | } |
| 10898 | } |
| 10899 | |
| 10900 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10901 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10902 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10903 | |
| 10904 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10905 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 10906 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10907 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10908 | } |
| 10909 | |
| 10910 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10911 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10912 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10913 | if (callingPackage == null) { |
| 10914 | callingPackage = getCurrentPackageName(); |
| 10915 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10916 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10917 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10918 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10919 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10920 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10921 | } |
| 10922 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10923 | Intent intent = new Intent(); |
| 10924 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10925 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10926 | // Bring up choose default SMS subscription dialog right now |
| 10927 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10928 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10929 | mApp.startActivity(intent); |
| 10930 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10931 | |
| 10932 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10933 | public void showSwitchToManagedProfileDialog() { |
| 10934 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10935 | try { |
| 10936 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10937 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10938 | // for work telephony. |
| 10939 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10940 | intent.setData(Uri.parse("smsto:")); |
| 10941 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10942 | mApp.startActivity(intent); |
| 10943 | } catch (ActivityNotFoundException e) { |
| 10944 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10945 | Intent intent = new Intent(); |
| 10946 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10947 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10948 | mApp.startActivity(intent); |
| 10949 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10950 | } |
| 10951 | |
| 10952 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10953 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10954 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10955 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 10956 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10957 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10958 | final long identity = Binder.clearCallingIdentity(); |
| 10959 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10960 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10961 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10962 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10963 | return carrierUAProfUrl; |
| 10964 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10965 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10966 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10967 | } finally { |
| 10968 | Binder.restoreCallingIdentity(identity); |
| 10969 | } |
| 10970 | } |
| 10971 | |
| 10972 | @Override |
| 10973 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10974 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10975 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 10976 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10977 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10978 | final long identity = Binder.clearCallingIdentity(); |
| 10979 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10980 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10981 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10982 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10983 | return carrierUserAgent; |
| 10984 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10985 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10986 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10987 | } finally { |
| 10988 | Binder.restoreCallingIdentity(identity); |
| 10989 | } |
| 10990 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10991 | |
| 10992 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10993 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10994 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10995 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10996 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10997 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 10998 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10999 | final long identity = Binder.clearCallingIdentity(); |
| 11000 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11001 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11002 | if (phone == null) return false; |
| 11003 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11004 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11005 | } finally { |
| 11006 | Binder.restoreCallingIdentity(identity); |
| 11007 | } |
| 11008 | } |
| 11009 | |
| 11010 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11011 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11012 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11013 | enforceModifyPermission(); |
| 11014 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11015 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11016 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11017 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11018 | final long identity = Binder.clearCallingIdentity(); |
| 11019 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11020 | Phone phone = getPhone(subscriptionId); |
| 11021 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11022 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11023 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11024 | } finally { |
| 11025 | Binder.restoreCallingIdentity(identity); |
| 11026 | } |
| 11027 | } |
| 11028 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11029 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11030 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11031 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11032 | * otherwise. |
| 11033 | */ |
| 11034 | @Override |
| 11035 | public void setCepEnabled(boolean isCepEnabled) { |
| 11036 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11037 | |
| 11038 | final long identity = Binder.clearCallingIdentity(); |
| 11039 | try { |
| 11040 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11041 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11042 | Phone defaultPhone = phone.getImsPhone(); |
| 11043 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11044 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11045 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11046 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11047 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11048 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11049 | + imsPhone.getMsisdn()); |
| 11050 | } |
| 11051 | } |
| 11052 | } finally { |
| 11053 | Binder.restoreCallingIdentity(identity); |
| 11054 | } |
| 11055 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11056 | |
| 11057 | /** |
| 11058 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11059 | * |
| 11060 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11061 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11062 | * before being read. |
| 11063 | */ |
| 11064 | @Override |
| 11065 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11066 | isCompressed) { |
| 11067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11068 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11069 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11070 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11071 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11072 | |
| 11073 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11074 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11075 | Binder.getCallingUserHandle())) { |
| 11076 | if (!isImsAvailableOnDevice()) { |
| 11077 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11078 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11079 | throw new IllegalStateException("IMS not available on device."); |
| 11080 | } |
| 11081 | } else { |
| 11082 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11083 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11084 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11085 | } |
| 11086 | |
| 11087 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11088 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11089 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11090 | } finally { |
| 11091 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11092 | } |
| 11093 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11094 | |
| 11095 | @Override |
| 11096 | public boolean isIccLockEnabled(int subId) { |
| 11097 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11098 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11099 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11100 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11101 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11102 | // Now that all security checks passes, perform the operation as ourselves. |
| 11103 | final long identity = Binder.clearCallingIdentity(); |
| 11104 | try { |
| 11105 | Phone phone = getPhone(subId); |
| 11106 | if (phone != null && phone.getIccCard() != null) { |
| 11107 | return phone.getIccCard().getIccLockEnabled(); |
| 11108 | } else { |
| 11109 | return false; |
| 11110 | } |
| 11111 | } finally { |
| 11112 | Binder.restoreCallingIdentity(identity); |
| 11113 | } |
| 11114 | } |
| 11115 | |
| 11116 | /** |
| 11117 | * Set the ICC pin lock enabled or disabled. |
| 11118 | * |
| 11119 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11120 | * three cases: |
| 11121 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11122 | * successfully. |
| 11123 | * - Positive number and zero for remaining password attempts. |
| 11124 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11125 | * |
| 11126 | */ |
| 11127 | @Override |
| 11128 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11129 | enforceModifyPermission(); |
| 11130 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11131 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11132 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11133 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11134 | Phone phone = getPhone(subId); |
| 11135 | if (phone == null) { |
| 11136 | return 0; |
| 11137 | } |
| 11138 | // Now that all security checks passes, perform the operation as ourselves. |
| 11139 | final long identity = Binder.clearCallingIdentity(); |
| 11140 | try { |
| 11141 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11142 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11143 | return attemptsRemaining; |
| 11144 | |
| 11145 | } catch (Exception e) { |
| 11146 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11147 | } finally { |
| 11148 | Binder.restoreCallingIdentity(identity); |
| 11149 | } |
| 11150 | return 0; |
| 11151 | } |
| 11152 | |
| 11153 | /** |
| 11154 | * Change the ICC password used in ICC pin lock. |
| 11155 | * |
| 11156 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11157 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11158 | * - Positive number and zero for remaining password attempts. |
| 11159 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11160 | * |
| 11161 | */ |
| 11162 | @Override |
| 11163 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11164 | enforceModifyPermission(); |
| 11165 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11166 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11167 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11168 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11169 | Phone phone = getPhone(subId); |
| 11170 | if (phone == null) { |
| 11171 | return 0; |
| 11172 | } |
| 11173 | // Now that all security checks passes, perform the operation as ourselves. |
| 11174 | final long identity = Binder.clearCallingIdentity(); |
| 11175 | try { |
| 11176 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11177 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11178 | return attemptsRemaining; |
| 11179 | |
| 11180 | } catch (Exception e) { |
| 11181 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11182 | } finally { |
| 11183 | Binder.restoreCallingIdentity(identity); |
| 11184 | } |
| 11185 | return 0; |
| 11186 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11187 | |
| 11188 | /** |
| 11189 | * Request for receiving user activity notification |
| 11190 | */ |
| 11191 | @Override |
| 11192 | public void requestUserActivityNotification() { |
| 11193 | if (!mNotifyUserActivity.get() |
| 11194 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11195 | mNotifyUserActivity.set(true); |
| 11196 | } |
| 11197 | } |
| 11198 | |
| 11199 | /** |
| 11200 | * Called when userActivity is signalled in the power manager. |
| 11201 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11202 | */ |
| 11203 | @Override |
| 11204 | public void userActivity() { |
| 11205 | // *************************************** |
| 11206 | // * Inherited from PhoneWindowManager * |
| 11207 | // *************************************** |
| 11208 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11209 | // WITH ITS LOCKS HELD. |
| 11210 | // |
| 11211 | // This code must be VERY careful about the locks |
| 11212 | // it acquires. |
| 11213 | // In fact, the current code acquires way too many, |
| 11214 | // and probably has lurking deadlocks. |
| 11215 | |
| 11216 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11217 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11218 | } |
| 11219 | |
| 11220 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11221 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11222 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11223 | } |
| 11224 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11225 | |
| 11226 | @Override |
| 11227 | public boolean canConnectTo5GInDsdsMode() { |
| 11228 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11229 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11230 | |
| 11231 | @Override |
| 11232 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11233 | String callingFeatureId) { |
| 11234 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11235 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11236 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11237 | } |
| 11238 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11239 | enforceTelephonyFeatureWithException(callingPackage, |
| 11240 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11241 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11242 | Phone phone = getPhone(subId); |
| 11243 | if (phone == null) { |
| 11244 | throw new RuntimeException("phone is not available"); |
| 11245 | } |
| 11246 | // Now that all security checks passes, perform the operation as ourselves. |
| 11247 | final long identity = Binder.clearCallingIdentity(); |
| 11248 | try { |
| 11249 | return phone.getEquivalentHomePlmns(); |
| 11250 | } finally { |
| 11251 | Binder.restoreCallingIdentity(identity); |
| 11252 | } |
| 11253 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11254 | |
| 11255 | @Override |
| 11256 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11257 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11258 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11259 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11260 | "isRadioInterfaceCapabilitySupported"); |
| 11261 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11262 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11263 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11264 | if (radioInterfaceCapabilities == null) { |
| 11265 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11266 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11267 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11268 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11269 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11270 | @Override |
| 11271 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11272 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11273 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11274 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11275 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11276 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11277 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11278 | |
| 11279 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11280 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11281 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11282 | if (DBG) { |
| 11283 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11284 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11285 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11286 | } |
| 11287 | |
| 11288 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11289 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11290 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11291 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11292 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11293 | if (callback != null) { |
| 11294 | try { |
| 11295 | callback.onAuthenticationFailure( |
| 11296 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11297 | } catch (RemoteException exception) { |
| 11298 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11299 | } |
| 11300 | return; |
| 11301 | } |
| 11302 | } |
| 11303 | |
| 11304 | final long token = Binder.clearCallingIdentity(); |
| 11305 | try { |
| 11306 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11307 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11308 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11309 | } finally { |
| 11310 | Binder.restoreCallingIdentity(token); |
| 11311 | } |
| 11312 | } |
| 11313 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11314 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11315 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11316 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11317 | * requested radio power state will actually be set. See {@link |
| 11318 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11319 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11320 | * @param enable {@code true} if trying to turn radio on. |
| 11321 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11322 | * false}. |
| 11323 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11324 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11325 | boolean isPhoneAvailable = false; |
| 11326 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11327 | Phone phone = PhoneFactory.getPhone(i); |
| 11328 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11329 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11330 | isPhoneAvailable = true; |
| 11331 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11332 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11333 | |
| 11334 | // return true if successfully informed the phone object about the thermal radio power |
| 11335 | // request. |
| 11336 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11337 | } |
| 11338 | |
| 11339 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11340 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11341 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11342 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11343 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11344 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11345 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11346 | } |
| 11347 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11348 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11349 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11350 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11351 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11352 | } |
| 11353 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11354 | setDataEnabledForReason( |
| 11355 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11356 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11357 | if (isDataThrottlingSupported) { |
| 11358 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11359 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11360 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11361 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11362 | } else if (thermalMitigationResult |
| 11363 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11364 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11365 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11366 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11367 | } |
| 11368 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11369 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11370 | |
| 11371 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11372 | } |
| 11373 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11374 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11375 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11376 | for (String pckg : context.getResources() |
| 11377 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11378 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11379 | } |
| 11380 | } |
| 11381 | |
| 11382 | return sThermalMitigationAllowlistedPackages; |
| 11383 | } |
| 11384 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11385 | private boolean isAnyPhoneInEmergencyState() { |
| 11386 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11387 | if (tm.isInEmergencyCall()) { |
| 11388 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11389 | return true; |
| 11390 | } |
| 11391 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11392 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11393 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11394 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11395 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11396 | return true; |
| 11397 | } |
| 11398 | } |
| 11399 | |
| 11400 | return false; |
| 11401 | } |
| 11402 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11403 | /** |
| 11404 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11405 | * @param packageName name of package to be allowlisted |
| 11406 | * @param context |
| 11407 | */ |
| 11408 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11409 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11410 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11411 | } |
| 11412 | |
| 11413 | /** |
| 11414 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11415 | * @param packageName name of package to remove from allowlist |
| 11416 | * @param context |
| 11417 | */ |
| 11418 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11419 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11420 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11421 | } |
| 11422 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11423 | /** |
| 11424 | * Thermal mitigation request to control functionalities at modem. |
| 11425 | * |
| 11426 | * @param subId the id of the subscription. |
| 11427 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11428 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11429 | * |
| 11430 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11431 | */ |
| 11432 | @Override |
| 11433 | @ThermalMitigationResult |
| 11434 | public int sendThermalMitigationRequest( |
| 11435 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11436 | ThermalMitigationRequest thermalMitigationRequest, |
| 11437 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11438 | enforceModifyPermission(); |
| 11439 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11440 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11441 | |
| 11442 | enforceTelephonyFeatureWithException(callingPackage, |
| 11443 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11444 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11445 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11446 | .contains(callingPackage)) { |
| 11447 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11448 | + "calling package: " + callingPackage); |
| 11449 | } |
| 11450 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11451 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11452 | final long identity = Binder.clearCallingIdentity(); |
| 11453 | |
| 11454 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11455 | try { |
| 11456 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11457 | switch (thermalMitigationAction) { |
| 11458 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11459 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11460 | handleDataThrottlingRequest(subId, |
| 11461 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11462 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11463 | break; |
| 11464 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11465 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11466 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11467 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11468 | } |
| 11469 | |
| 11470 | // Ensure that radio is on. If not able to power on due to phone being |
| 11471 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11472 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11473 | thermalMitigationResult = |
| 11474 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11475 | break; |
| 11476 | } |
| 11477 | |
| 11478 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11479 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11480 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11481 | break; |
| 11482 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11483 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11484 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11485 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11486 | } |
| 11487 | |
| 11488 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11489 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11490 | Phone phone = getPhone(subId); |
| 11491 | if (phone == null) { |
| 11492 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11493 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11494 | break; |
| 11495 | } |
| 11496 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11497 | TelephonyConnectionService service = |
| 11498 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11499 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11500 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11501 | thermalMitigationResult = |
| 11502 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11503 | break; |
| 11504 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11505 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11506 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11507 | break; |
| 11508 | } |
| 11509 | } else { |
| 11510 | thermalMitigationResult = |
| 11511 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11512 | break; |
| 11513 | } |
| 11514 | |
| 11515 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11516 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11517 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11518 | thermalMitigationResult = |
| 11519 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11520 | break; |
| 11521 | } |
| 11522 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11523 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11524 | break; |
| 11525 | default: |
| 11526 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11527 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11528 | } |
| 11529 | } catch (IllegalArgumentException e) { |
| 11530 | throw e; |
| 11531 | } catch (Exception e) { |
| 11532 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11533 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11534 | } finally { |
| 11535 | Binder.restoreCallingIdentity(identity); |
| 11536 | } |
| 11537 | |
| 11538 | if (DBG) { |
| 11539 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11540 | + thermalMitigationResult); |
| 11541 | } |
| 11542 | |
| 11543 | return thermalMitigationResult; |
| 11544 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11545 | |
| 11546 | /** |
| 11547 | * Set the GbaService Package Name that Telephony will bind to. |
| 11548 | * |
| 11549 | * @param subId The sim that the GbaService is associated with. |
| 11550 | * @param packageName The name of the package to be replaced with. |
| 11551 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11552 | */ |
| 11553 | @Override |
| 11554 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11555 | enforceModifyPermission(); |
| 11556 | |
| 11557 | final long identity = Binder.clearCallingIdentity(); |
| 11558 | try { |
| 11559 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11560 | } finally { |
| 11561 | Binder.restoreCallingIdentity(identity); |
| 11562 | } |
| 11563 | } |
| 11564 | |
| 11565 | /** |
| 11566 | * Return the package name of the currently bound GbaService. |
| 11567 | * |
| 11568 | * @param subId The sim that the GbaService is associated with. |
| 11569 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11570 | */ |
| 11571 | @Override |
| 11572 | public String getBoundGbaService(int subId) { |
| 11573 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11574 | |
| 11575 | final long identity = Binder.clearCallingIdentity(); |
| 11576 | try { |
| 11577 | return getGbaManager(subId).getServicePackage(); |
| 11578 | } finally { |
| 11579 | Binder.restoreCallingIdentity(identity); |
| 11580 | } |
| 11581 | } |
| 11582 | |
| 11583 | /** |
| 11584 | * Set the release time for telephony to unbind GbaService. |
| 11585 | * |
| 11586 | * @param subId The sim that the GbaService is associated with. |
| 11587 | * @param interval The release time to unbind GbaService by millisecond. |
| 11588 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11589 | */ |
| 11590 | @Override |
| 11591 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11592 | enforceModifyPermission(); |
| 11593 | |
| 11594 | final long identity = Binder.clearCallingIdentity(); |
| 11595 | try { |
| 11596 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11597 | } finally { |
| 11598 | Binder.restoreCallingIdentity(identity); |
| 11599 | } |
| 11600 | } |
| 11601 | |
| 11602 | /** |
| 11603 | * Return the release time for telephony to unbind GbaService. |
| 11604 | * |
| 11605 | * @param subId The sim that the GbaService is associated with. |
| 11606 | * @return The release time to unbind GbaService by millisecond. |
| 11607 | */ |
| 11608 | @Override |
| 11609 | public int getGbaReleaseTime(int subId) { |
| 11610 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11611 | |
| 11612 | final long identity = Binder.clearCallingIdentity(); |
| 11613 | try { |
| 11614 | return getGbaManager(subId).getReleaseTime(); |
| 11615 | } finally { |
| 11616 | Binder.restoreCallingIdentity(identity); |
| 11617 | } |
| 11618 | } |
| 11619 | |
| 11620 | private GbaManager getGbaManager(int subId) { |
| 11621 | GbaManager instance = GbaManager.getInstance(subId); |
| 11622 | if (instance == null) { |
| 11623 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11624 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11625 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11626 | } |
| 11627 | return instance; |
| 11628 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11629 | |
| 11630 | /** |
| 11631 | * indicate whether the device and the carrier can support |
| 11632 | * RCS VoLTE single registration. |
| 11633 | */ |
| 11634 | @Override |
| 11635 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11636 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11637 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11638 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11639 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11640 | |
| 11641 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11642 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11643 | } |
| 11644 | |
| 11645 | final long identity = Binder.clearCallingIdentity(); |
| 11646 | try { |
| 11647 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11648 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11649 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11650 | if (isCapable != null) { |
| 11651 | return isCapable; |
| 11652 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11653 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11654 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11655 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11656 | } finally { |
| 11657 | Binder.restoreCallingIdentity(identity); |
| 11658 | } |
| 11659 | } |
| 11660 | |
| 11661 | /** |
| 11662 | * Register RCS provisioning callback. |
| 11663 | */ |
| 11664 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11665 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11666 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11667 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11668 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11669 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11670 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11671 | |
| 11672 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11673 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11674 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11675 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11676 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11677 | Binder.getCallingUserHandle())) { |
| 11678 | if (!isImsAvailableOnDevice()) { |
| 11679 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11680 | "IMS not available on device."); |
| 11681 | } |
| 11682 | } else { |
| 11683 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11684 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11685 | } |
| 11686 | |
| 11687 | final long identity = Binder.clearCallingIdentity(); |
| 11688 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11689 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11690 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11691 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11692 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11693 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11694 | } finally { |
| 11695 | Binder.restoreCallingIdentity(identity); |
| 11696 | } |
| 11697 | } |
| 11698 | |
| 11699 | /** |
| 11700 | * Unregister RCS provisioning callback. |
| 11701 | */ |
| 11702 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11703 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11704 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11705 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11706 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11707 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11708 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11709 | |
| 11710 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11711 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11712 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11713 | |
| 11714 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11715 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11716 | Binder.getCallingUserHandle())) { |
| 11717 | if (!isImsAvailableOnDevice()) { |
| 11718 | // operation failed silently |
| 11719 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11720 | return; |
| 11721 | } |
| 11722 | } else { |
| 11723 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11724 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11725 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11726 | } |
| 11727 | |
| 11728 | final long identity = Binder.clearCallingIdentity(); |
| 11729 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11730 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11731 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11732 | } finally { |
| 11733 | Binder.restoreCallingIdentity(identity); |
| 11734 | } |
| 11735 | } |
| 11736 | |
| 11737 | /** |
| 11738 | * trigger RCS reconfiguration. |
| 11739 | */ |
| 11740 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11741 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11742 | "triggerRcsReconfiguration", |
| 11743 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11744 | |
| 11745 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11746 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11747 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11748 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11749 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11750 | Binder.getCallingUserHandle())) { |
| 11751 | if (!isImsAvailableOnDevice()) { |
| 11752 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11753 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11754 | throw new IllegalStateException("IMS not available on device."); |
| 11755 | } |
| 11756 | } else { |
| 11757 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11758 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11759 | } |
| 11760 | |
| 11761 | final long identity = Binder.clearCallingIdentity(); |
| 11762 | try { |
| 11763 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11764 | } finally { |
| 11765 | Binder.restoreCallingIdentity(identity); |
| 11766 | } |
| 11767 | } |
| 11768 | |
| 11769 | /** |
| 11770 | * Provide the client configuration parameters of the RCS application. |
| 11771 | */ |
| 11772 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11773 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11774 | "setRcsClientConfiguration", |
| 11775 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11776 | |
| 11777 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11778 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11779 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11780 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11781 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11782 | Binder.getCallingUserHandle())) { |
| 11783 | if (!isImsAvailableOnDevice()) { |
| 11784 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11785 | "IMS not available on device."); |
| 11786 | } |
| 11787 | } else { |
| 11788 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11789 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11790 | } |
| 11791 | |
| 11792 | final long identity = Binder.clearCallingIdentity(); |
| 11793 | |
| 11794 | try { |
| 11795 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11796 | if (configBinder == null) { |
| 11797 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11798 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11799 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11800 | } else { |
| 11801 | configBinder.setRcsClientConfiguration(rcc); |
| 11802 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11803 | |
| 11804 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11805 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11806 | } catch (RemoteException e) { |
| 11807 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11808 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11809 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11810 | } finally { |
| 11811 | Binder.restoreCallingIdentity(identity); |
| 11812 | } |
| 11813 | } |
| 11814 | |
| 11815 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11816 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11817 | */ |
| 11818 | @Override |
| 11819 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11820 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11821 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11822 | |
| 11823 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11824 | } |
| 11825 | |
| 11826 | /** |
| 11827 | * Gets the test mode for RCS VoLTE single registration. |
| 11828 | */ |
| 11829 | @Override |
| 11830 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11831 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11832 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11833 | |
| 11834 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11835 | } |
| 11836 | |
| 11837 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11838 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11839 | */ |
| 11840 | @Override |
| 11841 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11842 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11843 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11844 | enforceModifyPermission(); |
| 11845 | |
| 11846 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11847 | : Boolean.parseBoolean(enabledStr); |
| 11848 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11849 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11850 | } |
| 11851 | |
| 11852 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11853 | * Sends a device to device communication message. Only usable via shell. |
| 11854 | * @param message message to send. |
| 11855 | * @param value message value. |
| 11856 | */ |
| 11857 | @Override |
| 11858 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11859 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11860 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11861 | enforceModifyPermission(); |
| 11862 | |
| 11863 | final long identity = Binder.clearCallingIdentity(); |
| 11864 | try { |
| 11865 | TelephonyConnectionService service = |
| 11866 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11867 | if (service == null) { |
| 11868 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11869 | return; |
| 11870 | } |
| 11871 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11872 | } finally { |
| 11873 | Binder.restoreCallingIdentity(identity); |
| 11874 | } |
| 11875 | } |
| 11876 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11877 | /** |
| 11878 | * Sets the specified device to device transport active. |
| 11879 | * @param transport The transport to set active. |
| 11880 | */ |
| 11881 | @Override |
| 11882 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11883 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11884 | "setActiveDeviceToDeviceTransport"); |
| 11885 | enforceModifyPermission(); |
| 11886 | |
| 11887 | final long identity = Binder.clearCallingIdentity(); |
| 11888 | try { |
| 11889 | TelephonyConnectionService service = |
| 11890 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11891 | if (service == null) { |
| 11892 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11893 | return; |
| 11894 | } |
| 11895 | service.setActiveDeviceToDeviceTransport(transport); |
| 11896 | } finally { |
| 11897 | Binder.restoreCallingIdentity(identity); |
| 11898 | } |
| 11899 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11900 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11901 | @Override |
| 11902 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11903 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11904 | "setDeviceToDeviceForceEnabled"); |
| 11905 | |
| 11906 | final long identity = Binder.clearCallingIdentity(); |
| 11907 | try { |
| 11908 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11909 | p -> { |
| 11910 | Phone thePhone = p.getImsPhone(); |
| 11911 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11912 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11913 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11914 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11915 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11916 | (ImsPhoneCallTracker) tracker; |
| 11917 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11918 | } |
| 11919 | } |
| 11920 | } |
| 11921 | ); |
| 11922 | } finally { |
| 11923 | Binder.restoreCallingIdentity(identity); |
| 11924 | } |
| 11925 | } |
| 11926 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11927 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11928 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11929 | */ |
| 11930 | @Override |
| 11931 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11932 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11933 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11934 | } |
| 11935 | |
| 11936 | /** |
| 11937 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11938 | */ |
| 11939 | @Override |
| 11940 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11941 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11942 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11943 | enforceModifyPermission(); |
| 11944 | |
| 11945 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11946 | : Boolean.parseBoolean(enabledStr); |
| 11947 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11948 | subId, enabled); |
| 11949 | } |
| 11950 | |
| 11951 | /** |
| 11952 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11953 | */ |
| 11954 | @Override |
| 11955 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11956 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11957 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11958 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11959 | |
| 11960 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11961 | * Overrides the ims feature validation result |
| 11962 | */ |
| 11963 | @Override |
| 11964 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11965 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11966 | "setImsFeatureValidationOverride"); |
| 11967 | |
| 11968 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11969 | : Boolean.parseBoolean(enabledStr); |
| 11970 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11971 | subId, enabled); |
| 11972 | } |
| 11973 | |
| 11974 | /** |
| 11975 | * Gets the ims feature validation override value |
| 11976 | */ |
| 11977 | @Override |
| 11978 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11979 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11980 | "getImsFeatureValidationOverride"); |
| 11981 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11982 | } |
| 11983 | |
| 11984 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11985 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11986 | * their mobile plan. |
| 11987 | */ |
| 11988 | @Override |
| 11989 | public String getMobileProvisioningUrl() { |
| 11990 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11991 | final long identity = Binder.clearCallingIdentity(); |
| 11992 | try { |
| 11993 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11994 | } finally { |
| 11995 | Binder.restoreCallingIdentity(identity); |
| 11996 | } |
| 11997 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11998 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11999 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12000 | * Get the EAB contact from the EAB database. |
| 12001 | */ |
| 12002 | @Override |
| 12003 | public String getContactFromEab(String contact) { |
| 12004 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12005 | enforceModifyPermission(); |
| 12006 | final long identity = Binder.clearCallingIdentity(); |
| 12007 | try { |
| 12008 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12009 | } finally { |
| 12010 | Binder.restoreCallingIdentity(identity); |
| 12011 | } |
| 12012 | } |
| 12013 | |
| 12014 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12015 | * Get the EAB capability from the EAB database. |
| 12016 | */ |
| 12017 | @Override |
| 12018 | public String getCapabilityFromEab(String contact) { |
| 12019 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12020 | enforceModifyPermission(); |
| 12021 | final long identity = Binder.clearCallingIdentity(); |
| 12022 | try { |
| 12023 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12024 | } finally { |
| 12025 | Binder.restoreCallingIdentity(identity); |
| 12026 | } |
| 12027 | } |
| 12028 | |
| 12029 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12030 | * Remove the EAB contacts from the EAB database. |
| 12031 | */ |
| 12032 | @Override |
| 12033 | public int removeContactFromEab(int subId, String contacts) { |
| 12034 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12035 | enforceModifyPermission(); |
| 12036 | final long identity = Binder.clearCallingIdentity(); |
| 12037 | try { |
| 12038 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12039 | } finally { |
| 12040 | Binder.restoreCallingIdentity(identity); |
| 12041 | } |
| 12042 | } |
| 12043 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12044 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12045 | public boolean getDeviceUceEnabled() { |
| 12046 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12047 | final long identity = Binder.clearCallingIdentity(); |
| 12048 | try { |
| 12049 | return mApp.getDeviceUceEnabled(); |
| 12050 | } finally { |
| 12051 | Binder.restoreCallingIdentity(identity); |
| 12052 | } |
| 12053 | } |
| 12054 | |
| 12055 | @Override |
| 12056 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12057 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12058 | final long identity = Binder.clearCallingIdentity(); |
| 12059 | try { |
| 12060 | mApp.setDeviceUceEnabled(isEnabled); |
| 12061 | } finally { |
| 12062 | Binder.restoreCallingIdentity(identity); |
| 12063 | } |
| 12064 | } |
| 12065 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12066 | /** |
| 12067 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12068 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12069 | */ |
| 12070 | // Used for SHELL command only right now. |
| 12071 | @Override |
| 12072 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12073 | List<String> featureTags) { |
| 12074 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12075 | "addUceRegistrationOverrideShell"); |
| 12076 | final long identity = Binder.clearCallingIdentity(); |
| 12077 | try { |
| 12078 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12079 | new ArraySet<>(featureTags)); |
| 12080 | } catch (ImsException e) { |
| 12081 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12082 | } finally { |
| 12083 | Binder.restoreCallingIdentity(identity); |
| 12084 | } |
| 12085 | } |
| 12086 | |
| 12087 | /** |
| 12088 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12089 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12090 | */ |
| 12091 | // Used for SHELL command only right now. |
| 12092 | @Override |
| 12093 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12094 | List<String> featureTags) { |
| 12095 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12096 | "removeUceRegistrationOverrideShell"); |
| 12097 | final long identity = Binder.clearCallingIdentity(); |
| 12098 | try { |
| 12099 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12100 | new ArraySet<>(featureTags)); |
| 12101 | } catch (ImsException e) { |
| 12102 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12103 | } finally { |
| 12104 | Binder.restoreCallingIdentity(identity); |
| 12105 | } |
| 12106 | } |
| 12107 | |
| 12108 | /** |
| 12109 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12110 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12111 | */ |
| 12112 | // Used for SHELL command only right now. |
| 12113 | @Override |
| 12114 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12115 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12116 | "clearUceRegistrationOverrideShell"); |
| 12117 | final long identity = Binder.clearCallingIdentity(); |
| 12118 | try { |
| 12119 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12120 | } catch (ImsException e) { |
| 12121 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12122 | } finally { |
| 12123 | Binder.restoreCallingIdentity(identity); |
| 12124 | } |
| 12125 | } |
| 12126 | |
| 12127 | /** |
| 12128 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12129 | */ |
| 12130 | // Used for SHELL command only right now. |
| 12131 | @Override |
| 12132 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12133 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12134 | "getLatestRcsContactUceCapabilityShell"); |
| 12135 | final long identity = Binder.clearCallingIdentity(); |
| 12136 | try { |
| 12137 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12138 | } catch (ImsException e) { |
| 12139 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12140 | } finally { |
| 12141 | Binder.restoreCallingIdentity(identity); |
| 12142 | } |
| 12143 | } |
| 12144 | |
| 12145 | /** |
| 12146 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12147 | * device does not have an active PUBLISH. |
| 12148 | */ |
| 12149 | // Used for SHELL command only right now. |
| 12150 | @Override |
| 12151 | public String getLastUcePidfXmlShell(int subId) { |
| 12152 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12153 | final long identity = Binder.clearCallingIdentity(); |
| 12154 | try { |
| 12155 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12156 | } catch (ImsException e) { |
| 12157 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12158 | } finally { |
| 12159 | Binder.restoreCallingIdentity(identity); |
| 12160 | } |
| 12161 | } |
| 12162 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12163 | /** |
| 12164 | * Remove UCE requests cannot be sent to the network status. |
| 12165 | */ |
| 12166 | // Used for SHELL command only right now. |
| 12167 | @Override |
| 12168 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12169 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12170 | final long identity = Binder.clearCallingIdentity(); |
| 12171 | try { |
| 12172 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12173 | } catch (ImsException e) { |
| 12174 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12175 | } finally { |
| 12176 | Binder.restoreCallingIdentity(identity); |
| 12177 | } |
| 12178 | } |
| 12179 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12180 | /** |
| 12181 | * Remove UCE requests cannot be sent to the network status. |
| 12182 | */ |
| 12183 | // Used for SHELL command only. |
| 12184 | @Override |
| 12185 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12186 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12187 | final long identity = Binder.clearCallingIdentity(); |
| 12188 | try { |
| 12189 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12190 | } catch (ImsException e) { |
| 12191 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12192 | } finally { |
| 12193 | Binder.restoreCallingIdentity(identity); |
| 12194 | } |
| 12195 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12196 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12197 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12198 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12199 | String callingPackage) { |
| 12200 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12201 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12202 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12203 | enforceTelephonyFeatureWithException(callingPackage, |
| 12204 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12205 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12206 | final int callingUid = Binder.getCallingUid(); |
| 12207 | // Verify that tha callingPackage belongs to the calling UID |
| 12208 | mApp.getSystemService(AppOpsManager.class) |
| 12209 | .checkPackage(callingUid, callingPackage); |
| 12210 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12211 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12212 | |
| 12213 | final long identity = Binder.clearCallingIdentity(); |
| 12214 | try { |
| 12215 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12216 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12217 | |
| 12218 | if (result instanceof IllegalStateException) { |
| 12219 | throw (IllegalStateException) result; |
| 12220 | } |
| 12221 | } finally { |
| 12222 | Binder.restoreCallingIdentity(identity); |
| 12223 | } |
| 12224 | } |
| 12225 | |
| 12226 | @Override |
| 12227 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12228 | String callingPackage) { |
| 12229 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12230 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12231 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12232 | enforceTelephonyFeatureWithException(callingPackage, |
| 12233 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12234 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12235 | final int callingUid = Binder.getCallingUid(); |
| 12236 | // Verify that tha callingPackage belongs to the calling UID |
| 12237 | mApp.getSystemService(AppOpsManager.class) |
| 12238 | .checkPackage(callingUid, callingPackage); |
| 12239 | |
| 12240 | final long identity = Binder.clearCallingIdentity(); |
| 12241 | try { |
| 12242 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12243 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12244 | |
| 12245 | if (result instanceof IllegalStateException) { |
| 12246 | throw (IllegalStateException) result; |
| 12247 | } |
| 12248 | } finally { |
| 12249 | Binder.restoreCallingIdentity(identity); |
| 12250 | } |
| 12251 | } |
| 12252 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12253 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12254 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12255 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 12256 | // phone/system process do not have further restriction on request |
| 12257 | return; |
| 12258 | } |
| 12259 | |
| 12260 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12261 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12262 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12263 | context.enforceCallingOrSelfPermission( |
| 12264 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12265 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12266 | } |
| 12267 | |
| 12268 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12269 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12270 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12271 | || info.isEnabled()) { |
| 12272 | throw new IllegalArgumentException( |
| 12273 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12274 | } |
| 12275 | |
| 12276 | // Thresholds length for each RAN need in range. This has been validated in |
| 12277 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12278 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12279 | final int[] thresholds = info.getThresholds(); |
| 12280 | Objects.requireNonNull(thresholds); |
| 12281 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12282 | || thresholds.length |
| 12283 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12284 | throw new IllegalArgumentException( |
| 12285 | "thresholds length is out of range: " + thresholds.length); |
| 12286 | } |
| 12287 | } |
| 12288 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12289 | |
| 12290 | /** |
| 12291 | * Gets the current phone capability. |
| 12292 | * |
| 12293 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12294 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12295 | * It's used to evaluate possible phone config change, for example from single |
| 12296 | * SIM device to multi-SIM device. |
| 12297 | */ |
| 12298 | @Override |
| 12299 | public PhoneCapability getPhoneCapability() { |
| 12300 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12301 | |
| 12302 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12303 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12304 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12305 | final long identity = Binder.clearCallingIdentity(); |
| 12306 | try { |
| 12307 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12308 | } finally { |
| 12309 | Binder.restoreCallingIdentity(identity); |
| 12310 | } |
| 12311 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12312 | |
| 12313 | /** |
| 12314 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12315 | * required to be done shortly after the API is invoked. |
| 12316 | */ |
| 12317 | @Override |
| 12318 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12319 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12320 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12321 | enforceRebootPermission(); |
| 12322 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12323 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12324 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12325 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12326 | final long identity = Binder.clearCallingIdentity(); |
| 12327 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12328 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12329 | } finally { |
| 12330 | Binder.restoreCallingIdentity(identity); |
| 12331 | } |
| 12332 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12333 | |
| 12334 | /** |
| 12335 | * Request to get the current slicing configuration including URSP rules and |
| 12336 | * NSSAIs (configured, allowed and rejected). |
| 12337 | * |
| 12338 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12339 | */ |
| 12340 | @Override |
| 12341 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12342 | TelephonyPermissions |
| 12343 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12344 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12345 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12346 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12347 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12348 | "getSlicingConfig"); |
| 12349 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12350 | final long identity = Binder.clearCallingIdentity(); |
| 12351 | try { |
| 12352 | Phone phone = getDefaultPhone(); |
| 12353 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12354 | } finally { |
| 12355 | Binder.restoreCallingIdentity(identity); |
| 12356 | } |
| 12357 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12358 | |
| 12359 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12360 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12361 | * |
| 12362 | * @param capability The premium capability to check. |
| 12363 | * @param subId The subId to check the premium capability for. |
| 12364 | * |
| 12365 | * @return Whether the given premium capability is available to purchase. |
| 12366 | */ |
| 12367 | @Override |
| 12368 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12369 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12370 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12371 | log("Premium capability " |
| 12372 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12373 | + " is not available for purchase due to missing permissions."); |
| 12374 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12375 | + "permission READ_BASIC_PHONE_STATE."); |
| 12376 | } |
| 12377 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12378 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12379 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12380 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12381 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12382 | if (phone == null) { |
| 12383 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12384 | return false; |
| 12385 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12386 | final long identity = Binder.clearCallingIdentity(); |
| 12387 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12388 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12389 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12390 | } finally { |
| 12391 | Binder.restoreCallingIdentity(identity); |
| 12392 | } |
| 12393 | } |
| 12394 | |
| 12395 | /** |
| 12396 | * Purchase the given premium capability from the carrier. |
| 12397 | * |
| 12398 | * @param capability The premium capability to purchase. |
| 12399 | * @param callback The result of the purchase request. |
| 12400 | * @param subId The subId to purchase the premium capability for. |
| 12401 | */ |
| 12402 | @Override |
| 12403 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12404 | log("purchasePremiumCapability: capability=" |
| 12405 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12406 | + getCurrentPackageName()); |
| 12407 | |
| 12408 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12409 | mApp, "purchasePremiumCapability")) { |
| 12410 | log("purchasePremiumCapability " |
| 12411 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12412 | + " failed due to missing permissions."); |
| 12413 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12414 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12415 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12416 | mApp, "purchasePremiumCapability")) { |
| 12417 | log("purchasePremiumCapability " |
| 12418 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12419 | + " failed due to missing permissions."); |
| 12420 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12421 | } |
| 12422 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12423 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12424 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12425 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12426 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12427 | if (phone == null) { |
| 12428 | try { |
| 12429 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12430 | callback.accept(result); |
| 12431 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12432 | } catch (RemoteException e) { |
| 12433 | String logStr = "Purchase premium capability " |
| 12434 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12435 | + " failed due to RemoteException handling null phone: " + e; |
| 12436 | if (DBG) log(logStr); |
| 12437 | AnomalyReporter.reportAnomaly( |
| 12438 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12439 | } |
| 12440 | return; |
| 12441 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12442 | |
| 12443 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12444 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12445 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12446 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12447 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12448 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12449 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12450 | |
| 12451 | boolean isVisible = false; |
| 12452 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12453 | if (am != null) { |
| 12454 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12455 | if (processes != null) { |
| 12456 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12457 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12458 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12459 | if (process.processName.equals(callingProcess) && process.importance |
| 12460 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12461 | isVisible = true; |
| 12462 | break; |
| 12463 | } |
| 12464 | } |
| 12465 | } |
| 12466 | } |
| 12467 | |
| 12468 | if (!isVisible) { |
| 12469 | try { |
| 12470 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12471 | callback.accept(result); |
| 12472 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12473 | } catch (RemoteException e) { |
| 12474 | String logStr = "Purchase premium capability " |
| 12475 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12476 | + " failed due to RemoteException handling background application: " + e; |
| 12477 | if (DBG) log(logStr); |
| 12478 | AnomalyReporter.reportAnomaly( |
| 12479 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12480 | } |
| 12481 | return; |
| 12482 | } |
| 12483 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12484 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12485 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12486 | } |
| 12487 | |
| 12488 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12489 | * Register an IMS connection state callback |
| 12490 | */ |
| 12491 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12492 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12493 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12494 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12495 | // ImsMmTelManager |
| 12496 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12497 | TelephonyPermissions |
| 12498 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12499 | mApp, subId, "registerImsStateCallback"); |
| 12500 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12501 | // ImsRcsManager or SipDelegateManager |
| 12502 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12503 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12504 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12505 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12506 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12507 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12508 | } |
| 12509 | |
| 12510 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12511 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12512 | "IMS not available on device."); |
| 12513 | } |
| 12514 | |
| 12515 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12516 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12517 | } |
| 12518 | |
| 12519 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12520 | if (controller == null) { |
| 12521 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12522 | "IMS not available on device."); |
| 12523 | } |
| 12524 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12525 | if (callingPackage == null) { |
| 12526 | callingPackage = getCurrentPackageName(); |
| 12527 | } |
| 12528 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12529 | final long token = Binder.clearCallingIdentity(); |
| 12530 | try { |
| 12531 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12532 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12533 | } catch (ImsException e) { |
| 12534 | throw new ServiceSpecificException(e.getCode()); |
| 12535 | } finally { |
| 12536 | Binder.restoreCallingIdentity(token); |
| 12537 | } |
| 12538 | } |
| 12539 | |
| 12540 | /** |
| 12541 | * Unregister an IMS connection state callback |
| 12542 | */ |
| 12543 | @Override |
| 12544 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12545 | final long token = Binder.clearCallingIdentity(); |
| 12546 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12547 | if (controller == null) { |
| 12548 | return; |
| 12549 | } |
| 12550 | try { |
| 12551 | controller.unregisterImsStateCallback(cb); |
| 12552 | } finally { |
| 12553 | Binder.restoreCallingIdentity(token); |
| 12554 | } |
| 12555 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12556 | |
| 12557 | /** |
| 12558 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12559 | * |
| 12560 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 12561 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 12562 | * SecurityException. |
| 12563 | * If there is current registered network this value will be same as the registered cell |
| 12564 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12565 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12566 | * it will be cleared and null will be returned. |
| 12567 | * |
| 12568 | */ |
| 12569 | @Override |
| 12570 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12571 | String callingFeatureId) { |
| 12572 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12573 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12574 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12575 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12576 | .setCallingPackage(callingPackage) |
| 12577 | .setCallingFeatureId(callingFeatureId) |
| 12578 | .setCallingPid(Binder.getCallingPid()) |
| 12579 | .setCallingUid(Binder.getCallingUid()) |
| 12580 | .setMethod("getLastKnownCellIdentity") |
| 12581 | .setLogAsInfo(true) |
| 12582 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12583 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12584 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12585 | .build()); |
| 12586 | |
| 12587 | boolean hasFinePermission = |
| 12588 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12589 | if (!hasFinePermission |
| 12590 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12591 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12592 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12593 | } |
| 12594 | |
| 12595 | final long identity = Binder.clearCallingIdentity(); |
| 12596 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12597 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12598 | if (sst == null) return null; |
| 12599 | return sst.getLastKnownCellIdentity(); |
| 12600 | } finally { |
| 12601 | Binder.restoreCallingIdentity(identity); |
| 12602 | } |
| 12603 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12604 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12605 | /** |
| 12606 | * Sets the modem service class Name that Telephony will bind to. |
| 12607 | * |
| 12608 | * @param serviceName The class name of the modem service. |
| 12609 | * @return true if the operation is succeed, otherwise false. |
| 12610 | */ |
| 12611 | public boolean setModemService(String serviceName) { |
| 12612 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12613 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12615 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12616 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12617 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12618 | } |
| 12619 | |
| 12620 | /** |
| 12621 | * Return the class name of the currently bounded modem service. |
| 12622 | * |
| 12623 | * @return the class name of the modem service. |
| 12624 | */ |
| 12625 | public String getModemService() { |
| 12626 | String result; |
| 12627 | Log.d(LOG_TAG, "getModemService"); |
| 12628 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12629 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12630 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12631 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12632 | "getModemService"); |
| 12633 | result = mPhoneConfigurationManager.getModemService(); |
| 12634 | Log.d(LOG_TAG, "result = " + result); |
| 12635 | return result; |
| 12636 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12637 | |
| 12638 | @Override |
| 12639 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12640 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12641 | mApp.enforceCallingOrSelfPermission( |
| 12642 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12643 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12644 | |
| 12645 | final long identity = Binder.clearCallingIdentity(); |
| 12646 | try { |
| 12647 | Phone phone = getPhone(subId); |
| 12648 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12649 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12650 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12651 | phone.setVoiceServiceStateOverride(hasService); |
| 12652 | } finally { |
| 12653 | Binder.restoreCallingIdentity(identity); |
| 12654 | } |
| 12655 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12656 | |
| 12657 | /** |
| 12658 | * set removable eSIM as default eUICC. |
| 12659 | * |
| 12660 | * @hide |
| 12661 | */ |
| 12662 | @Override |
| 12663 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12664 | enforceModifyPermission(); |
| 12665 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12666 | |
| 12667 | final long identity = Binder.clearCallingIdentity(); |
| 12668 | try { |
| 12669 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12670 | } finally { |
| 12671 | Binder.restoreCallingIdentity(identity); |
| 12672 | } |
| 12673 | } |
| 12674 | |
| 12675 | /** |
| 12676 | * Returns whether the removable eSIM is default eUICC or not. |
| 12677 | * |
| 12678 | * @hide |
| 12679 | */ |
| 12680 | @Override |
| 12681 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12682 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12683 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12684 | |
| 12685 | final long identity = Binder.clearCallingIdentity(); |
| 12686 | try { |
| 12687 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12688 | } finally { |
| 12689 | Binder.restoreCallingIdentity(identity); |
| 12690 | } |
| 12691 | } |
| 12692 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12693 | /** |
| 12694 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12695 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12696 | * application currently configured for this user. |
| 12697 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12698 | * {@code null} if the functionality is not supported. |
| 12699 | * @hide |
| 12700 | */ |
| 12701 | @Override |
| 12702 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12703 | boolean updateIfNeeded) { |
| 12704 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12705 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12706 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12707 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12708 | "getDefaultRespondViaMessageApplication"); |
| 12709 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12710 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12711 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12712 | UserHandle userHandle = null; |
| 12713 | final long identity = Binder.clearCallingIdentity(); |
| 12714 | try { |
| 12715 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12716 | } finally { |
| 12717 | Binder.restoreCallingIdentity(identity); |
| 12718 | } |
| 12719 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12720 | updateIfNeeded, userHandle); |
| 12721 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12722 | |
| 12723 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12724 | * Set whether the device is able to connect with null ciphering or integrity |
| 12725 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12726 | * and all new subscriptions after this. |
| 12727 | * |
| 12728 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12729 | * @hide |
| 12730 | */ |
| 12731 | @Override |
| 12732 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12733 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12734 | enforceModifyPermission(); |
| 12735 | checkForNullCipherAndIntegritySupport(); |
| 12736 | |
| 12737 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12738 | // for listening to these preference changes and applying them immediately. |
| 12739 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12740 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12741 | editor.apply(); |
| 12742 | |
| 12743 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12744 | phone.handleNullCipherEnabledChange(); |
| 12745 | } |
| 12746 | } |
| 12747 | |
| 12748 | |
| 12749 | /** |
| 12750 | * Get whether the device is able to connect with null ciphering or integrity |
| 12751 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12752 | * the state of the radio. |
| 12753 | * |
| 12754 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12755 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12756 | * version for this feature. |
| 12757 | * @hide |
| 12758 | */ |
| 12759 | @Override |
| 12760 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12761 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12762 | enforceReadPermission(); |
| 12763 | checkForNullCipherAndIntegritySupport(); |
| 12764 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12765 | } |
| 12766 | |
| 12767 | private void checkForNullCipherAndIntegritySupport() { |
| 12768 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12769 | throw new UnsupportedOperationException( |
| 12770 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12771 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12772 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12773 | throw new UnsupportedOperationException( |
| 12774 | "Null cipher and integrity operations unsupported by modem"); |
| 12775 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12776 | } |
| 12777 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12778 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12779 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12780 | throw new UnsupportedOperationException( |
| 12781 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12782 | + "above"); |
| 12783 | } |
| 12784 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12785 | throw new UnsupportedOperationException( |
| 12786 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12787 | } |
| 12788 | } |
| 12789 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12790 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12791 | * Get the SIM state for the slot index. |
| 12792 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12793 | * |
| 12794 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12795 | */ |
| 12796 | @Override |
| 12797 | @SimState |
| 12798 | public int getSimStateForSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12799 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12800 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12801 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12802 | IccCardConstants.State simState; |
| 12803 | if (slotIndex < 0) { |
| 12804 | simState = IccCardConstants.State.UNKNOWN; |
| 12805 | } else { |
| 12806 | Phone phone = null; |
| 12807 | try { |
| 12808 | phone = PhoneFactory.getPhone(slotIndex); |
| 12809 | } catch (IllegalStateException e) { |
| 12810 | // ignore |
| 12811 | } |
| 12812 | if (phone == null) { |
| 12813 | simState = IccCardConstants.State.UNKNOWN; |
| 12814 | } else { |
| 12815 | IccCard icc = phone.getIccCard(); |
| 12816 | if (icc == null) { |
| 12817 | simState = IccCardConstants.State.UNKNOWN; |
| 12818 | } else { |
| 12819 | simState = icc.getState(); |
| 12820 | } |
| 12821 | } |
| 12822 | } |
| 12823 | return simState.ordinal(); |
| 12824 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12825 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12826 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12827 | boolean enableLogcat, |
| 12828 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12829 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12830 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 12831 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 12832 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 12833 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 12834 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 12835 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 12836 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 12837 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12838 | Executors.newCachedThreadPool(), db, |
| 12839 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 12840 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12841 | } |
| 12842 | |
| 12843 | /** |
| 12844 | * Request telephony to persist state for debugging emergency call failures. |
| 12845 | * |
| 12846 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 12847 | * @param enableLogcat whether to collect logcat output |
| 12848 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12849 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12850 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12851 | */ |
| 12852 | @Override |
| 12853 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12854 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12855 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12856 | boolean enableTelephonyDump) { |
| 12857 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12858 | "persistEmergencyCallDiagnosticData"); |
| 12859 | final long identity = Binder.clearCallingIdentity(); |
| 12860 | try { |
| 12861 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12862 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12863 | |
| 12864 | } finally { |
| 12865 | Binder.restoreCallingIdentity(identity); |
| 12866 | } |
| 12867 | } |
| 12868 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12869 | /** |
| 12870 | * Get current cell broadcast ranges. |
| 12871 | */ |
| 12872 | @Override |
| 12873 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12874 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12875 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12876 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12877 | |
| 12878 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12879 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 12880 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12881 | final long identity = Binder.clearCallingIdentity(); |
| 12882 | try { |
| 12883 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12884 | } finally { |
| 12885 | Binder.restoreCallingIdentity(identity); |
| 12886 | } |
| 12887 | } |
| 12888 | |
| 12889 | /** |
| 12890 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12891 | * |
| 12892 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12893 | */ |
| 12894 | @Override |
| 12895 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12896 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12897 | @Nullable IIntegerConsumer callback) { |
| 12898 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12899 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12900 | |
| 12901 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12902 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 12903 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12904 | final long identity = Binder.clearCallingIdentity(); |
| 12905 | try { |
| 12906 | Phone phone = getPhoneFromSubId(subId); |
| 12907 | if (DBG) { |
| 12908 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12909 | } |
| 12910 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12911 | if (callback != null) { |
| 12912 | try { |
| 12913 | callback.accept(result); |
| 12914 | } catch (RemoteException e) { |
| 12915 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12916 | } |
| 12917 | } |
| 12918 | }); |
| 12919 | } finally { |
| 12920 | Binder.restoreCallingIdentity(identity); |
| 12921 | } |
| 12922 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12923 | |
| 12924 | /** |
| 12925 | * Returns whether the device supports the domain selection service. |
| 12926 | * |
| 12927 | * @return {@code true} if the device supports the domain selection service. |
| 12928 | */ |
| 12929 | @Override |
| 12930 | public boolean isDomainSelectionSupported() { |
| 12931 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12932 | "isDomainSelectionSupported"); |
| 12933 | |
| 12934 | final long identity = Binder.clearCallingIdentity(); |
| 12935 | try { |
| 12936 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12937 | } finally { |
| 12938 | Binder.restoreCallingIdentity(identity); |
| 12939 | } |
| 12940 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12941 | |
| 12942 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12943 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12944 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12945 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12946 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12947 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12948 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12949 | * {@code false} to disable. |
| 12950 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12951 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12952 | * |
| 12953 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12954 | */ |
| 12955 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12956 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12957 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12958 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12959 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12960 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12961 | } |
| 12962 | |
| 12963 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12964 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12965 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12966 | * @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] | 12967 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12968 | * 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] | 12969 | * |
| 12970 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12971 | */ |
| 12972 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12973 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12974 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12975 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12976 | } |
| 12977 | |
| 12978 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12979 | * Request to get whether the satellite service demo mode is enabled. |
| 12980 | * |
| 12981 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12982 | * is enabled for. |
| 12983 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12984 | * if the request is successful or an error code if the request failed. |
| 12985 | * |
| 12986 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12987 | */ |
| 12988 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12989 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12990 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12991 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12992 | } |
| 12993 | |
| 12994 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12995 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12996 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12997 | * @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] | 12998 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12999 | * 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] | 13000 | */ |
| 13001 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13002 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13003 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13004 | } |
| 13005 | |
| 13006 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13007 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13008 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13009 | * @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] | 13010 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13011 | * 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] | 13012 | * |
| 13013 | * @throws SecurityException if the caller doesn't have required permission. |
| 13014 | */ |
| 13015 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13016 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13017 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13018 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13019 | } |
| 13020 | |
| 13021 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13022 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13023 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13024 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13025 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13026 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13027 | * @param resultCallback The callback to get the result of the request. |
| 13028 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13029 | * |
| 13030 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13031 | */ |
| 13032 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13033 | public void startSatelliteTransmissionUpdates(int subId, |
| 13034 | @NonNull IIntegerConsumer resultCallback, |
| 13035 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13036 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13037 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13038 | } |
| 13039 | |
| 13040 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13041 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13042 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13043 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13044 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13045 | * @param resultCallback The callback to get the result of the request. |
| 13046 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13047 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13048 | * |
| 13049 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13050 | */ |
| 13051 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13052 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13053 | @NonNull IIntegerConsumer resultCallback, |
| 13054 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13055 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13056 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13057 | } |
| 13058 | |
| 13059 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13060 | * Register the subscription with a satellite provider. |
| 13061 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13062 | * |
| 13063 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13064 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13065 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13066 | * @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] | 13067 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13068 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13069 | * @return The signal transport used by the caller to cancel the provision request, |
| 13070 | * or {@code null} if the request failed. |
| 13071 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13072 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13073 | */ |
| 13074 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13075 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13076 | @NonNull String token, @NonNull byte[] provisionData, |
| 13077 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13078 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13079 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13080 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13081 | } |
| 13082 | |
| 13083 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13084 | * Unregister the device/subscription with the satellite provider. |
| 13085 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13086 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13087 | * should report as deprovisioned. |
| 13088 | * |
| 13089 | * @param subId The subId of the subscription to be deprovisioned. |
| 13090 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13091 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13092 | * |
| 13093 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13094 | */ |
| 13095 | @Override |
| 13096 | public void deprovisionSatelliteService(int subId, |
| 13097 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13098 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13099 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13100 | } |
| 13101 | |
| 13102 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13103 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13104 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13105 | * @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] | 13106 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13107 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13108 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13109 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13110 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13111 | */ |
| 13112 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13113 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13114 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13115 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13116 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13117 | } |
| 13118 | |
| 13119 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13120 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13121 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13122 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13123 | * @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] | 13124 | * @param callback The callback that was passed to |
| 13125 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13126 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13127 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13128 | */ |
| 13129 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13130 | public void unregisterForSatelliteProvisionStateChanged( |
| 13131 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13132 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13133 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13134 | } |
| 13135 | |
| 13136 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13137 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13138 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13139 | * @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] | 13140 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13141 | * satellite provider if the request is successful or an error code if the |
| 13142 | * request failed. |
| 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 |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13147 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13148 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13149 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13150 | } |
| 13151 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13152 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13153 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13154 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13155 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13156 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13157 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13158 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13159 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13160 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13161 | */ |
| 13162 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13163 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13164 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13165 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13166 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13167 | } |
| 13168 | |
| 13169 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13170 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13171 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13172 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13173 | * @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] | 13174 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13175 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13176 | * |
| 13177 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13178 | */ |
| 13179 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13180 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13181 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13182 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13183 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13184 | } |
| 13185 | |
| 13186 | /** |
| 13187 | * Register to receive incoming datagrams over satellite. |
| 13188 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13189 | * @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] | 13190 | * @param callback The callback to handle incoming datagrams over satellite. |
| 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 registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13198 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13199 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13200 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13201 | } |
| 13202 | |
| 13203 | /** |
| 13204 | * Unregister to stop receiving incoming datagrams over satellite. |
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 | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13207 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13208 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13209 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
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 |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13214 | public void unregisterForSatelliteDatagram(int subId, |
| 13215 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13216 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13217 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13218 | } |
| 13219 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13220 | /** |
| 13221 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13222 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13223 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13224 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13225 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13226 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13227 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13228 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13229 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13230 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13231 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13232 | @Override |
| 13233 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13234 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13235 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13236 | } |
| 13237 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13238 | /** |
| 13239 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13240 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13241 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13242 | * input to this method. Datagram received here will be passed down to modem without any |
| 13243 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13244 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13245 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13246 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13247 | * SOS_SMS or LOCATION_SHARING. |
| 13248 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13249 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13250 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13251 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13252 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13253 | * |
| 13254 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13255 | */ |
| 13256 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13257 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 13258 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13259 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13260 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13261 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 13262 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13263 | } |
| 13264 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13265 | /** |
| 13266 | * Request to get whether satellite communication is allowed for the current location. |
| 13267 | * |
| 13268 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13269 | * allowed for the current location for. |
| 13270 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13271 | * for the current location if the request is successful or an error code |
| 13272 | * if the request failed. |
| 13273 | * |
| 13274 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13275 | */ |
| 13276 | @Override |
| 13277 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 13278 | @NonNull ResultReceiver result) { |
| 13279 | enforceSatelliteCommunicationPermission( |
| 13280 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13281 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 13282 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13283 | } |
| 13284 | |
| 13285 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13286 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13287 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13288 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13289 | * @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] | 13290 | * be visible if the request is successful or an error code if the request failed. |
| 13291 | * |
| 13292 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13293 | */ |
| 13294 | @Override |
| 13295 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13296 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13297 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13298 | } |
| 13299 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13300 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13301 | * Inform that Device is aligned to satellite for demo mode. |
| 13302 | * |
| 13303 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13304 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13305 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13306 | * |
| 13307 | * @throws SecurityException if the caller doesn't have required permission. |
| 13308 | */ |
| 13309 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13310 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13311 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13312 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13313 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13314 | } |
| 13315 | |
| 13316 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13317 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13318 | * by modem. |
| 13319 | * |
| 13320 | * @param subId The subId of the subscription to request for. |
| 13321 | * @param reason Reason for disallowing satellite communication for carrier. |
| 13322 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 13323 | * operation. |
| 13324 | * |
| 13325 | * @throws SecurityException if the caller doesn't have required permission. |
| 13326 | */ |
| 13327 | public void addSatelliteAttachRestrictionForCarrier(int subId, |
| 13328 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13329 | @NonNull IIntegerConsumer callback) { |
| 13330 | enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier"); |
| 13331 | final long identity = Binder.clearCallingIdentity(); |
| 13332 | try { |
| 13333 | mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback); |
| 13334 | } finally { |
| 13335 | Binder.restoreCallingIdentity(identity); |
| 13336 | } |
| 13337 | } |
| 13338 | |
| 13339 | /** |
| 13340 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13341 | * by modem. |
| 13342 | * |
| 13343 | * @param subId The subId of the subscription to request for. |
| 13344 | * @param reason Reason for disallowing satellite communication. |
| 13345 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 13346 | * operation. |
| 13347 | * |
| 13348 | * @throws SecurityException if the caller doesn't have required permission. |
| 13349 | */ |
| 13350 | public void removeSatelliteAttachRestrictionForCarrier(int subId, |
| 13351 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13352 | @NonNull IIntegerConsumer callback) { |
| 13353 | enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier"); |
| 13354 | final long identity = Binder.clearCallingIdentity(); |
| 13355 | try { |
| 13356 | mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason, |
| 13357 | callback); |
| 13358 | } finally { |
| 13359 | Binder.restoreCallingIdentity(identity); |
| 13360 | } |
| 13361 | } |
| 13362 | |
| 13363 | /** |
| 13364 | * Get reasons for disallowing satellite communication, as requested by |
| 13365 | * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
| 13366 | * |
| 13367 | * @param subId The subId of the subscription to request for. |
| 13368 | * |
| 13369 | * @return Integer array of reasons for disallowing satellite communication. |
| 13370 | * |
| 13371 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13372 | */ |
| 13373 | public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier( |
| 13374 | int subId) { |
| 13375 | enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier"); |
| 13376 | final long identity = Binder.clearCallingIdentity(); |
| 13377 | try { |
| 13378 | Set<Integer> reasonSet = |
| 13379 | mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId); |
| 13380 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13381 | } finally { |
| 13382 | Binder.restoreCallingIdentity(identity); |
| 13383 | } |
| 13384 | } |
| 13385 | |
| 13386 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13387 | * Request to get the signal strength of the satellite connection. |
| 13388 | * |
| 13389 | * @param subId The subId of the subscription to request for. |
| 13390 | * @param result Result receiver to get the error code of the request and the current signal |
| 13391 | * strength of the satellite connection. |
| 13392 | * |
| 13393 | * @throws SecurityException if the caller doesn't have required permission. |
| 13394 | */ |
| 13395 | @Override |
| 13396 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13397 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13398 | final long identity = Binder.clearCallingIdentity(); |
| 13399 | try { |
| 13400 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13401 | } finally { |
| 13402 | Binder.restoreCallingIdentity(identity); |
| 13403 | } |
| 13404 | } |
| 13405 | |
| 13406 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13407 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13408 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13409 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13410 | * |
| 13411 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13412 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13413 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13414 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13415 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13416 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13417 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13418 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13419 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13420 | */ |
| 13421 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13422 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13423 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13424 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13425 | final long identity = Binder.clearCallingIdentity(); |
| 13426 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13427 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13428 | } finally { |
| 13429 | Binder.restoreCallingIdentity(identity); |
| 13430 | } |
| 13431 | } |
| 13432 | |
| 13433 | /** |
| 13434 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13435 | * If callback was not registered before, the request will be ignored. |
| 13436 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13437 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13438 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13439 | * @param callback The callback that was passed to |
| 13440 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13441 | * |
| 13442 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13443 | */ |
| 13444 | @Override |
| 13445 | public void unregisterForNtnSignalStrengthChanged( |
| 13446 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13447 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13448 | final long identity = Binder.clearCallingIdentity(); |
| 13449 | try { |
| 13450 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13451 | } finally { |
| 13452 | Binder.restoreCallingIdentity(identity); |
| 13453 | } |
| 13454 | } |
| 13455 | |
| 13456 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13457 | * Registers for satellite capabilities change event from the satellite service. |
| 13458 | * |
| 13459 | * @param subId The subId of the subscription to request for. |
| 13460 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13461 | * |
| 13462 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13463 | * |
| 13464 | * @throws SecurityException if the caller doesn't have required permission. |
| 13465 | */ |
| 13466 | @Override |
| 13467 | @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged( |
| 13468 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13469 | enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged"); |
| 13470 | final long identity = Binder.clearCallingIdentity(); |
| 13471 | try { |
| 13472 | return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback); |
| 13473 | } finally { |
| 13474 | Binder.restoreCallingIdentity(identity); |
| 13475 | } |
| 13476 | } |
| 13477 | |
| 13478 | /** |
| 13479 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13480 | * If callback was not registered before, the request will be ignored. |
| 13481 | * |
| 13482 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13483 | * @param callback The callback that was passed to. |
| 13484 | * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
| 13485 | * |
| 13486 | * @throws SecurityException if the caller doesn't have required permission. |
| 13487 | */ |
| 13488 | @Override |
| 13489 | public void unregisterForSatelliteCapabilitiesChanged( |
| 13490 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13491 | enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged"); |
| 13492 | final long identity = Binder.clearCallingIdentity(); |
| 13493 | try { |
| 13494 | mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback); |
| 13495 | } finally { |
| 13496 | Binder.restoreCallingIdentity(identity); |
| 13497 | } |
| 13498 | } |
| 13499 | |
| 13500 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13501 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13502 | * |
| 13503 | * @param servicePackageName The package name of the satellite vendor service. |
| 13504 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13505 | * {@code false} otherwise. |
| 13506 | */ |
| 13507 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13508 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13509 | TelephonyPermissions.enforceShellOnly( |
| 13510 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13511 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13512 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13513 | "setSatelliteServicePackageName"); |
| 13514 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13515 | } |
| 13516 | |
| 13517 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13518 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13519 | * |
| 13520 | * @param servicePackageName The package name of the satellite gateway service. |
| 13521 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13522 | * {@code false} otherwise. |
| 13523 | */ |
| 13524 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13525 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13526 | TelephonyPermissions.enforceShellOnly( |
| 13527 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13529 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13530 | "setSatelliteGatewayServicePackageName"); |
| 13531 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13532 | } |
| 13533 | |
| 13534 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13535 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13536 | * |
| 13537 | * @param packageName The package name of the satellite pointing UI app. |
| 13538 | * @param className The class name of the satellite pointing UI app. |
| 13539 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13540 | * {@code false} otherwise. |
| 13541 | */ |
| 13542 | public boolean setSatellitePointingUiClassName( |
| 13543 | @Nullable String packageName, @Nullable String className) { |
| 13544 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13545 | + ", className=" + className); |
| 13546 | TelephonyPermissions.enforceShellOnly( |
| 13547 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13549 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13550 | "setSatelliteGatewayServicePackageName"); |
| 13551 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13552 | } |
| 13553 | |
| 13554 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13555 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13556 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13557 | * listening mode. |
| 13558 | * |
| 13559 | * @param timeoutMillis The timeout duration in millisecond. |
| 13560 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13561 | */ |
| 13562 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13563 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13564 | TelephonyPermissions.enforceShellOnly( |
| 13565 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13566 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13567 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13568 | "setSatelliteListeningTimeoutDuration"); |
| 13569 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13570 | } |
| 13571 | |
| 13572 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13573 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 13574 | * the device is aligned with the satellite for demo mode |
| 13575 | * |
| 13576 | * @param timeoutMillis The timeout duration in millisecond. |
| 13577 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13578 | */ |
| 13579 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 13580 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 13581 | TelephonyPermissions.enforceShellOnly( |
| 13582 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 13583 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13584 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13585 | "setDeviceAlignedTimeoutDuration"); |
| 13586 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 13587 | } |
| 13588 | |
| 13589 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13590 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13591 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13592 | * |
| 13593 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13594 | * of the following values to enable the override: |
| 13595 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13596 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13597 | * To disable the override, use -1 for handoverType. |
| 13598 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13599 | * delaySeconds after the emergency call starts. |
| 13600 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13601 | */ |
| 13602 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13603 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13604 | TelephonyPermissions.enforceShellOnly( |
| 13605 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13606 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13607 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13608 | "setEmergencyCallToSatelliteHandoverType"); |
| 13609 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13610 | handoverType, delaySeconds); |
| 13611 | } |
| 13612 | |
| 13613 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13614 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13615 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13616 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13617 | * |
| 13618 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13619 | * satellite modem or not. |
| 13620 | * |
| 13621 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13622 | */ |
| 13623 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13624 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13625 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 13626 | + "disabled"); |
| 13627 | return false; |
| 13628 | } |
| 13629 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 13630 | TelephonyPermissions.enforceShellOnly( |
| 13631 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 13632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13633 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13634 | "setShouldSendDatagramToModemInDemoMode"); |
| 13635 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 13636 | shouldSendToModemInDemoMode); |
| 13637 | } |
| 13638 | |
| 13639 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13640 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 13641 | * |
| 13642 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 13643 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 13644 | * identifier is sent in the clear, which has privacy implications for the user. |
| 13645 | * |
| 13646 | * @param enable if notifications about disclosure events should be enabled |
| 13647 | * @throws SecurityException if the caller does not have the required privileges |
| 13648 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13649 | */ |
| 13650 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13651 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13652 | enforceModifyPermission(); |
| 13653 | checkForIdentifierDisclosureNotificationSupport(); |
| 13654 | |
| 13655 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 13656 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 13657 | editor.apply(); |
| 13658 | |
| 13659 | // Each phone instance is responsible for updating its respective modem immediately |
| 13660 | // after we've made a preference change. |
| 13661 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13662 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 13663 | } |
| 13664 | } |
| 13665 | |
| 13666 | /** |
| 13667 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 13668 | * |
| 13669 | * @throws SecurityException if the caller does not have the required privileges |
| 13670 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13671 | */ |
| 13672 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13673 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13674 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 13675 | checkForIdentifierDisclosureNotificationSupport(); |
| 13676 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 13677 | } |
| 13678 | |
| 13679 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13680 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 13681 | * |
| 13682 | * <p>This method behaves in one of the following ways: |
| 13683 | * <ul> |
| 13684 | * <li>return true : if the calling package has the appop permission {@link |
| 13685 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 13686 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 13687 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 13688 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 13689 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 13690 | * </ul> |
| 13691 | */ |
| 13692 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 13693 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 13694 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13695 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 13696 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 13697 | return true; |
| 13698 | } |
| 13699 | } |
| 13700 | return false; |
| 13701 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13702 | |
| 13703 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13704 | * @return The subscription manager service instance. |
| 13705 | */ |
| 13706 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 13707 | return SubscriptionManagerService.getInstance(); |
| 13708 | } |
| 13709 | |
| 13710 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13711 | * Class binds the consumer[callback] and carrierId. |
| 13712 | */ |
| 13713 | private static class CallerCallbackInfo { |
| 13714 | private final Consumer<Integer> mConsumer; |
| 13715 | private final int mCarrierId; |
| 13716 | |
| 13717 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 13718 | mConsumer = consumer; |
| 13719 | mCarrierId = carrierId; |
| 13720 | } |
| 13721 | |
| 13722 | public Consumer<Integer> getConsumer() { |
| 13723 | return mConsumer; |
| 13724 | } |
| 13725 | |
| 13726 | public int getCarrierId() { |
| 13727 | return mCarrierId; |
| 13728 | } |
| 13729 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13730 | |
| 13731 | /* |
| 13732 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 13733 | * But the context that is passed in is unused if the phone app is already alive. |
| 13734 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 13735 | */ |
| 13736 | @VisibleForTesting |
| 13737 | public void setPackageManager(PackageManager packageManager) { |
| 13738 | mPackageManager = packageManager; |
| 13739 | } |
| 13740 | |
| 13741 | /* |
| 13742 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 13743 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 13744 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 13745 | */ |
| 13746 | @VisibleForTesting |
| 13747 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 13748 | mFeatureFlags = featureFlags; |
| 13749 | } |
| 13750 | |
| 13751 | /** |
| 13752 | * Make sure the device has required telephony feature |
| 13753 | * |
| 13754 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 13755 | */ |
| 13756 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 13757 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 13758 | if (callingPackage == null || mPackageManager == null) { |
| 13759 | return; |
| 13760 | } |
| 13761 | |
| 13762 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 13763 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
| 13764 | Binder.getCallingUserHandle())) { |
| 13765 | return; |
| 13766 | } |
| 13767 | |
| 13768 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 13769 | throw new UnsupportedOperationException( |
| 13770 | methodName + " is unsupported without " + telephonyFeature); |
| 13771 | } |
| 13772 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13773 | } |