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 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 20 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 22 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 23 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 27 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 28 | 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] | 29 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 30 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 32 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 33 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 34 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 35 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 37 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 38 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 39 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 40 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 41 | import android.compat.annotation.ChangeId; |
| 42 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 43 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 44 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 45 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.content.Context; |
| 47 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 48 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 49 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 50 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.net.Uri; |
| 52 | import android.os.AsyncResult; |
| 53 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 54 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 56 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 58 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 59 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 60 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.os.Looper; |
| 62 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 63 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 64 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 65 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 66 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 67 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 68 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 69 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 70 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 71 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 73 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 74 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 75 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 76 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 77 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 78 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 79 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 80 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 81 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 82 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 83 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 84 | import android.telephony.AccessNetworkConstants; |
| 85 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 86 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 87 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 88 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 89 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 90 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 91 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 92 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 93 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 94 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 95 | import android.telephony.CellIdentityCdma; |
| 96 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 97 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 98 | import android.telephony.CellInfoGsm; |
| 99 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 100 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 101 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 102 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 103 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 104 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 105 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 106 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 107 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 108 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 109 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 110 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 111 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 112 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 114 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 115 | import android.telephony.SignalStrengthUpdateRequest; |
| 116 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 117 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 118 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 119 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 120 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 121 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 122 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 123 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 124 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 125 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 126 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 127 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 128 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 129 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 130 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 131 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 132 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 133 | import android.telephony.gba.GbaAuthRequest; |
| 134 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 135 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 136 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 137 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 138 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 139 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 145 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 146 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 147 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 148 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 149 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 150 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 151 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 152 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 153 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 154 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 156 | import android.telephony.satellite.NtnSignalStrength; |
| 157 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 158 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 159 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 160 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 162 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 163 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 164 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 165 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 167 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 168 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 169 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 170 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 171 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 172 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 187 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 204 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 207 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.SmsPermissions; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 210 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 213 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 217 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 219 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 220 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 222 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 224 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 225 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.IccIoResult; |
| 227 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 229 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 230 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 231 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 232 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 233 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 234 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 235 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 236 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 237 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 238 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 239 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 240 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 241 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 242 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 243 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 244 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 245 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 246 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 247 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 248 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 249 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 250 | import com.android.services.telephony.TelecomAccountRegistry; |
| 251 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 252 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 253 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 254 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 255 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 256 | import java.io.IOException; |
| 257 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 258 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 259 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 260 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 261 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 262 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 263 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 264 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 265 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 266 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 267 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 268 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 269 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 270 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 271 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 272 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 273 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 274 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | |
| 276 | /** |
| 277 | * Implementation of the ITelephony interface. |
| 278 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 279 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 280 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 281 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 282 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 283 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 284 | |
| 285 | // Message codes used with mMainThreadHandler |
| 286 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 287 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 288 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 289 | private static final int CMD_OPEN_CHANNEL = 9; |
| 290 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 291 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 292 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 293 | private static final int CMD_NV_READ_ITEM = 13; |
| 294 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 295 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 296 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 297 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 298 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 299 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 300 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 301 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 302 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 303 | private static final int CMD_SEND_ENVELOPE = 25; |
| 304 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 305 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 306 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 307 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 308 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 309 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 310 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 311 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 312 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 313 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 314 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 315 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 316 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 317 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 318 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 319 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 320 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 321 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 322 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 323 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 324 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 325 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 326 | private static final int CMD_SWITCH_SLOTS = 50; |
| 327 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 329 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 330 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 331 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 332 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 333 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 334 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 335 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 336 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 337 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 338 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 339 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 340 | private static final int CMD_MODEM_REBOOT = 64; |
| 341 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 342 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 343 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 344 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 345 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 346 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 347 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 348 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 349 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 350 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 351 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 352 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 353 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 354 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 355 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 356 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 357 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 358 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 359 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 360 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 361 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 362 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 363 | private static final int CMD_GET_CALL_WAITING = 87; |
| 364 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 365 | private static final int CMD_SET_CALL_WAITING = 89; |
| 366 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 367 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 368 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 369 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 370 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 371 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 372 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 373 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 374 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 375 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 376 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 377 | private static final int CMD_SET_SIM_POWER = 101; |
| 378 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 379 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 380 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 381 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 382 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 383 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 384 | 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] | 385 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 386 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 387 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 388 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 389 | private static final int CMD_ENABLE_VONR = 113; |
| 390 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 391 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 392 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 393 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 394 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 395 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 396 | // Parameters of select command. |
| 397 | private static final int SELECT_COMMAND = 0xA4; |
| 398 | private static final int SELECT_P1 = 0x04; |
| 399 | private static final int SELECT_P2 = 0; |
| 400 | private static final int SELECT_P3 = 0x10; |
| 401 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 402 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 403 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 404 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 405 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 406 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 407 | /** The singleton instance. */ |
| 408 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 409 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 411 | private final PhoneGlobals mApp; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 412 | private final FeatureFlags mFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 413 | private final CallManager mCM; |
| 414 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 415 | |
| 416 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 417 | private final UserManager mUserManager; |
| 418 | private final AppOpsManager mAppOps; |
| 419 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 420 | private final SharedPreferences mTelephonySharedPreferences; |
| 421 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 422 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 424 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 425 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 426 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 427 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 428 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 429 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 430 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 431 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 432 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 433 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 434 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 435 | // String to store multi SIM allowed |
| 436 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 437 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 438 | // The AID of ISD-R. |
| 439 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 440 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 441 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 442 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 443 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 444 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 445 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 446 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 447 | 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] | 448 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 449 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 450 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 451 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 452 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 453 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 454 | */ |
| 455 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 456 | "reset_network_erase_modem_config_enabled"; |
| 457 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 458 | 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] | 459 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 460 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 461 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 462 | /** |
| 463 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 464 | * one ICCID active at the same time. |
| 465 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 466 | * |
| 467 | * @hide |
| 468 | */ |
| 469 | @ChangeId |
| 470 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 471 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 472 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 473 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 474 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 475 | * operation fails. |
| 476 | */ |
| 477 | @ChangeId |
| 478 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 479 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 480 | |
| 481 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 482 | * A request object to use for transmitting data to an ICC. |
| 483 | */ |
| 484 | private static final class IccAPDUArgument { |
| 485 | public int channel, cla, command, p1, p2, p3; |
| 486 | public String data; |
| 487 | |
| 488 | public IccAPDUArgument(int channel, int cla, int command, |
| 489 | int p1, int p2, int p3, String data) { |
| 490 | this.channel = channel; |
| 491 | this.cla = cla; |
| 492 | this.command = command; |
| 493 | this.p1 = p1; |
| 494 | this.p2 = p2; |
| 495 | this.p3 = p3; |
| 496 | this.data = data; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 501 | * A request object to use for transmitting data to an ICC. |
| 502 | */ |
| 503 | private static final class ManualNetworkSelectionArgument { |
| 504 | public OperatorInfo operatorInfo; |
| 505 | public boolean persistSelection; |
| 506 | |
| 507 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 508 | this.operatorInfo = operatorInfo; |
| 509 | this.persistSelection = persistSelection; |
| 510 | } |
| 511 | } |
| 512 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 513 | private static final class PurchasePremiumCapabilityArgument { |
| 514 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 515 | public @NonNull IIntegerConsumer callback; |
| 516 | |
| 517 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 518 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 519 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 520 | this.callback = callback; |
| 521 | } |
| 522 | } |
| 523 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 524 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 525 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 526 | * request after sending. The main thread will notify the request when it is complete. |
| 527 | */ |
| 528 | private static final class MainThreadRequest { |
| 529 | /** The argument to use for the request */ |
| 530 | public Object argument; |
| 531 | /** The result of the request that is run on the main thread */ |
| 532 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 533 | // The subscriber id that this request applies to. Defaults to |
| 534 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 535 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 536 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 537 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 538 | public Phone phone; |
| 539 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 540 | public WorkSource workSource; |
| 541 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 542 | public MainThreadRequest(Object argument) { |
| 543 | this.argument = argument; |
| 544 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 545 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 546 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 547 | this.argument = argument; |
| 548 | if (phone != null) { |
| 549 | this.phone = phone; |
| 550 | } |
| 551 | this.workSource = workSource; |
| 552 | } |
| 553 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 554 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 555 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 556 | if (subId != null) { |
| 557 | this.subId = subId; |
| 558 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 559 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 560 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 563 | private static final class IncomingThirdPartyCallArgs { |
| 564 | public final ComponentName component; |
| 565 | public final String callId; |
| 566 | public final String callerDisplayName; |
| 567 | |
| 568 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 569 | String callerDisplayName) { |
| 570 | this.component = component; |
| 571 | this.callId = callId; |
| 572 | this.callerDisplayName = callerDisplayName; |
| 573 | } |
| 574 | } |
| 575 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 576 | /** |
| 577 | * A handler that processes messages on the main thread in the phone process. Since many |
| 578 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 579 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 580 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 581 | * on, which will be notified when the operation completes and will contain the result of the |
| 582 | * request. |
| 583 | * |
| 584 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 585 | * note that request.result must be set to something non-null for the calling thread to |
| 586 | * unblock. |
| 587 | */ |
| 588 | private final class MainThreadHandler extends Handler { |
| 589 | @Override |
| 590 | public void handleMessage(Message msg) { |
| 591 | MainThreadRequest request; |
| 592 | Message onCompleted; |
| 593 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 594 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 595 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 596 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 597 | |
| 598 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 599 | case CMD_HANDLE_USSD_REQUEST: { |
| 600 | request = (MainThreadRequest) msg.obj; |
| 601 | final Phone phone = getPhoneFromRequest(request); |
| 602 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 603 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 604 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 605 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | if (!isUssdApiAllowed(request.subId)) { |
| 607 | // Carrier does not support use of this API, return failure. |
| 608 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 609 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 610 | Bundle returnData = new Bundle(); |
| 611 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 612 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 613 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 614 | request.result = true; |
| 615 | notifyRequester(request); |
| 616 | return; |
| 617 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 618 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | try { |
| 620 | request.result = phone != null |
| 621 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 622 | } catch (CallStateException cse) { |
| 623 | request.result = false; |
| 624 | } |
| 625 | // Wake up the requesting thread |
| 626 | notifyRequester(request); |
| 627 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 630 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 631 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 632 | final Phone phone = getPhoneFromRequest(request); |
| 633 | request.result = phone != null ? |
| 634 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 635 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 636 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 637 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 638 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 639 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 640 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 641 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 642 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 643 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 644 | uiccPort = getUiccPortFromRequest(request); |
| 645 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 646 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 647 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 648 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 649 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 650 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 651 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 652 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 653 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 654 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 655 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 656 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | break; |
| 658 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 659 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | ar = (AsyncResult) msg.obj; |
| 661 | request = (MainThreadRequest) ar.userObj; |
| 662 | if (ar.exception == null && ar.result != null) { |
| 663 | request.result = ar.result; |
| 664 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 665 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | if (ar.result == null) { |
| 667 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 670 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | } else { |
| 672 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 673 | } |
| 674 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 675 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | break; |
| 677 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 679 | request = (MainThreadRequest) msg.obj; |
| 680 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 681 | uiccPort = getUiccPortFromRequest(request); |
| 682 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 683 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 684 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 686 | } else { |
| 687 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 688 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 689 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 690 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 691 | iccArgument.p2, |
| 692 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 693 | } |
| 694 | break; |
| 695 | |
| 696 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 697 | ar = (AsyncResult) msg.obj; |
| 698 | request = (MainThreadRequest) ar.userObj; |
| 699 | if (ar.exception == null && ar.result != null) { |
| 700 | request.result = ar.result; |
| 701 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 702 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | if (ar.result == null) { |
| 704 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 705 | } else if (ar.exception instanceof CommandException) { |
| 706 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 707 | ar.exception); |
| 708 | } else { |
| 709 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 710 | } |
| 711 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 712 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 713 | break; |
| 714 | |
| 715 | case CMD_EXCHANGE_SIM_IO: |
| 716 | request = (MainThreadRequest) msg.obj; |
| 717 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 718 | uiccPort = getUiccPortFromRequest(request); |
| 719 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 720 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 721 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 722 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 723 | } else { |
| 724 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 725 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 726 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 727 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 728 | iccArgument.data, onCompleted); |
| 729 | } |
| 730 | break; |
| 731 | |
| 732 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 733 | ar = (AsyncResult) msg.obj; |
| 734 | request = (MainThreadRequest) ar.userObj; |
| 735 | if (ar.exception == null && ar.result != null) { |
| 736 | request.result = ar.result; |
| 737 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 738 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 739 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 740 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 741 | break; |
| 742 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 743 | case CMD_SEND_ENVELOPE: |
| 744 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 745 | uiccPort = getUiccPortFromRequest(request); |
| 746 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 747 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 748 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 749 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 750 | } else { |
| 751 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 752 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 753 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 754 | break; |
| 755 | |
| 756 | case EVENT_SEND_ENVELOPE_DONE: |
| 757 | ar = (AsyncResult) msg.obj; |
| 758 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 759 | if (ar.exception == null && ar.result != null) { |
| 760 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 761 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 762 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 763 | if (ar.result == null) { |
| 764 | loge("sendEnvelopeWithStatus: Empty response"); |
| 765 | } else if (ar.exception instanceof CommandException) { |
| 766 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 767 | ar.exception); |
| 768 | } else { |
| 769 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 770 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 771 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 772 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 773 | break; |
| 774 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 775 | case CMD_OPEN_CHANNEL: |
| 776 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 777 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 778 | IccLogicalChannelRequest openChannelRequest = |
| 779 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 780 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 781 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 782 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 783 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 784 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 785 | } else { |
| 786 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 787 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 788 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 789 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 790 | break; |
| 791 | |
| 792 | case EVENT_OPEN_CHANNEL_DONE: |
| 793 | ar = (AsyncResult) msg.obj; |
| 794 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 795 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 796 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 797 | int[] result = (int[]) ar.result; |
| 798 | int channelId = result[0]; |
| 799 | byte[] selectResponse = null; |
| 800 | if (result.length > 1) { |
| 801 | selectResponse = new byte[result.length - 1]; |
| 802 | for (int i = 1; i < result.length; ++i) { |
| 803 | selectResponse[i - 1] = (byte) result[i]; |
| 804 | } |
| 805 | } |
| 806 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 807 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 808 | |
| 809 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 810 | if (uiccPort == null) { |
| 811 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 812 | } else { |
| 813 | IccLogicalChannelRequest channelRequest = |
| 814 | (IccLogicalChannelRequest) request.argument; |
| 815 | channelRequest.channel = channelId; |
| 816 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 817 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 818 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 819 | if (ar.result == null) { |
| 820 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 821 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 822 | if (ar.exception != null) { |
| 823 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 824 | } |
| 825 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 826 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 827 | if (ar.exception instanceof CommandException) { |
| 828 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 829 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 830 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 831 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 832 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 833 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 837 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 838 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 839 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 840 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 841 | break; |
| 842 | |
| 843 | case CMD_CLOSE_CHANNEL: |
| 844 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 845 | uiccPort = getUiccPortFromRequest(request); |
| 846 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 847 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 848 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 849 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 850 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 851 | } else { |
| 852 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 853 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 854 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 855 | break; |
| 856 | |
| 857 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 858 | ar = (AsyncResult) msg.obj; |
| 859 | request = (MainThreadRequest) ar.userObj; |
| 860 | if (ar.exception == null) { |
| 861 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 862 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 863 | if (uiccPort == null) { |
| 864 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 865 | } else { |
| 866 | final int channelId = (Integer) request.argument; |
| 867 | uiccPort.onLogicalChannelClosed(channelId); |
| 868 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 869 | } else { |
| 870 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 871 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 872 | if (ar.exception instanceof CommandException) { |
| 873 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 874 | CommandException.Error error = |
| 875 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 876 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 877 | // should only throw exceptions from the binder threads. |
| 878 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 879 | "iccCloseLogicalChannel: invalid argument "); |
| 880 | } |
| 881 | } else { |
| 882 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 883 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 884 | request.result = (exception != null) ? exception : |
| 885 | new IllegalStateException( |
| 886 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 887 | } |
| 888 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case CMD_NV_READ_ITEM: |
| 892 | request = (MainThreadRequest) msg.obj; |
| 893 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 894 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 895 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 896 | break; |
| 897 | |
| 898 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 899 | ar = (AsyncResult) msg.obj; |
| 900 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 901 | if (ar.exception == null && ar.result != null) { |
| 902 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 903 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 904 | request.result = ""; |
| 905 | if (ar.result == null) { |
| 906 | loge("nvReadItem: Empty response"); |
| 907 | } else if (ar.exception instanceof CommandException) { |
| 908 | loge("nvReadItem: CommandException: " + |
| 909 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 910 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 911 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 912 | } |
| 913 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 914 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 915 | break; |
| 916 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 917 | case CMD_NV_WRITE_ITEM: |
| 918 | request = (MainThreadRequest) msg.obj; |
| 919 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 920 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 921 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 922 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 923 | break; |
| 924 | |
| 925 | case EVENT_NV_WRITE_ITEM_DONE: |
| 926 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 927 | break; |
| 928 | |
| 929 | case CMD_NV_WRITE_CDMA_PRL: |
| 930 | request = (MainThreadRequest) msg.obj; |
| 931 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 932 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 933 | break; |
| 934 | |
| 935 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 936 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 937 | break; |
| 938 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 939 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 940 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 941 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 942 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 943 | break; |
| 944 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 945 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 946 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 947 | break; |
| 948 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 949 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 950 | request = (MainThreadRequest) msg.obj; |
| 951 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 952 | request); |
| 953 | Phone phone = getPhoneFromRequest(request); |
| 954 | if (phone != null) { |
| 955 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 956 | } else { |
| 957 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 958 | request.result = false; |
| 959 | notifyRequester(request); |
| 960 | } |
| 961 | break; |
| 962 | } |
| 963 | |
| 964 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 965 | ar = (AsyncResult) msg.obj; |
| 966 | request = (MainThreadRequest) ar.userObj; |
| 967 | if (ar.exception == null && ar.result != null) { |
| 968 | request.result = ar.result; |
| 969 | } else { |
| 970 | // request.result must be set to something non-null |
| 971 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 972 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 973 | request.result = ar.result; |
| 974 | } else { |
| 975 | request.result = false; |
| 976 | } |
| 977 | if (ar.result == null) { |
| 978 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 979 | } else if (ar.exception instanceof CommandException) { |
| 980 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 981 | + ar.exception); |
| 982 | } else { |
| 983 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 984 | } |
| 985 | } |
| 986 | notifyRequester(request); |
| 987 | break; |
| 988 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 989 | case CMD_IS_VONR_ENABLED: { |
| 990 | request = (MainThreadRequest) msg.obj; |
| 991 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 992 | request); |
| 993 | Phone phone = getPhoneFromRequest(request); |
| 994 | if (phone != null) { |
| 995 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 996 | } else { |
| 997 | loge("isVoNrEnabled: No phone object"); |
| 998 | request.result = false; |
| 999 | notifyRequester(request); |
| 1000 | } |
| 1001 | break; |
| 1002 | } |
| 1003 | |
| 1004 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1005 | ar = (AsyncResult) msg.obj; |
| 1006 | request = (MainThreadRequest) ar.userObj; |
| 1007 | if (ar.exception == null && ar.result != null) { |
| 1008 | request.result = ar.result; |
| 1009 | } else { |
| 1010 | // request.result must be set to something non-null |
| 1011 | // for the calling thread to unblock |
| 1012 | if (ar.result != null) { |
| 1013 | request.result = ar.result; |
| 1014 | } else { |
| 1015 | request.result = false; |
| 1016 | } |
| 1017 | if (ar.result == null) { |
| 1018 | loge("isVoNrEnabled: Empty response"); |
| 1019 | } else if (ar.exception instanceof CommandException) { |
| 1020 | loge("isVoNrEnabled: CommandException: " |
| 1021 | + ar.exception); |
| 1022 | } else { |
| 1023 | loge("isVoNrEnabled: Unknown exception"); |
| 1024 | } |
| 1025 | } |
| 1026 | notifyRequester(request); |
| 1027 | break; |
| 1028 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1029 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1030 | request = (MainThreadRequest) msg.obj; |
| 1031 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1032 | Phone phone = getPhoneFromRequest(request); |
| 1033 | if (phone != null) { |
| 1034 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1035 | request.workSource); |
| 1036 | } else { |
| 1037 | loge("enableNrDualConnectivity: No phone object"); |
| 1038 | request.result = |
| 1039 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1040 | notifyRequester(request); |
| 1041 | } |
| 1042 | break; |
| 1043 | } |
| 1044 | |
| 1045 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1046 | ar = (AsyncResult) msg.obj; |
| 1047 | request = (MainThreadRequest) ar.userObj; |
| 1048 | if (ar.exception == null) { |
| 1049 | request.result = |
| 1050 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1051 | } else { |
| 1052 | request.result = |
| 1053 | TelephonyManager |
| 1054 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1055 | if (ar.exception instanceof CommandException) { |
| 1056 | CommandException.Error error = |
| 1057 | ((CommandException) (ar.exception)).getCommandError(); |
| 1058 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1059 | request.result = |
| 1060 | TelephonyManager |
| 1061 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1062 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1063 | request.result = |
| 1064 | TelephonyManager |
| 1065 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1066 | } |
| 1067 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1068 | + ar.exception); |
| 1069 | } else { |
| 1070 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1071 | } |
| 1072 | } |
| 1073 | notifyRequester(request); |
| 1074 | break; |
| 1075 | } |
| 1076 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1077 | case CMD_ENABLE_VONR: { |
| 1078 | request = (MainThreadRequest) msg.obj; |
| 1079 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1080 | Phone phone = getPhoneFromRequest(request); |
| 1081 | if (phone != null) { |
| 1082 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1083 | request.workSource); |
| 1084 | } else { |
| 1085 | loge("setVoNrEnabled: No phone object"); |
| 1086 | request.result = |
| 1087 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1088 | notifyRequester(request); |
| 1089 | } |
| 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | case EVENT_ENABLE_VONR_DONE: { |
| 1094 | ar = (AsyncResult) msg.obj; |
| 1095 | request = (MainThreadRequest) ar.userObj; |
| 1096 | if (ar.exception == null) { |
| 1097 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1098 | } else { |
| 1099 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1100 | if (ar.exception instanceof CommandException) { |
| 1101 | CommandException.Error error = |
| 1102 | ((CommandException) (ar.exception)).getCommandError(); |
| 1103 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1104 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1105 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1106 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1107 | } else { |
| 1108 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1109 | } |
| 1110 | loge("setVoNrEnabled" + ": CommandException: " |
| 1111 | + ar.exception); |
| 1112 | } else { |
| 1113 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1114 | } |
| 1115 | } |
| 1116 | notifyRequester(request); |
| 1117 | break; |
| 1118 | } |
| 1119 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1120 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1121 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1122 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1123 | request); |
| 1124 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1125 | break; |
| 1126 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1127 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1128 | ar = (AsyncResult) msg.obj; |
| 1129 | request = (MainThreadRequest) ar.userObj; |
| 1130 | if (ar.exception == null && ar.result != null) { |
| 1131 | request.result = ar.result; // Integer |
| 1132 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1133 | // request.result must be set to something non-null |
| 1134 | // for the calling thread to unblock |
| 1135 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1136 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1137 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1138 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1139 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1140 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1141 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1142 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1143 | } |
| 1144 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1145 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1146 | break; |
| 1147 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1148 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1149 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1150 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1151 | request); |
| 1152 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1153 | (Pair<Integer, Long>) request.argument; |
| 1154 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1155 | reasonWithNetworkTypes.first, |
| 1156 | reasonWithNetworkTypes.second, |
| 1157 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1158 | break; |
| 1159 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1160 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1161 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1162 | break; |
| 1163 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1164 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1165 | request = (MainThreadRequest) msg.obj; |
| 1166 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1167 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1168 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1169 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1170 | break; |
| 1171 | |
| 1172 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1173 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1174 | break; |
| 1175 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1176 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1177 | request = (MainThreadRequest) msg.obj; |
| 1178 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1179 | request); |
| 1180 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1181 | break; |
| 1182 | |
| 1183 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1184 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1185 | break; |
| 1186 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1187 | case CMD_PERFORM_NETWORK_SCAN: |
| 1188 | request = (MainThreadRequest) msg.obj; |
| 1189 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1190 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1191 | break; |
| 1192 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1193 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1194 | request = (MainThreadRequest) msg.obj; |
| 1195 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1196 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1197 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1198 | request.argument; |
| 1199 | int callForwardingReason = args.first; |
| 1200 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1202 | } |
| 1203 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1204 | ar = (AsyncResult) msg.obj; |
| 1205 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1207 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1208 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1210 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1212 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1213 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1214 | // any service for voice call. |
| 1215 | if ((callForwardInfo.serviceClass |
| 1216 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1217 | callForwardingInfo = new CallForwardingInfo( |
| 1218 | callForwardInfo.status |
| 1219 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1220 | callForwardInfo.reason, |
| 1221 | callForwardInfo.number, |
| 1222 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1223 | break; |
| 1224 | } |
| 1225 | } |
| 1226 | // Didn't find a call forward info for voice call. |
| 1227 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1229 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | } else { |
| 1233 | if (ar.result == null) { |
| 1234 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1235 | } |
| 1236 | if (ar.exception != null) { |
| 1237 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1238 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1239 | int errorCode = TelephonyManager |
| 1240 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | if (ar.exception instanceof CommandException) { |
| 1242 | CommandException.Error error = |
| 1243 | ((CommandException) (ar.exception)).getCommandError(); |
| 1244 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1245 | errorCode = TelephonyManager |
| 1246 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1248 | errorCode = TelephonyManager |
| 1249 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | } |
| 1251 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1257 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | request = (MainThreadRequest) msg.obj; |
| 1259 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1262 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1263 | request.argument).first; |
| 1264 | request.phone.setCallForwardingOption( |
| 1265 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1266 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1267 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | callForwardingInfoToSet.getReason(), |
| 1269 | callForwardingInfoToSet.getNumber(), |
| 1270 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1271 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1272 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | ar = (AsyncResult) msg.obj; |
| 1276 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | Consumer<Integer> callback = |
| 1278 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1279 | request.argument).second; |
| 1280 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1282 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1283 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | if (ar.exception instanceof CommandException) { |
| 1285 | CommandException.Error error = |
| 1286 | ((CommandException) (ar.exception)).getCommandError(); |
| 1287 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1288 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1289 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1290 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1291 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1292 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | } |
| 1294 | } |
| 1295 | callback.accept(errorCode); |
| 1296 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1297 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1298 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1302 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | request = (MainThreadRequest) msg.obj; |
| 1304 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1305 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1306 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | ar = (AsyncResult) msg.obj; |
| 1311 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1313 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1314 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1315 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | // Service Class is a bit mask per 3gpp 27.007. |
| 1317 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1318 | if (callForwardResults.length > 1 |
| 1319 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1320 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1321 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1322 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1323 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1325 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1326 | } |
| 1327 | } else { |
| 1328 | if (ar.result == null) { |
| 1329 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1330 | } |
| 1331 | if (ar.exception != null) { |
| 1332 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1333 | } |
| 1334 | if (ar.exception instanceof CommandException) { |
| 1335 | CommandException.Error error = |
| 1336 | ((CommandException) (ar.exception)).getCommandError(); |
| 1337 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1338 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1339 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1340 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1341 | callWaitingStatus = |
| 1342 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1346 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1348 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1349 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1350 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1351 | request = (MainThreadRequest) msg.obj; |
| 1352 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1353 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1354 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1355 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1356 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1357 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1358 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1359 | ar = (AsyncResult) msg.obj; |
| 1360 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1361 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1362 | Consumer<Integer> callback = |
| 1363 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1364 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1365 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1366 | if (ar.exception instanceof CommandException) { |
| 1367 | CommandException.Error error = |
| 1368 | ((CommandException) (ar.exception)).getCommandError(); |
| 1369 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1370 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1371 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1372 | callback.accept( |
| 1373 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1374 | } else { |
| 1375 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1376 | } |
| 1377 | } else { |
| 1378 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1379 | } |
| 1380 | } else { |
| 1381 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1382 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1383 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1384 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1385 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1386 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1387 | ar = (AsyncResult) msg.obj; |
| 1388 | request = (MainThreadRequest) ar.userObj; |
| 1389 | CellNetworkScanResult cellScanResult; |
| 1390 | if (ar.exception == null && ar.result != null) { |
| 1391 | cellScanResult = new CellNetworkScanResult( |
| 1392 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1393 | (List<OperatorInfo>) ar.result); |
| 1394 | } else { |
| 1395 | if (ar.result == null) { |
| 1396 | loge("getCellNetworkScanResults: Empty response"); |
| 1397 | } |
| 1398 | if (ar.exception != null) { |
| 1399 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1400 | } |
| 1401 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1402 | if (ar.exception instanceof CommandException) { |
| 1403 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1404 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1405 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1406 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1407 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1408 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1409 | } |
| 1410 | } |
| 1411 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1412 | } |
| 1413 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1414 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1415 | break; |
| 1416 | |
| 1417 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1418 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1419 | ManualNetworkSelectionArgument selArg = |
| 1420 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1421 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1422 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1423 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1424 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1425 | break; |
| 1426 | |
| 1427 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1428 | ar = (AsyncResult) msg.obj; |
| 1429 | request = (MainThreadRequest) ar.userObj; |
| 1430 | if (ar.exception == null) { |
| 1431 | request.result = true; |
| 1432 | } else { |
| 1433 | request.result = false; |
| 1434 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1435 | } |
| 1436 | notifyRequester(request); |
| 1437 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1438 | break; |
| 1439 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1440 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1441 | request = (MainThreadRequest) msg.obj; |
| 1442 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1443 | if (defaultPhone != null) { |
| 1444 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1445 | } else { |
| 1446 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1447 | Bundle bundle = new Bundle(); |
| 1448 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1449 | new ModemActivityInfo(0, 0, 0, |
| 1450 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1451 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1452 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1453 | break; |
| 1454 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1455 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1456 | ar = (AsyncResult) msg.obj; |
| 1457 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1458 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1459 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1460 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1461 | if (mLastModemActivityInfo == null) { |
| 1462 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1463 | mLastModemActivitySpecificInfo[0] = |
| 1464 | new ActivityStatsTechSpecificInfo( |
| 1465 | 0, |
| 1466 | 0, |
| 1467 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1468 | 0); |
| 1469 | mLastModemActivityInfo = |
| 1470 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1471 | } |
| 1472 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1473 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1474 | // Update the last modem activity info and the result of the request. |
| 1475 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1476 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1477 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1478 | } else { |
| 1479 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1480 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1481 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1482 | // We don't want to return mLastModemActivityInfo which is updated |
| 1483 | // inside mergeModemActivityInfo() |
| 1484 | ret = new ModemActivityInfo( |
| 1485 | mLastModemActivityInfo.getTimestampMillis(), |
| 1486 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1487 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1488 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1489 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1490 | } else { |
| 1491 | if (ar.result == null) { |
| 1492 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1493 | error = TelephonyManager.ModemActivityInfoException |
| 1494 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1495 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1496 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1497 | error = TelephonyManager.ModemActivityInfoException |
| 1498 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1499 | } else { |
| 1500 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1501 | error = TelephonyManager.ModemActivityInfoException |
| 1502 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1503 | } |
| 1504 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1505 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1506 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1507 | bundle.putParcelable( |
| 1508 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1509 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1510 | } else { |
| 1511 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1512 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1513 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1514 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1515 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1516 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1517 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1518 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1519 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1520 | CarrierRestrictionRules argument = |
| 1521 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1522 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1523 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1524 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1525 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1526 | |
| 1527 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1528 | ar = (AsyncResult) msg.obj; |
| 1529 | request = (MainThreadRequest) ar.userObj; |
| 1530 | if (ar.exception == null && ar.result != null) { |
| 1531 | request.result = ar.result; |
| 1532 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1533 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1534 | if (ar.exception instanceof CommandException) { |
| 1535 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1536 | CommandException.Error error = |
| 1537 | ((CommandException) (ar.exception)).getCommandError(); |
| 1538 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1539 | request.result = |
| 1540 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1541 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1542 | } else { |
| 1543 | loge("setAllowedCarriers: Unknown exception"); |
| 1544 | } |
| 1545 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1546 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1547 | break; |
| 1548 | |
| 1549 | case CMD_GET_ALLOWED_CARRIERS: |
| 1550 | request = (MainThreadRequest) msg.obj; |
| 1551 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1552 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1553 | break; |
| 1554 | |
| 1555 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1556 | ar = (AsyncResult) msg.obj; |
| 1557 | request = (MainThreadRequest) ar.userObj; |
| 1558 | if (ar.exception == null && ar.result != null) { |
| 1559 | request.result = ar.result; |
| 1560 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1561 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1562 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1563 | if (ar.result == null) { |
| 1564 | loge("getAllowedCarriers: Empty response"); |
| 1565 | } else if (ar.exception instanceof CommandException) { |
| 1566 | loge("getAllowedCarriers: CommandException: " + |
| 1567 | ar.exception); |
| 1568 | } else { |
| 1569 | loge("getAllowedCarriers: Unknown exception"); |
| 1570 | } |
| 1571 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1572 | if (request.argument != null) { |
| 1573 | // This is for the implementation of carrierRestrictionStatus. |
| 1574 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1575 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1576 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1577 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1578 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1579 | CarrierRestrictionRules carrierRestrictionRules = |
| 1580 | (CarrierRestrictionRules) ar.result; |
| 1581 | int carrierId = -1; |
| 1582 | try { |
| 1583 | CarrierIdentifier carrierIdentifier = |
| 1584 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1585 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1586 | carrierIdentifier); |
| 1587 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1588 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1589 | } |
| 1590 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1591 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1592 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1593 | lockStatus = TelephonyManager |
| 1594 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1595 | } |
| 1596 | } else { |
| 1597 | Rlog.e(LOG_TAG, |
| 1598 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1599 | } |
| 1600 | callback.accept(lockStatus); |
| 1601 | } else { |
| 1602 | // This is for the implementation of getAllowedCarriers. |
| 1603 | notifyRequester(request); |
| 1604 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1605 | break; |
| 1606 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1607 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1608 | ar = (AsyncResult) msg.obj; |
| 1609 | request = (MainThreadRequest) ar.userObj; |
| 1610 | if (ar.exception == null && ar.result != null) { |
| 1611 | request.result = ar.result; |
| 1612 | } else { |
| 1613 | request.result = new IllegalArgumentException( |
| 1614 | "Failed to retrieve Forbidden Plmns"); |
| 1615 | if (ar.result == null) { |
| 1616 | loge("getForbiddenPlmns: Empty response"); |
| 1617 | } else { |
| 1618 | loge("getForbiddenPlmns: Unknown exception"); |
| 1619 | } |
| 1620 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1621 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1622 | break; |
| 1623 | |
| 1624 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1625 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1626 | uiccPort = getUiccPortFromRequest(request); |
| 1627 | if (uiccPort == null) { |
| 1628 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1629 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1630 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1631 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1632 | break; |
| 1633 | } |
| 1634 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1635 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1636 | if (uiccApp == null) { |
| 1637 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1638 | + appType); |
| 1639 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1640 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1641 | break; |
| 1642 | } else { |
| 1643 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1644 | + " specified type -- " + appType); |
| 1645 | } |
| 1646 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1647 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1648 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1649 | break; |
| 1650 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1651 | case CMD_SWITCH_SLOTS: |
| 1652 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1653 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1654 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1655 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1656 | break; |
| 1657 | |
| 1658 | case EVENT_SWITCH_SLOTS_DONE: |
| 1659 | ar = (AsyncResult) msg.obj; |
| 1660 | request = (MainThreadRequest) ar.userObj; |
| 1661 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1662 | notifyRequester(request); |
| 1663 | break; |
| 1664 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1665 | request = (MainThreadRequest) msg.obj; |
| 1666 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1667 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1668 | break; |
| 1669 | |
| 1670 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1671 | ar = (AsyncResult) msg.obj; |
| 1672 | request = (MainThreadRequest) ar.userObj; |
| 1673 | if (ar.exception != null) { |
| 1674 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1675 | } else { |
| 1676 | int mode = ((int[]) ar.result)[0]; |
| 1677 | if (mode == 0) { |
| 1678 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1679 | } else { |
| 1680 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1681 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1682 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1683 | notifyRequester(request); |
| 1684 | break; |
| 1685 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1686 | request = (MainThreadRequest) msg.obj; |
| 1687 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1688 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1689 | break; |
| 1690 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1691 | ar = (AsyncResult) msg.obj; |
| 1692 | request = (MainThreadRequest) ar.userObj; |
| 1693 | if (ar.exception != null) { |
| 1694 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1695 | } else { |
| 1696 | request.result = ((int[]) ar.result)[0]; |
| 1697 | } |
| 1698 | notifyRequester(request); |
| 1699 | break; |
| 1700 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1701 | request = (MainThreadRequest) msg.obj; |
| 1702 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1703 | int mode = (int) request.argument; |
| 1704 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1705 | break; |
| 1706 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1707 | ar = (AsyncResult) msg.obj; |
| 1708 | request = (MainThreadRequest) ar.userObj; |
| 1709 | request.result = ar.exception == null; |
| 1710 | notifyRequester(request); |
| 1711 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1712 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1713 | request = (MainThreadRequest) msg.obj; |
| 1714 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1715 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1716 | break; |
| 1717 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1718 | ar = (AsyncResult) msg.obj; |
| 1719 | request = (MainThreadRequest) ar.userObj; |
| 1720 | if (ar.exception != null) { |
| 1721 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1722 | } else { |
| 1723 | request.result = ((int[]) ar.result)[0]; |
| 1724 | } |
| 1725 | notifyRequester(request); |
| 1726 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1727 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1728 | request = (MainThreadRequest) msg.obj; |
| 1729 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1730 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1731 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1732 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1733 | break; |
| 1734 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1735 | ar = (AsyncResult) msg.obj; |
| 1736 | request = (MainThreadRequest) ar.userObj; |
| 1737 | request.result = ar.exception == null; |
| 1738 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1739 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1740 | case CMD_GET_ALL_CELL_INFO: |
| 1741 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1742 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1743 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1744 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1745 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1746 | ar = (AsyncResult) msg.obj; |
| 1747 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1748 | // If a timeout occurs, the response will be null |
| 1749 | request.result = (ar.exception == null && ar.result != null) |
| 1750 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1751 | synchronized (request) { |
| 1752 | request.notifyAll(); |
| 1753 | } |
| 1754 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1755 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1756 | request = (MainThreadRequest) msg.obj; |
| 1757 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1758 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1759 | break; |
| 1760 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1761 | ar = (AsyncResult) msg.obj; |
| 1762 | request = (MainThreadRequest) ar.userObj; |
| 1763 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1764 | try { |
| 1765 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1766 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1767 | cb.onError( |
| 1768 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1769 | ar.exception.getClass().getName(), |
| 1770 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1771 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1772 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1773 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1774 | } else { |
| 1775 | // use the result as returned |
| 1776 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1777 | } |
| 1778 | } catch (RemoteException re) { |
| 1779 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1780 | } |
| 1781 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1782 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1783 | request = (MainThreadRequest) msg.obj; |
| 1784 | WorkSource ws = (WorkSource) request.argument; |
| 1785 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1786 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1787 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1788 | } |
| 1789 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1790 | ar = (AsyncResult) msg.obj; |
| 1791 | request = (MainThreadRequest) ar.userObj; |
| 1792 | if (ar.exception == null) { |
| 1793 | request.result = ar.result; |
| 1794 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1795 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1796 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1797 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | synchronized (request) { |
| 1801 | request.notifyAll(); |
| 1802 | } |
| 1803 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1804 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1805 | case CMD_MODEM_REBOOT: |
| 1806 | request = (MainThreadRequest) msg.obj; |
| 1807 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1808 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1809 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1810 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1811 | handleNullReturnEvent(msg, "rebootModem"); |
| 1812 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1813 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1814 | request = (MainThreadRequest) msg.obj; |
| 1815 | boolean enable = (boolean) request.argument; |
| 1816 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1817 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1818 | PhoneConfigurationManager.getInstance() |
| 1819 | .enablePhone(request.phone, enable, onCompleted); |
| 1820 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1821 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1822 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1823 | ar = (AsyncResult) msg.obj; |
| 1824 | request = (MainThreadRequest) ar.userObj; |
| 1825 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1826 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1827 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1828 | if ((boolean) request.result) { |
| 1829 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1830 | updateModemStateMetrics(); |
| 1831 | } else { |
| 1832 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1833 | + ar.exception); |
| 1834 | } |
| 1835 | notifyRequester(request); |
| 1836 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1837 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1838 | case CMD_GET_MODEM_STATUS: |
| 1839 | request = (MainThreadRequest) msg.obj; |
| 1840 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1841 | PhoneConfigurationManager.getInstance() |
| 1842 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1843 | break; |
| 1844 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1845 | ar = (AsyncResult) msg.obj; |
| 1846 | request = (MainThreadRequest) ar.userObj; |
| 1847 | int id = request.phone.getPhoneId(); |
| 1848 | if (ar.exception == null && ar.result != null) { |
| 1849 | request.result = ar.result; |
| 1850 | //update the cache as modem status has changed |
| 1851 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1852 | (boolean) request.result); |
| 1853 | } else { |
| 1854 | // Return true if modem status cannot be retrieved. For most cases, |
| 1855 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1856 | // and disable modem are not supported. Modem is always on. |
| 1857 | // TODO: this should be fixed in R to support a third |
| 1858 | // status UNKNOWN b/131631629 |
| 1859 | request.result = true; |
| 1860 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1861 | + ar.exception); |
| 1862 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1863 | notifyRequester(request); |
| 1864 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1865 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1866 | request = (MainThreadRequest) msg.obj; |
| 1867 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1868 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1869 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1870 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1871 | break; |
| 1872 | } |
| 1873 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1874 | ar = (AsyncResult) msg.obj; |
| 1875 | request = (MainThreadRequest) ar.userObj; |
| 1876 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1877 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1878 | args.second.accept(ar.exception == null); |
| 1879 | notifyRequester(request); |
| 1880 | break; |
| 1881 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1882 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1883 | request = (MainThreadRequest) msg.obj; |
| 1884 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1885 | Phone phone = getPhoneFromRequest(request); |
| 1886 | if (phone != null) { |
| 1887 | phone.getSystemSelectionChannels(onCompleted); |
| 1888 | } else { |
| 1889 | loge("getSystemSelectionChannels: No phone object"); |
| 1890 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1891 | notifyRequester(request); |
| 1892 | } |
| 1893 | break; |
| 1894 | } |
| 1895 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1896 | ar = (AsyncResult) msg.obj; |
| 1897 | request = (MainThreadRequest) ar.userObj; |
| 1898 | if (ar.exception == null && ar.result != null) { |
| 1899 | request.result = ar.result; |
| 1900 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1901 | request.result = new IllegalStateException( |
| 1902 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1903 | if (ar.result == null) { |
| 1904 | loge("getSystemSelectionChannels: Empty response"); |
| 1905 | } else { |
| 1906 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1907 | } |
| 1908 | } |
| 1909 | notifyRequester(request); |
| 1910 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1911 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1912 | ar = (AsyncResult) msg.obj; |
| 1913 | request = (MainThreadRequest) ar.userObj; |
| 1914 | if (ar.exception == null && ar.result != null) { |
| 1915 | request.result = ar.result; |
| 1916 | } else { |
| 1917 | request.result = -1; |
| 1918 | loge("Failed to set Forbidden Plmns"); |
| 1919 | if (ar.result == null) { |
| 1920 | loge("setForbidenPlmns: Empty response"); |
| 1921 | } else if (ar.exception != null) { |
| 1922 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1923 | request.result = -1; |
| 1924 | } else { |
| 1925 | loge("setForbiddenPlmns: Unknown exception"); |
| 1926 | } |
| 1927 | } |
| 1928 | notifyRequester(request); |
| 1929 | break; |
| 1930 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1931 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1932 | uiccPort = getUiccPortFromRequest(request); |
| 1933 | if (uiccPort == null) { |
| 1934 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1935 | request.result = -1; |
| 1936 | notifyRequester(request); |
| 1937 | break; |
| 1938 | } |
| 1939 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1940 | (Pair<Integer, List<String>>) request.argument; |
| 1941 | appType = setFplmnsArgs.first; |
| 1942 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1943 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1944 | if (uiccApp == null) { |
| 1945 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1946 | request.result = -1; |
| 1947 | loge("Failed to get UICC App"); |
| 1948 | notifyRequester(request); |
| 1949 | } else { |
| 1950 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1951 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1952 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1953 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1954 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1955 | case CMD_ERASE_MODEM_CONFIG: |
| 1956 | request = (MainThreadRequest) msg.obj; |
| 1957 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1958 | defaultPhone.eraseModemConfig(onCompleted); |
| 1959 | break; |
| 1960 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1961 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1962 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1963 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1964 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1965 | request = (MainThreadRequest) msg.obj; |
| 1966 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1967 | notifyRequester(request); |
| 1968 | break; |
| 1969 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1970 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1971 | request = (MainThreadRequest) msg.obj; |
| 1972 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1973 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1974 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1975 | changed.first, changed.second, onCompleted); |
| 1976 | break; |
| 1977 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1978 | ar = (AsyncResult) msg.obj; |
| 1979 | request = (MainThreadRequest) ar.userObj; |
| 1980 | if (ar.exception == null) { |
| 1981 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1982 | // If the operation is successful, update the PIN storage |
| 1983 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1984 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1985 | UiccController.getInstance().getPinStorage() |
| 1986 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1987 | } else { |
| 1988 | request.result = msg.arg1; |
| 1989 | } |
| 1990 | notifyRequester(request); |
| 1991 | break; |
| 1992 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1993 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1994 | request = (MainThreadRequest) msg.obj; |
| 1995 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1996 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1997 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1998 | enabled.first, enabled.second, onCompleted); |
| 1999 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2000 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2001 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2002 | ar = (AsyncResult) msg.obj; |
| 2003 | request = (MainThreadRequest) ar.userObj; |
| 2004 | if (ar.exception == null) { |
| 2005 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2006 | // If the operation is successful, update the PIN storage |
| 2007 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2008 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2009 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2010 | UiccController.getInstance().getPinStorage() |
| 2011 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2012 | } else { |
| 2013 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2014 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2015 | } else { |
| 2016 | request.result = msg.arg1; |
| 2017 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2018 | |
| 2019 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2020 | notifyRequester(request); |
| 2021 | break; |
| 2022 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2023 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2024 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2025 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2026 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2027 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2028 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2029 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2030 | |
| 2031 | case CMD_SET_DATA_THROTTLING: { |
| 2032 | request = (MainThreadRequest) msg.obj; |
| 2033 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2034 | DataThrottlingRequest dataThrottlingRequest = |
| 2035 | (DataThrottlingRequest) request.argument; |
| 2036 | Phone phone = getPhoneFromRequest(request); |
| 2037 | if (phone != null) { |
| 2038 | phone.setDataThrottling(onCompleted, |
| 2039 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2040 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2041 | } else { |
| 2042 | loge("setDataThrottling: No phone object"); |
| 2043 | request.result = |
| 2044 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2045 | notifyRequester(request); |
| 2046 | } |
| 2047 | |
| 2048 | break; |
| 2049 | } |
| 2050 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2051 | ar = (AsyncResult) msg.obj; |
| 2052 | request = (MainThreadRequest) ar.userObj; |
| 2053 | |
| 2054 | if (ar.exception == null) { |
| 2055 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2056 | } else if (ar.exception instanceof CommandException) { |
| 2057 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2058 | CommandException.Error error = |
| 2059 | ((CommandException) (ar.exception)).getCommandError(); |
| 2060 | |
| 2061 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2062 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2063 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2064 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2065 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2066 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2067 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2068 | } else { |
| 2069 | request.result = |
| 2070 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2071 | } |
| 2072 | } else { |
| 2073 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2074 | } |
| 2075 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2076 | notifyRequester(request); |
| 2077 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2078 | |
| 2079 | case CMD_SET_SIM_POWER: { |
| 2080 | request = (MainThreadRequest) msg.obj; |
| 2081 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2082 | request = (MainThreadRequest) msg.obj; |
| 2083 | int stateToSet = |
| 2084 | ((Pair<Integer, IIntegerConsumer>) |
| 2085 | request.argument).first; |
| 2086 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2087 | break; |
| 2088 | } |
| 2089 | case EVENT_SET_SIM_POWER_DONE: { |
| 2090 | ar = (AsyncResult) msg.obj; |
| 2091 | request = (MainThreadRequest) ar.userObj; |
| 2092 | IIntegerConsumer callback = |
| 2093 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2094 | if (ar.exception != null) { |
| 2095 | loge("setSimPower exception: " + ar.exception); |
| 2096 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2097 | .RESULT_ERROR_UNKNOWN; |
| 2098 | if (ar.exception instanceof CommandException) { |
| 2099 | CommandException.Error error = |
| 2100 | ((CommandException) (ar.exception)).getCommandError(); |
| 2101 | if (error == CommandException.Error.SIM_ERR) { |
| 2102 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2103 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2104 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2105 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2106 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2107 | } else { |
| 2108 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2109 | } |
| 2110 | } |
| 2111 | try { |
| 2112 | callback.accept(errorCode); |
| 2113 | } catch (RemoteException e) { |
| 2114 | // Ignore if the remote process is no longer available to call back. |
| 2115 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2116 | } |
| 2117 | } else { |
| 2118 | try { |
| 2119 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2120 | } catch (RemoteException e) { |
| 2121 | // Ignore if the remote process is no longer available to call back. |
| 2122 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2123 | } |
| 2124 | } |
| 2125 | break; |
| 2126 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2127 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2128 | request = (MainThreadRequest) msg.obj; |
| 2129 | |
| 2130 | final Phone phone = getPhoneFromRequest(request); |
| 2131 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2132 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2133 | notifyRequester(request); |
| 2134 | break; |
| 2135 | } |
| 2136 | |
| 2137 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2138 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2139 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2140 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2141 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2142 | request.subId, pair.first /*callingUid*/, |
| 2143 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2144 | break; |
| 2145 | } |
| 2146 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2147 | ar = (AsyncResult) msg.obj; |
| 2148 | request = (MainThreadRequest) ar.userObj; |
| 2149 | // request.result will be the exception of ar if present, true otherwise. |
| 2150 | // Be cautious not to leave result null which will wait() forever |
| 2151 | request.result = ar.exception != null ? ar.exception : true; |
| 2152 | notifyRequester(request); |
| 2153 | break; |
| 2154 | } |
| 2155 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2156 | request = (MainThreadRequest) msg.obj; |
| 2157 | |
| 2158 | Phone phone = getPhoneFromRequest(request); |
| 2159 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2160 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2161 | notifyRequester(request); |
| 2162 | break; |
| 2163 | } |
| 2164 | |
| 2165 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2166 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2167 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2168 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2169 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2170 | request.subId, pair.first /*callingUid*/, |
| 2171 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2172 | break; |
| 2173 | } |
| 2174 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2175 | ar = (AsyncResult) msg.obj; |
| 2176 | request = (MainThreadRequest) ar.userObj; |
| 2177 | request.result = ar.exception != null ? ar.exception : true; |
| 2178 | notifyRequester(request); |
| 2179 | break; |
| 2180 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2181 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2182 | case CMD_GET_SLICING_CONFIG: { |
| 2183 | request = (MainThreadRequest) msg.obj; |
| 2184 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2185 | request.phone.getSlicingConfig(onCompleted); |
| 2186 | break; |
| 2187 | } |
| 2188 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2189 | ar = (AsyncResult) msg.obj; |
| 2190 | request = (MainThreadRequest) ar.userObj; |
| 2191 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2192 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2193 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2194 | Bundle bundle = new Bundle(); |
| 2195 | int resultCode = 0; |
| 2196 | if (ar.exception != null) { |
| 2197 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2198 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2199 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2200 | } else if (ar.result == null) { |
| 2201 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2202 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2203 | } else { |
| 2204 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2205 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2206 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2210 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2211 | } |
| 2212 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2213 | result.send(resultCode, bundle); |
| 2214 | notifyRequester(request); |
| 2215 | break; |
| 2216 | } |
| 2217 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2218 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2219 | request = (MainThreadRequest) msg.obj; |
| 2220 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2221 | PurchasePremiumCapabilityArgument arg = |
| 2222 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2223 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2224 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2225 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2226 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2227 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2228 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2229 | ar = (AsyncResult) msg.obj; |
| 2230 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2231 | PurchasePremiumCapabilityArgument arg = |
| 2232 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2233 | try { |
| 2234 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2235 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2236 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2237 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2238 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2239 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2240 | } catch (RemoteException e) { |
| 2241 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2242 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2243 | + " failed: " + e; |
| 2244 | if (DBG) log(logStr); |
| 2245 | AnomalyReporter.reportAnomaly( |
| 2246 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2247 | } |
| 2248 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2249 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2250 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2251 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2252 | request = (MainThreadRequest) msg.obj; |
| 2253 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2254 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2255 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2256 | notifyRequester(request); |
| 2257 | break; |
| 2258 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2259 | default: |
| 2260 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2261 | break; |
| 2262 | } |
| 2263 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2264 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2265 | private void notifyRequester(MainThreadRequest request) { |
| 2266 | synchronized (request) { |
| 2267 | request.notifyAll(); |
| 2268 | } |
| 2269 | } |
| 2270 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2271 | private void handleNullReturnEvent(Message msg, String command) { |
| 2272 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2273 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2274 | if (ar.exception == null) { |
| 2275 | request.result = true; |
| 2276 | } else { |
| 2277 | request.result = false; |
| 2278 | if (ar.exception instanceof CommandException) { |
| 2279 | loge(command + ": CommandException: " + ar.exception); |
| 2280 | } else { |
| 2281 | loge(command + ": Unknown exception"); |
| 2282 | } |
| 2283 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2284 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2285 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | /** |
| 2289 | * Posts the specified command to be executed on the main thread, |
| 2290 | * waits for the request to complete, and returns the result. |
| 2291 | * @see #sendRequestAsync |
| 2292 | */ |
| 2293 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2294 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2295 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | /** |
| 2299 | * Posts the specified command to be executed on the main thread, |
| 2300 | * waits for the request to complete, and returns the result. |
| 2301 | * @see #sendRequestAsync |
| 2302 | */ |
| 2303 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2304 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2305 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * Posts the specified command to be executed on the main thread, |
| 2310 | * waits for the request to complete, and returns the result. |
| 2311 | * @see #sendRequestAsync |
| 2312 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2313 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2314 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2315 | } |
| 2316 | |
| 2317 | /** |
| 2318 | * Posts the specified command to be executed on the main thread, |
| 2319 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2320 | * if not timeout or null otherwise. |
| 2321 | * @see #sendRequestAsync |
| 2322 | */ |
| 2323 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2324 | long timeoutInMs) { |
| 2325 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | /** |
| 2329 | * Posts the specified command to be executed on the main thread, |
| 2330 | * waits for the request to complete, and returns the result. |
| 2331 | * @see #sendRequestAsync |
| 2332 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2333 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2334 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | /** |
| 2338 | * Posts the specified command to be executed on the main thread, |
| 2339 | * waits for the request to complete, and returns the result. |
| 2340 | * @see #sendRequestAsync |
| 2341 | */ |
| 2342 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2343 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2344 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2348 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2349 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2350 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2351 | * @see #sendRequestAsync |
| 2352 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2353 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2354 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2355 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2356 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2357 | } |
| 2358 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2359 | MainThreadRequest request = null; |
| 2360 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2361 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2362 | } else if (phone != null) { |
| 2363 | request = new MainThreadRequest(argument, phone, workSource); |
| 2364 | } else { |
| 2365 | request = new MainThreadRequest(argument, subId, workSource); |
| 2366 | } |
| 2367 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2369 | msg.sendToTarget(); |
| 2370 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2371 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2373 | if (timeoutInMs >= 0) { |
| 2374 | // Wait for at least timeoutInMs before returning null request result |
| 2375 | long now = SystemClock.elapsedRealtime(); |
| 2376 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2377 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2378 | try { |
| 2379 | request.wait(deadline - now); |
| 2380 | } catch (InterruptedException e) { |
| 2381 | // Do nothing, go back and check if request is completed or timeout |
| 2382 | } finally { |
| 2383 | now = SystemClock.elapsedRealtime(); |
| 2384 | } |
| 2385 | } |
| 2386 | } else { |
| 2387 | // Wait for the request to complete |
| 2388 | while (request.result == null) { |
| 2389 | try { |
| 2390 | request.wait(); |
| 2391 | } catch (InterruptedException e) { |
| 2392 | // Do nothing, go back and wait until the request is complete |
| 2393 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | } |
| 2395 | } |
| 2396 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2397 | if (request.result == null) { |
| 2398 | Log.wtf(LOG_TAG, |
| 2399 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2400 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2401 | return request.result; |
| 2402 | } |
| 2403 | |
| 2404 | /** |
| 2405 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2406 | * Posts the specified command to be executed on the main thread, and |
| 2407 | * returns immediately. |
| 2408 | * @see #sendRequest |
| 2409 | */ |
| 2410 | private void sendRequestAsync(int command) { |
| 2411 | mMainThreadHandler.sendEmptyMessage(command); |
| 2412 | } |
| 2413 | |
| 2414 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2415 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2416 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2417 | */ |
| 2418 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2419 | sendRequestAsync(command, argument, null, null); |
| 2420 | } |
| 2421 | |
| 2422 | /** |
| 2423 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2424 | * @see {@link #sendRequest(int,Object)} |
| 2425 | */ |
| 2426 | private void sendRequestAsync( |
| 2427 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2428 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2429 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2430 | msg.sendToTarget(); |
| 2431 | } |
| 2432 | |
| 2433 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2434 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2435 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2436 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2437 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2438 | synchronized (PhoneInterfaceManager.class) { |
| 2439 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2440 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | } else { |
| 2442 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2443 | } |
| 2444 | return sInstance; |
| 2445 | } |
| 2446 | } |
| 2447 | |
| 2448 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2449 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2450 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2451 | mFeatureFlags = featureFlags; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2452 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2453 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2454 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2455 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2456 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2457 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2458 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2459 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2460 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2461 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2462 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2463 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2465 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2468 | @VisibleForTesting |
| 2469 | public SharedPreferences getSharedPreferences() { |
| 2470 | return mTelephonySharedPreferences; |
| 2471 | } |
| 2472 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2473 | /** |
| 2474 | * Get the default phone for this device. |
| 2475 | */ |
| 2476 | @VisibleForTesting |
| 2477 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2478 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2479 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2480 | } |
| 2481 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2482 | private void publish() { |
| 2483 | if (DBG) log("publish: " + this); |
| 2484 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2485 | TelephonyFrameworkInitializer |
| 2486 | .getTelephonyServiceManager() |
| 2487 | .getTelephonyServiceRegisterer() |
| 2488 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2491 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2492 | if (request.phone != null) { |
| 2493 | return request.phone; |
| 2494 | } else { |
| 2495 | return getPhoneFromSubId(request.subId); |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | private Phone getPhoneFromSubId(int subId) { |
| 2500 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2501 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2502 | } |
| 2503 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2504 | /** |
| 2505 | * Get phone object associated with a subscription. |
| 2506 | * Return default phone if phone object associated with subscription is null |
| 2507 | * @param subId - subscriptionId |
| 2508 | * @return phone object associated with a subscription or default phone if null. |
| 2509 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2510 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2511 | Phone phone = getPhoneFromSubId(subId); |
| 2512 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2513 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2514 | phone = getDefaultPhone(); |
| 2515 | } |
| 2516 | return phone; |
| 2517 | } |
| 2518 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2519 | @Nullable |
| 2520 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2521 | Phone phone = getPhoneFromRequest(request); |
| 2522 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2523 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2524 | } |
| 2525 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2526 | /** |
| 2527 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2528 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2529 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2530 | * @return The Phone associated the sub Id |
| 2531 | */ |
| 2532 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2533 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2535 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2536 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2537 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2538 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2539 | } |
| 2540 | |
| 2541 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2542 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2543 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2546 | private boolean isImsAvailableOnDevice() { |
| 2547 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2548 | if (pm == null) { |
| 2549 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2550 | // so do not throw error and allow. |
| 2551 | return true; |
| 2552 | } |
| 2553 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2554 | } |
| 2555 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2556 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2557 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2560 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2561 | if (DBG) log("dial: " + number); |
| 2562 | // No permission check needed here: This is just a wrapper around the |
| 2563 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2564 | // the UI before it does anything. |
| 2565 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2566 | final long identity = Binder.clearCallingIdentity(); |
| 2567 | try { |
| 2568 | String url = createTelUrl(number); |
| 2569 | if (url == null) { |
| 2570 | return; |
| 2571 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2574 | PhoneConstants.State state = mCM.getState(subId); |
| 2575 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2576 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2577 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2578 | mApp.startActivity(intent); |
| 2579 | } |
| 2580 | } finally { |
| 2581 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2586 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2589 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2590 | if (DBG) log("call: " + number); |
| 2591 | |
| 2592 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2593 | // need to do a permission check since we're calling startActivity() |
| 2594 | // from the context of the phone app. |
| 2595 | enforceCallPermission(); |
| 2596 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2597 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2598 | != AppOpsManager.MODE_ALLOWED) { |
| 2599 | return; |
| 2600 | } |
| 2601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | final long identity = Binder.clearCallingIdentity(); |
| 2603 | try { |
| 2604 | String url = createTelUrl(number); |
| 2605 | if (url == null) { |
| 2606 | return; |
| 2607 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2608 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | boolean isValid = false; |
| 2610 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2611 | if (slist != null) { |
| 2612 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2613 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2614 | isValid = true; |
| 2615 | break; |
| 2616 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2617 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2618 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | if (!isValid) { |
| 2620 | return; |
| 2621 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2622 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2624 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2625 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2626 | mApp.startActivity(intent); |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
| 2629 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2632 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2633 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2634 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2635 | } |
| 2636 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2637 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2638 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2639 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2640 | } |
| 2641 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2642 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2643 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2644 | |
| 2645 | final long identity = Binder.clearCallingIdentity(); |
| 2646 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2647 | Phone phone = getPhone(subId); |
| 2648 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2649 | checkSimPin.start(); |
| 2650 | return checkSimPin.unlockSim(null, pin); |
| 2651 | } finally { |
| 2652 | Binder.restoreCallingIdentity(identity); |
| 2653 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2656 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2657 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2658 | |
| 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 checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | checkSimPuk.start(); |
| 2664 | return checkSimPuk.unlockSim(puk, pin); |
| 2665 | } finally { |
| 2666 | Binder.restoreCallingIdentity(identity); |
| 2667 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2671 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2672 | * a synchronous one. |
| 2673 | */ |
| 2674 | private static class UnlockSim extends Thread { |
| 2675 | |
| 2676 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2677 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | |
| 2679 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2680 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2681 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | |
| 2683 | // For replies from SimCard interface |
| 2684 | private Handler mHandler; |
| 2685 | |
| 2686 | // For async handler to identify request type |
| 2687 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2688 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2689 | UnlockSim(int phoneId, IccCard simCard) { |
| 2690 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | mSimCard = simCard; |
| 2692 | } |
| 2693 | |
| 2694 | @Override |
| 2695 | public void run() { |
| 2696 | Looper.prepare(); |
| 2697 | synchronized (UnlockSim.this) { |
| 2698 | mHandler = new Handler() { |
| 2699 | @Override |
| 2700 | public void handleMessage(Message msg) { |
| 2701 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2702 | switch (msg.what) { |
| 2703 | case SUPPLY_PIN_COMPLETE: |
| 2704 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2705 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2706 | mRetryCount = msg.arg1; |
| 2707 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2708 | CommandException.Error error = null; |
| 2709 | if (ar.exception instanceof CommandException) { |
| 2710 | error = ((CommandException) (ar.exception)) |
| 2711 | .getCommandError(); |
| 2712 | } |
| 2713 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2714 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2715 | } else if (error == CommandException.Error.ABORTED) { |
| 2716 | /* When UiccCardApp dispose, handle message and return |
| 2717 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2718 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2719 | } else { |
| 2720 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2721 | } |
| 2722 | } else { |
| 2723 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2724 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2725 | mDone = true; |
| 2726 | UnlockSim.this.notifyAll(); |
| 2727 | } |
| 2728 | break; |
| 2729 | } |
| 2730 | } |
| 2731 | }; |
| 2732 | UnlockSim.this.notifyAll(); |
| 2733 | } |
| 2734 | Looper.loop(); |
| 2735 | } |
| 2736 | |
| 2737 | /* |
| 2738 | * Use PIN or PUK to unlock SIM card |
| 2739 | * |
| 2740 | * If PUK is null, unlock SIM card with PIN |
| 2741 | * |
| 2742 | * 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] | 2743 | * |
| 2744 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2745 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2746 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2747 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2748 | |
| 2749 | while (mHandler == null) { |
| 2750 | try { |
| 2751 | wait(); |
| 2752 | } catch (InterruptedException e) { |
| 2753 | Thread.currentThread().interrupt(); |
| 2754 | } |
| 2755 | } |
| 2756 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2757 | |
| 2758 | if (puk == null) { |
| 2759 | mSimCard.supplyPin(pin, callback); |
| 2760 | } else { |
| 2761 | mSimCard.supplyPuk(puk, pin, callback); |
| 2762 | } |
| 2763 | |
| 2764 | while (!mDone) { |
| 2765 | try { |
| 2766 | Log.d(LOG_TAG, "wait for done"); |
| 2767 | wait(); |
| 2768 | } catch (InterruptedException e) { |
| 2769 | // Restore the interrupted status |
| 2770 | Thread.currentThread().interrupt(); |
| 2771 | } |
| 2772 | } |
| 2773 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2774 | int[] resultArray = new int[2]; |
| 2775 | resultArray[0] = mResult; |
| 2776 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2777 | |
| 2778 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2779 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2780 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2781 | // This instance is no longer reused, so quit its thread's looper. |
| 2782 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2783 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2784 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2785 | } |
| 2786 | } |
| 2787 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2788 | /** |
| 2789 | * This method has been removed due to privacy and stability concerns. |
| 2790 | */ |
| 2791 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2793 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2794 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2797 | @Override |
| 2798 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2799 | mApp.getSystemService(AppOpsManager.class) |
| 2800 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2801 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2802 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2803 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2804 | // Callers targeting S have no business invoking this method. |
| 2805 | return; |
| 2806 | } |
| 2807 | |
| 2808 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2809 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2810 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2811 | .setCallingPackage(callingPackage) |
| 2812 | .setCallingFeatureId(null) |
| 2813 | .setCallingPid(Binder.getCallingPid()) |
| 2814 | .setCallingUid(Binder.getCallingUid()) |
| 2815 | .setMethod("updateServiceLocation") |
| 2816 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2817 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2818 | .build()); |
| 2819 | // Apps that lack location permission have no business calling this method; |
| 2820 | // however, because no permission was declared in the public API, denials must |
| 2821 | // all be "soft". |
| 2822 | switch (locationResult) { |
| 2823 | case DENIED_HARD: /* fall through */ |
| 2824 | case DENIED_SOFT: |
| 2825 | return; |
| 2826 | } |
| 2827 | |
| 2828 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2831 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2832 | } finally { |
| 2833 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2834 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2837 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2838 | @Override |
| 2839 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2840 | return isRadioOnWithFeature(callingPackage, null); |
| 2841 | } |
| 2842 | |
| 2843 | |
| 2844 | @Override |
| 2845 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2846 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2847 | callingFeatureId); |
| 2848 | } |
| 2849 | |
| 2850 | @Deprecated |
| 2851 | @Override |
| 2852 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2853 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2856 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2857 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2858 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2859 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2860 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2861 | return false; |
| 2862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2863 | |
| 2864 | final long identity = Binder.clearCallingIdentity(); |
| 2865 | try { |
| 2866 | return isRadioOnForSubscriber(subId); |
| 2867 | } finally { |
| 2868 | Binder.restoreCallingIdentity(identity); |
| 2869 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2873 | final long identity = Binder.clearCallingIdentity(); |
| 2874 | try { |
| 2875 | final Phone phone = getPhone(subId); |
| 2876 | if (phone != null) { |
| 2877 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2878 | } else { |
| 2879 | return false; |
| 2880 | } |
| 2881 | } finally { |
| 2882 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2883 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2887 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2888 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2889 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2890 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2891 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2892 | |
| 2893 | final long identity = Binder.clearCallingIdentity(); |
| 2894 | try { |
| 2895 | final Phone phone = getPhone(subId); |
| 2896 | if (phone != null) { |
| 2897 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2898 | } |
| 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2901 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2905 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2906 | } |
| 2907 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2908 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2909 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2910 | |
| 2911 | final long identity = Binder.clearCallingIdentity(); |
| 2912 | try { |
| 2913 | final Phone phone = getPhone(subId); |
| 2914 | if (phone == null) { |
| 2915 | return false; |
| 2916 | } |
| 2917 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2918 | toggleRadioOnOffForSubscriber(subId); |
| 2919 | } |
| 2920 | return true; |
| 2921 | } finally { |
| 2922 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2923 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2924 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2925 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2926 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2927 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2928 | /* |
| 2929 | * If any of the Radios are available, it will need to be |
| 2930 | * shutdown. So return true if any Radio is available. |
| 2931 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2932 | final long identity = Binder.clearCallingIdentity(); |
| 2933 | try { |
| 2934 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2935 | Phone phone = PhoneFactory.getPhone(i); |
| 2936 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2937 | } |
| 2938 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2939 | return false; |
| 2940 | } finally { |
| 2941 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2942 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2945 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2946 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2947 | enforceModifyPermission(); |
| 2948 | |
| 2949 | final long identity = Binder.clearCallingIdentity(); |
| 2950 | try { |
| 2951 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2952 | logv("Shutting down Phone " + i); |
| 2953 | shutdownRadioUsingPhoneId(i); |
| 2954 | } |
| 2955 | } finally { |
| 2956 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2961 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2962 | if (phone != null && phone.isRadioAvailable()) { |
| 2963 | phone.shutdownRadio(); |
| 2964 | } |
| 2965 | } |
| 2966 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2967 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2968 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2970 | if (!turnOn) { |
| 2971 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 2972 | } |
| 2973 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2974 | final long identity = Binder.clearCallingIdentity(); |
| 2975 | try { |
| 2976 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2977 | if (defaultPhone != null) { |
| 2978 | defaultPhone.setRadioPower(turnOn); |
| 2979 | return true; |
| 2980 | } else { |
| 2981 | loge("There's no default phone."); |
| 2982 | return false; |
| 2983 | } |
| 2984 | } finally { |
| 2985 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2986 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2989 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2990 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2992 | if (!turnOn) { |
| 2993 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 2994 | + ",callingPackage=" + getCurrentPackageName()); |
| 2995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | final long identity = Binder.clearCallingIdentity(); |
| 2997 | try { |
| 2998 | final Phone phone = getPhone(subId); |
| 2999 | if (phone != null) { |
| 3000 | phone.setRadioPower(turnOn); |
| 3001 | return true; |
| 3002 | } else { |
| 3003 | return false; |
| 3004 | } |
| 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3007 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3010 | /** |
| 3011 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3012 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3013 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3014 | * powering it off, and these radio off votes will be cleared. |
| 3015 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3016 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3017 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3018 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3019 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3020 | * check its vote. |
| 3021 | * |
| 3022 | * @param subId The subscription ID. |
| 3023 | * @param reason The reason for powering off radio. |
| 3024 | * @return true on success and false on failure. |
| 3025 | */ |
| 3026 | public boolean requestRadioPowerOffForReason(int subId, |
| 3027 | @TelephonyManager.RadioPowerReason int reason) { |
| 3028 | enforceModifyPermission(); |
| 3029 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3030 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3031 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3032 | final long identity = Binder.clearCallingIdentity(); |
| 3033 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3034 | boolean result = false; |
| 3035 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3036 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3037 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3038 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3039 | if (!result) { |
| 3040 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3041 | } |
| 3042 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3043 | } finally { |
| 3044 | Binder.restoreCallingIdentity(identity); |
| 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | /** |
| 3049 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3050 | * {@link requestRadioPowerOffForReason}. |
| 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 clearRadioPowerOffForReason(int subId, |
| 3057 | @TelephonyManager.RadioPowerReason int reason) { |
| 3058 | enforceModifyPermission(); |
| 3059 | |
| 3060 | final long identity = Binder.clearCallingIdentity(); |
| 3061 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3062 | boolean result = false; |
| 3063 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3064 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3065 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3066 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3067 | if (!result) { |
| 3068 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3069 | } |
| 3070 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3071 | } finally { |
| 3072 | Binder.restoreCallingIdentity(identity); |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | /** |
| 3077 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3078 | * |
| 3079 | * @param subId The subscription ID. |
| 3080 | * @param callingPackage The package making the call. |
| 3081 | * @param callingFeatureId The feature in the package. |
| 3082 | * @return List of reasons for powering off radio. |
| 3083 | */ |
| 3084 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3085 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3086 | |
| 3087 | final long identity = Binder.clearCallingIdentity(); |
| 3088 | List result = new ArrayList(); |
| 3089 | try { |
| 3090 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3091 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3092 | return result; |
| 3093 | } |
| 3094 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3095 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3096 | if (phone != null) { |
| 3097 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3098 | } else { |
| 3099 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3100 | } |
| 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
| 3103 | } |
| 3104 | return result; |
| 3105 | } |
| 3106 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3107 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3108 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3109 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3110 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3111 | |
| 3112 | final long identity = Binder.clearCallingIdentity(); |
| 3113 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3114 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3115 | final Phone phone = getPhone(subId); |
| 3116 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3117 | phone.getDataSettingsManager().setDataEnabled( |
| 3118 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3119 | return true; |
| 3120 | } else { |
| 3121 | return false; |
| 3122 | } |
| 3123 | } finally { |
| 3124 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3125 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3128 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3129 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3130 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3131 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3132 | |
| 3133 | final long identity = Binder.clearCallingIdentity(); |
| 3134 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3135 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3136 | final Phone phone = getPhone(subId); |
| 3137 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3138 | phone.getDataSettingsManager().setDataEnabled( |
| 3139 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3140 | return true; |
| 3141 | } else { |
| 3142 | return false; |
| 3143 | } |
| 3144 | } finally { |
| 3145 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3146 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3149 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3150 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3151 | final long identity = Binder.clearCallingIdentity(); |
| 3152 | try { |
| 3153 | final Phone phone = getPhone(subId); |
| 3154 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3155 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 | } else { |
| 3157 | return false; |
| 3158 | } |
| 3159 | } finally { |
| 3160 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3161 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3165 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3166 | } |
| 3167 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3168 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3169 | enforceCallPermission(); |
| 3170 | |
| 3171 | final long identity = Binder.clearCallingIdentity(); |
| 3172 | try { |
| 3173 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3174 | return; |
| 3175 | } |
| 3176 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3177 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3178 | } finally { |
| 3179 | Binder.restoreCallingIdentity(identity); |
| 3180 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3181 | }; |
| 3182 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3183 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3184 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3185 | |
| 3186 | final long identity = Binder.clearCallingIdentity(); |
| 3187 | try { |
| 3188 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3189 | return false; |
| 3190 | } |
| 3191 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3192 | } finally { |
| 3193 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3194 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3197 | /** |
| 3198 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3199 | * tag on getCallState Binder call. |
| 3200 | */ |
| 3201 | @Deprecated |
| 3202 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3203 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3204 | if (CompatChanges.isChangeEnabled( |
| 3205 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3206 | Binder.getCallingUid())) { |
| 3207 | // Do not allow this API to be called on API version 31+, it should only be |
| 3208 | // called on old apps using this Binder call directly. |
| 3209 | throw new SecurityException("This method can only be used for applications " |
| 3210 | + "targeting API version 30 or less."); |
| 3211 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3212 | final long identity = Binder.clearCallingIdentity(); |
| 3213 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3214 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3215 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3216 | } finally { |
| 3217 | Binder.restoreCallingIdentity(identity); |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | @Override |
| 3222 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3223 | if (CompatChanges.isChangeEnabled( |
| 3224 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3225 | Binder.getCallingUid())) { |
| 3226 | // Check READ_PHONE_STATE for API version 31+ |
| 3227 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3228 | featureId, "getCallStateForSubscription")) { |
| 3229 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3230 | + "targeting API level 31+."); |
| 3231 | } |
| 3232 | } |
| 3233 | final long identity = Binder.clearCallingIdentity(); |
| 3234 | try { |
| 3235 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3236 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3237 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3238 | } finally { |
| 3239 | Binder.restoreCallingIdentity(identity); |
| 3240 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3243 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3244 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3245 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | @Override |
| 3249 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | final long identity = Binder.clearCallingIdentity(); |
| 3251 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3252 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3253 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3254 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3255 | } else { |
| 3256 | return PhoneConstantConversions.convertDataState( |
| 3257 | PhoneConstants.DataState.DISCONNECTED); |
| 3258 | } |
| 3259 | } finally { |
| 3260 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3261 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3262 | } |
| 3263 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3264 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3265 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3266 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3270 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 | final long identity = Binder.clearCallingIdentity(); |
| 3272 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3273 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3275 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3276 | } else { |
| 3277 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3278 | } |
| 3279 | } finally { |
| 3280 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3281 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3285 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3286 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3287 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3288 | |
| 3289 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3290 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3291 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3292 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3293 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3294 | .setCallingPid(Binder.getCallingPid()) |
| 3295 | .setCallingUid(Binder.getCallingUid()) |
| 3296 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3297 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3298 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3299 | .build()); |
| 3300 | switch (locationResult) { |
| 3301 | case DENIED_HARD: |
| 3302 | throw new SecurityException("Not allowed to access cell location"); |
| 3303 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3304 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3305 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3308 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3309 | final long identity = Binder.clearCallingIdentity(); |
| 3310 | try { |
| 3311 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3312 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3313 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | } finally { |
| 3315 | Binder.restoreCallingIdentity(identity); |
| 3316 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3319 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3320 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3321 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3322 | // registered cell info, so return a NULL country instead. |
| 3323 | final long identity = Binder.clearCallingIdentity(); |
| 3324 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3325 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3326 | // Get default phone in this case. |
| 3327 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3328 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3329 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3331 | if (phone == null) return ""; |
| 3332 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3333 | if (sst == null) return ""; |
| 3334 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3335 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3336 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3337 | } finally { |
| 3338 | Binder.restoreCallingIdentity(identity); |
| 3339 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3342 | /** |
| 3343 | * This method was removed due to potential issues caused by performing partial |
| 3344 | * updates of service state, and lack of a credible use case. |
| 3345 | * |
| 3346 | * This has the ability to break the telephony implementation by disabling notification of |
| 3347 | * changes in device connectivity. DO NOT USE THIS! |
| 3348 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3349 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3350 | public void enableLocationUpdates() { |
| 3351 | mApp.enforceCallingOrSelfPermission( |
| 3352 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3353 | } |
| 3354 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3355 | /** |
| 3356 | * This method was removed due to potential issues caused by performing partial |
| 3357 | * updates of service state, and lack of a credible use case. |
| 3358 | * |
| 3359 | * This has the ability to break the telephony implementation by disabling notification of |
| 3360 | * changes in device connectivity. DO NOT USE THIS! |
| 3361 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3362 | @Override |
| 3363 | public void disableLocationUpdates() { |
| 3364 | mApp.enforceCallingOrSelfPermission( |
| 3365 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | @Override |
| 3369 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3370 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3371 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3372 | try { |
| 3373 | mApp.getSystemService(AppOpsManager.class) |
| 3374 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3375 | } catch (SecurityException e) { |
| 3376 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3377 | throw e; |
| 3378 | } |
| 3379 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3380 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3381 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3382 | throw new SecurityException( |
| 3383 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3384 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3385 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3386 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3387 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3388 | return null; |
| 3389 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3390 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3391 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3392 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3393 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3394 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3395 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3396 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3397 | for (CellInfo ci : info) { |
| 3398 | if (ci instanceof CellInfoGsm) { |
| 3399 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3400 | } else if (ci instanceof CellInfoWcdma) { |
| 3401 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3403 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3404 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3405 | } |
| 3406 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3407 | private List<CellInfo> getCachedCellInfo() { |
| 3408 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3409 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3410 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3411 | if (info != null) cellInfos.addAll(info); |
| 3412 | } |
| 3413 | return cellInfos; |
| 3414 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3415 | |
| 3416 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3417 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3418 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3419 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3420 | |
| 3421 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3422 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3423 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3424 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3425 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3426 | .setCallingPid(Binder.getCallingPid()) |
| 3427 | .setCallingUid(Binder.getCallingUid()) |
| 3428 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3429 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3430 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3431 | .build()); |
| 3432 | switch (locationResult) { |
| 3433 | case DENIED_HARD: |
| 3434 | throw new SecurityException("Not allowed to access cell info"); |
| 3435 | case DENIED_SOFT: |
| 3436 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3437 | } |
| 3438 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3439 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3440 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3441 | return getCachedCellInfo(); |
| 3442 | } |
| 3443 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3444 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3445 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3446 | final long identity = Binder.clearCallingIdentity(); |
| 3447 | try { |
| 3448 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3449 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3450 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3451 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3452 | if (info != null) cellInfos.addAll(info); |
| 3453 | } |
| 3454 | return cellInfos; |
| 3455 | } finally { |
| 3456 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3457 | } |
| 3458 | } |
| 3459 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3460 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3461 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3462 | String callingFeatureId) { |
| 3463 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3464 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3468 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3469 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3470 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3471 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3472 | } |
| 3473 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3474 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3475 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3476 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3477 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3478 | |
| 3479 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3480 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3481 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3482 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3483 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3484 | .setCallingPid(Binder.getCallingPid()) |
| 3485 | .setCallingUid(Binder.getCallingUid()) |
| 3486 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3487 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3488 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3489 | .build()); |
| 3490 | switch (locationResult) { |
| 3491 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3492 | if (TelephonyPermissions |
| 3493 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3494 | // Safetynet logging for b/154934934 |
| 3495 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3496 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3497 | throw new SecurityException("Not allowed to access cell info"); |
| 3498 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3499 | if (TelephonyPermissions |
| 3500 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3501 | // Safetynet logging for b/154934934 |
| 3502 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3503 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3504 | try { |
| 3505 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3506 | } catch (RemoteException re) { |
| 3507 | // Drop without consequences |
| 3508 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3509 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3510 | } |
| 3511 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3512 | |
| 3513 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3514 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3515 | |
| 3516 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3517 | } |
| 3518 | |
| 3519 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3520 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3521 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3522 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 | |
| 3524 | final long identity = Binder.clearCallingIdentity(); |
| 3525 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3526 | Phone phone = getPhone(subId); |
| 3527 | if (phone == null) { |
| 3528 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3529 | } else { |
| 3530 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3531 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3532 | } finally { |
| 3533 | Binder.restoreCallingIdentity(identity); |
| 3534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3537 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3538 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3539 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3540 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3541 | return null; |
| 3542 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3543 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3544 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3545 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3546 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3547 | return null; |
| 3548 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3549 | |
| 3550 | final long identity = Binder.clearCallingIdentity(); |
| 3551 | try { |
| 3552 | return phone.getImei(); |
| 3553 | } finally { |
| 3554 | Binder.restoreCallingIdentity(identity); |
| 3555 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3559 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3560 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3561 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3562 | callingFeatureId, "getPrimaryImei")) { |
| 3563 | throw new SecurityException("Caller does not have permission"); |
| 3564 | } |
| 3565 | final long identity = Binder.clearCallingIdentity(); |
| 3566 | try { |
| 3567 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3568 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3569 | return phone.getImei(); |
| 3570 | } |
| 3571 | } |
| 3572 | throw new UnsupportedOperationException("Operation not supported"); |
| 3573 | } finally { |
| 3574 | Binder.restoreCallingIdentity(identity); |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3579 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3580 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3581 | String tac = null; |
| 3582 | if (phone != null) { |
| 3583 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3584 | try { |
| 3585 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3586 | } catch (IndexOutOfBoundsException e) { |
| 3587 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3588 | return null; |
| 3589 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3590 | } |
| 3591 | return tac; |
| 3592 | } |
| 3593 | |
| 3594 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3595 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3596 | try { |
| 3597 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3598 | } catch (SecurityException se) { |
| 3599 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3600 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3601 | + Binder.getCallingUid()); |
| 3602 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3603 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3604 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3605 | return null; |
| 3606 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3607 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3608 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3609 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3610 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3611 | return null; |
| 3612 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3613 | |
| 3614 | final long identity = Binder.clearCallingIdentity(); |
| 3615 | try { |
| 3616 | return phone.getMeid(); |
| 3617 | } finally { |
| 3618 | Binder.restoreCallingIdentity(identity); |
| 3619 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3623 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3624 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3625 | String manufacturerCode = null; |
| 3626 | if (phone != null) { |
| 3627 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3628 | try { |
| 3629 | manufacturerCode = |
| 3630 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3631 | } catch (IndexOutOfBoundsException e) { |
| 3632 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3633 | return null; |
| 3634 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3635 | } |
| 3636 | return manufacturerCode; |
| 3637 | } |
| 3638 | |
| 3639 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3640 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3641 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3642 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3643 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3644 | return null; |
| 3645 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3646 | int subId = phone.getSubId(); |
| 3647 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3648 | mApp, subId, callingPackage, callingFeatureId, |
| 3649 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3650 | return null; |
| 3651 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 | |
| 3653 | final long identity = Binder.clearCallingIdentity(); |
| 3654 | try { |
| 3655 | return phone.getDeviceSvn(); |
| 3656 | } finally { |
| 3657 | Binder.restoreCallingIdentity(identity); |
| 3658 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3659 | } |
| 3660 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3661 | @Override |
| 3662 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3663 | final long identity = Binder.clearCallingIdentity(); |
| 3664 | try { |
| 3665 | final Phone phone = getPhone(subId); |
| 3666 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3667 | } finally { |
| 3668 | Binder.restoreCallingIdentity(identity); |
| 3669 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | @Override |
| 3673 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3674 | final long identity = Binder.clearCallingIdentity(); |
| 3675 | try { |
| 3676 | final Phone phone = getPhone(subId); |
| 3677 | return phone == null ? null : phone.getCarrierName(); |
| 3678 | } finally { |
| 3679 | Binder.restoreCallingIdentity(identity); |
| 3680 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3681 | } |
| 3682 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3683 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3684 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3685 | final long identity = Binder.clearCallingIdentity(); |
| 3686 | try { |
| 3687 | final Phone phone = getPhone(subId); |
| 3688 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3689 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(identity); |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3696 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3697 | final long identity = Binder.clearCallingIdentity(); |
| 3698 | try { |
| 3699 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3700 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3701 | } finally { |
| 3702 | Binder.restoreCallingIdentity(identity); |
| 3703 | } |
| 3704 | } |
| 3705 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3706 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3707 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3708 | if (!isSubscriptionMccMnc) { |
| 3709 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3710 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3711 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3712 | if (phone == null) { |
| 3713 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3714 | } |
| 3715 | final long identity = Binder.clearCallingIdentity(); |
| 3716 | try { |
| 3717 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3718 | } finally { |
| 3719 | Binder.restoreCallingIdentity(identity); |
| 3720 | } |
| 3721 | } |
| 3722 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3723 | // |
| 3724 | // Internal helper methods. |
| 3725 | // |
| 3726 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3727 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3728 | * Make sure the caller is the calling package itself |
| 3729 | * |
| 3730 | * @throws SecurityException if the caller is not the calling package |
| 3731 | */ |
| 3732 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3733 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3734 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3735 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3736 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3737 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3738 | } catch (PackageManager.NameNotFoundException e) { |
| 3739 | // packageUid is -1 |
| 3740 | } |
| 3741 | if (packageUid != callingUid) { |
| 3742 | throw new SecurityException(message + ": Package " + callingPackage |
| 3743 | + " does not belong to " + callingUid); |
| 3744 | } |
| 3745 | } |
| 3746 | |
| 3747 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3748 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3749 | * |
| 3750 | * @throws SecurityException if the caller does not have the required permission |
| 3751 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3752 | @VisibleForTesting |
| 3753 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3754 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3755 | } |
| 3756 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3757 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3758 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3759 | * |
| 3760 | * @throws SecurityException if the caller does not have the required permission |
| 3761 | */ |
| 3762 | @VisibleForTesting |
| 3763 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3764 | enforceReadPermission(null); |
| 3765 | } |
| 3766 | |
| 3767 | /** |
| 3768 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3769 | * |
| 3770 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3771 | */ |
| 3772 | @VisibleForTesting |
| 3773 | public void enforceReadPermission(String msg) { |
| 3774 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3775 | } |
| 3776 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3777 | private void enforceActiveEmergencySessionPermission() { |
| 3778 | mApp.enforceCallingOrSelfPermission( |
| 3779 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3780 | } |
| 3781 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3782 | /** |
| 3783 | * Make sure the caller has the CALL_PHONE permission. |
| 3784 | * |
| 3785 | * @throws SecurityException if the caller does not have the required permission |
| 3786 | */ |
| 3787 | private void enforceCallPermission() { |
| 3788 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3789 | } |
| 3790 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3791 | private void enforceSettingsPermission() { |
| 3792 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3793 | } |
| 3794 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3795 | private void enforceRebootPermission() { |
| 3796 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3797 | } |
| 3798 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3799 | /** |
| 3800 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3801 | * @param message - log message to print. |
| 3802 | * @throws SecurityException if the caller does not have the required permission |
| 3803 | */ |
| 3804 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3805 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3806 | } |
| 3807 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3808 | private String createTelUrl(String number) { |
| 3809 | if (TextUtils.isEmpty(number)) { |
| 3810 | return null; |
| 3811 | } |
| 3812 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3813 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3816 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3817 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3820 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3821 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3822 | } |
| 3823 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3824 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3825 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3828 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3829 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3830 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3833 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3834 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3835 | final long identity = Binder.clearCallingIdentity(); |
| 3836 | try { |
| 3837 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3838 | if (phone == null) { |
| 3839 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3840 | } else { |
| 3841 | return phone.getPhoneType(); |
| 3842 | } |
| 3843 | } finally { |
| 3844 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3845 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | /** |
| 3849 | * Returns the CDMA ERI icon index to display |
| 3850 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3851 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3852 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3853 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3854 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3857 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3858 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3859 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3860 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3861 | mApp, subId, callingPackage, callingFeatureId, |
| 3862 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3863 | return -1; |
| 3864 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3865 | |
| 3866 | final long identity = Binder.clearCallingIdentity(); |
| 3867 | try { |
| 3868 | final Phone phone = getPhone(subId); |
| 3869 | if (phone != null) { |
| 3870 | return phone.getCdmaEriIconIndex(); |
| 3871 | } else { |
| 3872 | return -1; |
| 3873 | } |
| 3874 | } finally { |
| 3875 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3876 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | /** |
| 3880 | * Returns the CDMA ERI icon mode, |
| 3881 | * 0 - ON |
| 3882 | * 1 - FLASHING |
| 3883 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3884 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3885 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3886 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3887 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3888 | } |
| 3889 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3890 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3891 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3892 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3893 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3894 | mApp, subId, callingPackage, callingFeatureId, |
| 3895 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3896 | return -1; |
| 3897 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3898 | |
| 3899 | final long identity = Binder.clearCallingIdentity(); |
| 3900 | try { |
| 3901 | final Phone phone = getPhone(subId); |
| 3902 | if (phone != null) { |
| 3903 | return phone.getCdmaEriIconMode(); |
| 3904 | } else { |
| 3905 | return -1; |
| 3906 | } |
| 3907 | } finally { |
| 3908 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3909 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3910 | } |
| 3911 | |
| 3912 | /** |
| 3913 | * Returns the CDMA ERI text, |
| 3914 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3915 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3916 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3917 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3918 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3921 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3922 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3923 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3924 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3925 | mApp, subId, callingPackage, callingFeatureId, |
| 3926 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3927 | return null; |
| 3928 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3929 | |
| 3930 | final long identity = Binder.clearCallingIdentity(); |
| 3931 | try { |
| 3932 | final Phone phone = getPhone(subId); |
| 3933 | if (phone != null) { |
| 3934 | return phone.getCdmaEriText(); |
| 3935 | } else { |
| 3936 | return null; |
| 3937 | } |
| 3938 | } finally { |
| 3939 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3940 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3944 | * Returns the CDMA MDN. |
| 3945 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3946 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3947 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3948 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3949 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 | |
| 3951 | final long identity = Binder.clearCallingIdentity(); |
| 3952 | try { |
| 3953 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3954 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | return phone.getLine1Number(); |
| 3956 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3957 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | return null; |
| 3959 | } |
| 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | /** |
| 3966 | * Returns the CDMA MIN. |
| 3967 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3968 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3969 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3970 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3971 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3972 | |
| 3973 | final long identity = Binder.clearCallingIdentity(); |
| 3974 | try { |
| 3975 | final Phone phone = getPhone(subId); |
| 3976 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3977 | return phone.getCdmaMin(); |
| 3978 | } else { |
| 3979 | return null; |
| 3980 | } |
| 3981 | } finally { |
| 3982 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3986 | @Override |
| 3987 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3988 | INumberVerificationCallback callback, String callingPackage) { |
| 3989 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3990 | != PERMISSION_GRANTED) { |
| 3991 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3992 | } |
| 3993 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3994 | |
| 3995 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3996 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3997 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3998 | + "calling package: " + callingPackage |
| 3999 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | if (range == null) { |
| 4003 | throw new NullPointerException("Range must be non-null"); |
| 4004 | } |
| 4005 | |
| 4006 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4007 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4008 | |
| 4009 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4010 | } |
| 4011 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4012 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4013 | * Returns true if CDMA provisioning needs to run. |
| 4014 | */ |
| 4015 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4016 | final long identity = Binder.clearCallingIdentity(); |
| 4017 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4018 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4019 | } finally { |
| 4020 | Binder.restoreCallingIdentity(identity); |
| 4021 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4025 | * Sets the voice mail number of a given subId. |
| 4026 | */ |
| 4027 | @Override |
| 4028 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4029 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4030 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4031 | |
| 4032 | final long identity = Binder.clearCallingIdentity(); |
| 4033 | try { |
| 4034 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4035 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4036 | return success; |
| 4037 | } finally { |
| 4038 | Binder.restoreCallingIdentity(identity); |
| 4039 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4042 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4043 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4044 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4045 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4046 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4047 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4048 | throw new SecurityException("caller must be system dialer"); |
| 4049 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4054 | if (phoneAccountHandle == null) { |
| 4055 | return null; |
| 4056 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4057 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4058 | } finally { |
| 4059 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4060 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
| 4063 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4064 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4065 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4066 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4067 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4068 | mApp, subId, callingPackage, callingFeatureId, |
| 4069 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4070 | return null; |
| 4071 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4072 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4073 | final long identity = Binder.clearCallingIdentity(); |
| 4074 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4075 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4076 | } finally { |
| 4077 | Binder.restoreCallingIdentity(identity); |
| 4078 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4082 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4083 | VisualVoicemailSmsFilterSettings settings) { |
| 4084 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4085 | |
| 4086 | final long identity = Binder.clearCallingIdentity(); |
| 4087 | try { |
| 4088 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4089 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4090 | } finally { |
| 4091 | Binder.restoreCallingIdentity(identity); |
| 4092 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4096 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4097 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4098 | |
| 4099 | final long identity = Binder.clearCallingIdentity(); |
| 4100 | try { |
| 4101 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4102 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(identity); |
| 4105 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4109 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4110 | String callingPackage, int subId) { |
| 4111 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | |
| 4113 | final long identity = Binder.clearCallingIdentity(); |
| 4114 | try { |
| 4115 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4116 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4117 | } finally { |
| 4118 | Binder.restoreCallingIdentity(identity); |
| 4119 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
| 4122 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4123 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4124 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4125 | |
| 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4129 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(identity); |
| 4132 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4136 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4137 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4138 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4139 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4140 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4141 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4142 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4143 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4144 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4145 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4146 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4147 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4148 | * Sets the voice activation state of a given subId. |
| 4149 | */ |
| 4150 | @Override |
| 4151 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4153 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4154 | |
| 4155 | final long identity = Binder.clearCallingIdentity(); |
| 4156 | try { |
| 4157 | final Phone phone = getPhone(subId); |
| 4158 | if (phone != null) { |
| 4159 | phone.setVoiceActivationState(activationState); |
| 4160 | } else { |
| 4161 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4162 | } |
| 4163 | } finally { |
| 4164 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | |
| 4168 | /** |
| 4169 | * Sets the data activation state of a given subId. |
| 4170 | */ |
| 4171 | @Override |
| 4172 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4173 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4174 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4175 | |
| 4176 | final long identity = Binder.clearCallingIdentity(); |
| 4177 | try { |
| 4178 | final Phone phone = getPhone(subId); |
| 4179 | if (phone != null) { |
| 4180 | phone.setDataActivationState(activationState); |
| 4181 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4182 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | } |
| 4184 | } finally { |
| 4185 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | /** |
| 4190 | * Returns the voice activation state of a given subId. |
| 4191 | */ |
| 4192 | @Override |
| 4193 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4194 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4196 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4197 | final long identity = Binder.clearCallingIdentity(); |
| 4198 | try { |
| 4199 | if (phone != null) { |
| 4200 | return phone.getVoiceActivationState(); |
| 4201 | } else { |
| 4202 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4203 | } |
| 4204 | } finally { |
| 4205 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | /** |
| 4210 | * Returns the data activation state of a given subId. |
| 4211 | */ |
| 4212 | @Override |
| 4213 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4216 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4217 | final long identity = Binder.clearCallingIdentity(); |
| 4218 | try { |
| 4219 | if (phone != null) { |
| 4220 | return phone.getDataActivationState(); |
| 4221 | } else { |
| 4222 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4223 | } |
| 4224 | } finally { |
| 4225 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4230 | * Returns the unread count of voicemails for a subId |
| 4231 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4232 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4233 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4234 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4236 | mApp, subId, callingPackage, callingFeatureId, |
| 4237 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4238 | return 0; |
| 4239 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4240 | final long identity = Binder.clearCallingIdentity(); |
| 4241 | try { |
| 4242 | final Phone phone = getPhone(subId); |
| 4243 | if (phone != null) { |
| 4244 | return phone.getVoiceMessageCount(); |
| 4245 | } else { |
| 4246 | return 0; |
| 4247 | } |
| 4248 | } finally { |
| 4249 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4250 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4254 | * returns true, if the device is in a state where both voice and data |
| 4255 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4256 | */ |
| 4257 | @Override |
| 4258 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4259 | final long identity = Binder.clearCallingIdentity(); |
| 4260 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4261 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4262 | } finally { |
| 4263 | Binder.restoreCallingIdentity(identity); |
| 4264 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4268 | * Send the dialer code if called from the current default dialer or the caller has |
| 4269 | * carrier privilege. |
| 4270 | * @param inputCode The dialer code to send |
| 4271 | */ |
| 4272 | @Override |
| 4273 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4274 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4275 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4276 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4277 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4278 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4279 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4280 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4281 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4282 | |
| 4283 | final long identity = Binder.clearCallingIdentity(); |
| 4284 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4285 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4286 | } finally { |
| 4287 | Binder.restoreCallingIdentity(identity); |
| 4288 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4289 | } |
| 4290 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4291 | @Override |
| 4292 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4293 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4294 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4295 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4296 | final long identity = Binder.clearCallingIdentity(); |
| 4297 | try { |
| 4298 | if (!isActiveSubscription(subId)) { |
| 4299 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4300 | } |
| 4301 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4302 | } finally { |
| 4303 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4304 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4307 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4308 | public boolean isInEmergencySmsMode() { |
| 4309 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
| 4312 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4313 | if (phone.isInEmergencySmsMode()) { |
| 4314 | return true; |
| 4315 | } |
| 4316 | } |
| 4317 | } finally { |
| 4318 | Binder.restoreCallingIdentity(identity); |
| 4319 | } |
| 4320 | return false; |
| 4321 | } |
| 4322 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4323 | /** |
| 4324 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4325 | * @param subId The subscription to use to check the configuration. |
| 4326 | * @param c The callback that will be used to send the result. |
| 4327 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4328 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4329 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4330 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4331 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4332 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4333 | |
| 4334 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4335 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4336 | "IMS not available on device."); |
| 4337 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4338 | final long token = Binder.clearCallingIdentity(); |
| 4339 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4340 | int slotId = getSlotIndexOrException(subId); |
| 4341 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4342 | |
| 4343 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4344 | if (controller != null) { |
| 4345 | ImsManager imsManager = controller.getImsManager(subId); |
| 4346 | if (imsManager != null) { |
| 4347 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4348 | } else { |
| 4349 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4350 | } |
| 4351 | } else { |
| 4352 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4353 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4354 | } catch (ImsException e) { |
| 4355 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4356 | } finally { |
| 4357 | Binder.restoreCallingIdentity(token); |
| 4358 | } |
| 4359 | } |
| 4360 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4361 | /** |
| 4362 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4363 | * @param subId The subscription to use to check the configuration. |
| 4364 | * @param c The callback that will be used to send the result. |
| 4365 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4366 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4367 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4368 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4369 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4370 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4371 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4372 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4373 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4374 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4375 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4376 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4377 | if (controller != null) { |
| 4378 | ImsManager imsManager = controller.getImsManager(subId); |
| 4379 | if (imsManager != null) { |
| 4380 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4381 | } else { |
| 4382 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4383 | + "is inactive, ignoring unregister."); |
| 4384 | // If the ImsManager is not valid, just return, since the callback |
| 4385 | // will already have been removed internally. |
| 4386 | } |
| 4387 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4388 | } finally { |
| 4389 | Binder.restoreCallingIdentity(token); |
| 4390 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4391 | } |
| 4392 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4393 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4394 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4395 | * @param subId The subscription to use to check the configuration. |
| 4396 | * @param c The callback that will be used to send the result. |
| 4397 | */ |
| 4398 | @Override |
| 4399 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4400 | throws RemoteException { |
| 4401 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4402 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4403 | |
| 4404 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4405 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4406 | "IMS not available on device."); |
| 4407 | } |
| 4408 | final long token = Binder.clearCallingIdentity(); |
| 4409 | try { |
| 4410 | int slotId = getSlotIndexOrException(subId); |
| 4411 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4412 | |
| 4413 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4414 | if (controller != null) { |
| 4415 | ImsManager imsManager = controller.getImsManager(subId); |
| 4416 | if (imsManager != null) { |
| 4417 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4418 | } else { |
| 4419 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4420 | } |
| 4421 | } else { |
| 4422 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4423 | } |
| 4424 | } catch (ImsException e) { |
| 4425 | throw new ServiceSpecificException(e.getCode()); |
| 4426 | } finally { |
| 4427 | Binder.restoreCallingIdentity(token); |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | /** |
| 4432 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4433 | * @param subId The subscription to use to check the configuration. |
| 4434 | * @param c The callback that will be used to send the result. |
| 4435 | */ |
| 4436 | @Override |
| 4437 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4438 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4439 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4440 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4441 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4442 | } |
| 4443 | final long token = Binder.clearCallingIdentity(); |
| 4444 | |
| 4445 | try { |
| 4446 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4447 | if (controller != null) { |
| 4448 | ImsManager imsManager = controller.getImsManager(subId); |
| 4449 | if (imsManager != null) { |
| 4450 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4451 | } else { |
| 4452 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4453 | + "is inactive, ignoring unregister."); |
| 4454 | // If the ImsManager is not valid, just return, since the callback |
| 4455 | // will already have been removed internally. |
| 4456 | } |
| 4457 | } |
| 4458 | } finally { |
| 4459 | Binder.restoreCallingIdentity(token); |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4464 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4465 | */ |
| 4466 | @Override |
| 4467 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4468 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4469 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4470 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4471 | "IMS not available on device."); |
| 4472 | } |
| 4473 | final long token = Binder.clearCallingIdentity(); |
| 4474 | try { |
| 4475 | Phone phone = getPhone(subId); |
| 4476 | if (phone == null) { |
| 4477 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4478 | + subId + "'"); |
| 4479 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4480 | } |
| 4481 | phone.getImsRegistrationState(regState -> { |
| 4482 | try { |
| 4483 | consumer.accept((regState == null) |
| 4484 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4485 | } catch (RemoteException e) { |
| 4486 | // Ignore if the remote process is no longer available to call back. |
| 4487 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4488 | } |
| 4489 | }); |
| 4490 | } finally { |
| 4491 | Binder.restoreCallingIdentity(token); |
| 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | /** |
| 4496 | * Get the transport type for the IMS service registration state. |
| 4497 | */ |
| 4498 | @Override |
| 4499 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4500 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4501 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4502 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4503 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4504 | "IMS not available on device."); |
| 4505 | } |
| 4506 | final long token = Binder.clearCallingIdentity(); |
| 4507 | try { |
| 4508 | Phone phone = getPhone(subId); |
| 4509 | if (phone == null) { |
| 4510 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4511 | + subId + "'"); |
| 4512 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4513 | } |
| 4514 | phone.getImsRegistrationTech(regTech -> { |
| 4515 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4516 | int regTechConverted = (regTech == null) |
| 4517 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4518 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4519 | regTechConverted); |
| 4520 | try { |
| 4521 | consumer.accept(regTechConverted); |
| 4522 | } catch (RemoteException e) { |
| 4523 | // Ignore if the remote process is no longer available to call back. |
| 4524 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4525 | } |
| 4526 | }); |
| 4527 | } finally { |
| 4528 | Binder.restoreCallingIdentity(token); |
| 4529 | } |
| 4530 | } |
| 4531 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4532 | /** |
| 4533 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4534 | * @param subId The subscription to use to check the configuration. |
| 4535 | * @param c The callback that will be used to send the result. |
| 4536 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4537 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4538 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4539 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4540 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4541 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4542 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4543 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4544 | "IMS not available on device."); |
| 4545 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4546 | final long token = Binder.clearCallingIdentity(); |
| 4547 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4548 | int slotId = getSlotIndexOrException(subId); |
| 4549 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4550 | |
| 4551 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4552 | if (controller != null) { |
| 4553 | ImsManager imsManager = controller.getImsManager(subId); |
| 4554 | if (imsManager != null) { |
| 4555 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4556 | } else { |
| 4557 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4558 | } |
| 4559 | } else { |
| 4560 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4561 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4562 | } catch (ImsException e) { |
| 4563 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4564 | } finally { |
| 4565 | Binder.restoreCallingIdentity(token); |
| 4566 | } |
| 4567 | } |
| 4568 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4569 | /** |
| 4570 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4571 | * @param subId The subscription to use to check the configuration. |
| 4572 | * @param c The callback that will be used to send the result. |
| 4573 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4574 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4575 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4576 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4577 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4578 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4579 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4580 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4581 | |
| 4582 | final long token = Binder.clearCallingIdentity(); |
| 4583 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4584 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4585 | if (controller != null) { |
| 4586 | ImsManager imsManager = controller.getImsManager(subId); |
| 4587 | if (imsManager != null) { |
| 4588 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4589 | } else { |
| 4590 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4591 | + " is inactive, ignoring unregister."); |
| 4592 | // If the ImsManager is not valid, just return, since the callback |
| 4593 | // will already have been removed internally. |
| 4594 | } |
| 4595 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4596 | } finally { |
| 4597 | Binder.restoreCallingIdentity(token); |
| 4598 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4602 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4603 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4604 | final long token = Binder.clearCallingIdentity(); |
| 4605 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4606 | int slotId = getSlotIndexOrException(subId); |
| 4607 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4608 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4609 | } catch (com.android.ims.ImsException e) { |
| 4610 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4611 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4612 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4613 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4614 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4615 | } finally { |
| 4616 | Binder.restoreCallingIdentity(token); |
| 4617 | } |
| 4618 | } |
| 4619 | |
| 4620 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4621 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4622 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4623 | final long token = Binder.clearCallingIdentity(); |
| 4624 | try { |
| 4625 | Phone phone = getPhone(subId); |
| 4626 | if (phone == null) return false; |
| 4627 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4628 | } catch (com.android.ims.ImsException e) { |
| 4629 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4630 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4631 | } finally { |
| 4632 | Binder.restoreCallingIdentity(token); |
| 4633 | } |
| 4634 | } |
| 4635 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4636 | /** |
| 4637 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4638 | * subscription. |
| 4639 | * @param subId The subscription to use to check the configuration. |
| 4640 | * @param callback The callback that will be used to send the result. |
| 4641 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4642 | * @param transportType The transport type of the MmTelFeature capability. |
| 4643 | */ |
| 4644 | @Override |
| 4645 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4646 | int transportType) { |
| 4647 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4648 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4649 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4650 | "IMS not available on device."); |
| 4651 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4652 | final long token = Binder.clearCallingIdentity(); |
| 4653 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4654 | int slotId = getSlotIndex(subId); |
| 4655 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4656 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4657 | + subId + "'"); |
| 4658 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4659 | } |
| 4660 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4661 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4662 | transportType, aBoolean -> { |
| 4663 | try { |
| 4664 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4665 | } catch (RemoteException e) { |
| 4666 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4667 | + "running. Ignore"); |
| 4668 | } |
| 4669 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4670 | } catch (ImsException e) { |
| 4671 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4672 | } finally { |
| 4673 | Binder.restoreCallingIdentity(token); |
| 4674 | } |
| 4675 | } |
| 4676 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4677 | /** |
| 4678 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4679 | * @param subId The subscription to use to check the configuration. |
| 4680 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4681 | @Override |
| 4682 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4683 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4684 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4685 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4686 | final long token = Binder.clearCallingIdentity(); |
| 4687 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4688 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4689 | // 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] | 4690 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4691 | } catch (ImsException e) { |
| 4692 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4693 | } finally { |
| 4694 | Binder.restoreCallingIdentity(token); |
| 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4699 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4701 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4702 | final long identity = Binder.clearCallingIdentity(); |
| 4703 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4704 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4705 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4706 | // 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] | 4707 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4708 | } catch (ImsException e) { |
| 4709 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4710 | } finally { |
| 4711 | Binder.restoreCallingIdentity(identity); |
| 4712 | } |
| 4713 | } |
| 4714 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4715 | /** |
| 4716 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4717 | * @param subId The subscription to use to check the configuration. |
| 4718 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4719 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4720 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4721 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4722 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4723 | final long identity = Binder.clearCallingIdentity(); |
| 4724 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4725 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4726 | // 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] | 4727 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4728 | } catch (ImsException e) { |
| 4729 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4730 | } finally { |
| 4731 | Binder.restoreCallingIdentity(identity); |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4736 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4738 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4739 | final long identity = Binder.clearCallingIdentity(); |
| 4740 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4741 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4742 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4743 | // 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] | 4744 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4745 | } catch (ImsException e) { |
| 4746 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4747 | } finally { |
| 4748 | Binder.restoreCallingIdentity(identity); |
| 4749 | } |
| 4750 | } |
| 4751 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4752 | /** |
| 4753 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4754 | * @param subId The subscription to use to check the configuration. |
| 4755 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4756 | @Override |
| 4757 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4758 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4759 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4760 | final long identity = Binder.clearCallingIdentity(); |
| 4761 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4762 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4763 | // 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] | 4764 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4765 | } catch (ImsException e) { |
| 4766 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4767 | } finally { |
| 4768 | Binder.restoreCallingIdentity(identity); |
| 4769 | } |
| 4770 | } |
| 4771 | |
| 4772 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4773 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4774 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4775 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4776 | final long identity = Binder.clearCallingIdentity(); |
| 4777 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4778 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4779 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4780 | // 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] | 4781 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4782 | } catch (ImsException e) { |
| 4783 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4784 | } finally { |
| 4785 | Binder.restoreCallingIdentity(identity); |
| 4786 | } |
| 4787 | } |
| 4788 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4789 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4790 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4791 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4792 | * @param subId The subscription to use to check the configuration. |
| 4793 | */ |
| 4794 | @Override |
| 4795 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4796 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4797 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4798 | final long identity = Binder.clearCallingIdentity(); |
| 4799 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4800 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4801 | // 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] | 4802 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4803 | } catch (ImsException e) { |
| 4804 | throw new ServiceSpecificException(e.getCode()); |
| 4805 | } finally { |
| 4806 | Binder.restoreCallingIdentity(identity); |
| 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | /** |
| 4811 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4812 | * Requires MODIFY_PHONE_STATE permission. |
| 4813 | * @param subId The subscription to use to check the configuration. |
| 4814 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4815 | * false otherwise |
| 4816 | */ |
| 4817 | @Override |
| 4818 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4819 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4820 | "setCrossSimCallingEnabled"); |
| 4821 | final long identity = Binder.clearCallingIdentity(); |
| 4822 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4823 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4824 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4825 | // 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] | 4826 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4827 | } catch (ImsException e) { |
| 4828 | throw new ServiceSpecificException(e.getCode()); |
| 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
| 4831 | } |
| 4832 | } |
| 4833 | |
| 4834 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4835 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4836 | * @param subId The subscription to use to check the configuration. |
| 4837 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4838 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4839 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4840 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4841 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4842 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4843 | final long identity = Binder.clearCallingIdentity(); |
| 4844 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4845 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4846 | // 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] | 4847 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4848 | } catch (ImsException e) { |
| 4849 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4850 | } finally { |
| 4851 | Binder.restoreCallingIdentity(identity); |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4856 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4858 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4859 | final long identity = Binder.clearCallingIdentity(); |
| 4860 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4861 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4862 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4863 | // 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] | 4864 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4865 | } catch (ImsException e) { |
| 4866 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4867 | } finally { |
| 4868 | Binder.restoreCallingIdentity(identity); |
| 4869 | } |
| 4870 | } |
| 4871 | |
| 4872 | @Override |
| 4873 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4874 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4875 | "setVoWiFiNonPersistent"); |
| 4876 | final long identity = Binder.clearCallingIdentity(); |
| 4877 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4878 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4879 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4880 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4881 | } catch (ImsException e) { |
| 4882 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4883 | } finally { |
| 4884 | Binder.restoreCallingIdentity(identity); |
| 4885 | } |
| 4886 | } |
| 4887 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4888 | /** |
| 4889 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4890 | * @param subId The subscription to use to check the configuration. |
| 4891 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4892 | @Override |
| 4893 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4894 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4895 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4896 | final long identity = Binder.clearCallingIdentity(); |
| 4897 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4898 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4899 | // 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] | 4900 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
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 | |
| 4908 | @Override |
| 4909 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4910 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4911 | "setVoWiFiModeSetting"); |
| 4912 | final long identity = Binder.clearCallingIdentity(); |
| 4913 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4914 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4915 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4916 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4917 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4918 | } catch (ImsException e) { |
| 4919 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(identity); |
| 4922 | } |
| 4923 | } |
| 4924 | |
| 4925 | @Override |
| 4926 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4927 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4928 | final long identity = Binder.clearCallingIdentity(); |
| 4929 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4930 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4931 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4932 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4933 | } catch (ImsException e) { |
| 4934 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4935 | } finally { |
| 4936 | Binder.restoreCallingIdentity(identity); |
| 4937 | } |
| 4938 | } |
| 4939 | |
| 4940 | @Override |
| 4941 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4943 | "setVoWiFiRoamingModeSetting"); |
| 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4946 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4947 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4948 | // 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] | 4949 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4950 | } catch (ImsException e) { |
| 4951 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4952 | } finally { |
| 4953 | Binder.restoreCallingIdentity(identity); |
| 4954 | } |
| 4955 | } |
| 4956 | |
| 4957 | @Override |
| 4958 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4960 | "setRttCapabilityEnabled"); |
| 4961 | final long identity = Binder.clearCallingIdentity(); |
| 4962 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4963 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4964 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4965 | // 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] | 4966 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4967 | } catch (ImsException e) { |
| 4968 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4969 | } finally { |
| 4970 | Binder.restoreCallingIdentity(identity); |
| 4971 | } |
| 4972 | } |
| 4973 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4974 | /** |
| 4975 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4976 | * @param subId The subscription to use to check the configuration. |
| 4977 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4978 | @Override |
| 4979 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4980 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4981 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4982 | final long identity = Binder.clearCallingIdentity(); |
| 4983 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4984 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4985 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4986 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4987 | } catch (ImsException e) { |
| 4988 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4989 | } finally { |
| 4990 | Binder.restoreCallingIdentity(identity); |
| 4991 | } |
| 4992 | } |
| 4993 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4994 | @Override |
| 4995 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4996 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4997 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4998 | final long identity = Binder.clearCallingIdentity(); |
| 4999 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5000 | if (!isImsAvailableOnDevice()) { |
| 5001 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5002 | "IMS not available on device."); |
| 5003 | } |
| 5004 | int slotId = getSlotIndexOrException(subId); |
| 5005 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5006 | |
| 5007 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5008 | if (controller != null) { |
| 5009 | ImsManager imsManager = controller.getImsManager(subId); |
| 5010 | if (imsManager != null) { |
| 5011 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5012 | } else { |
| 5013 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5014 | } |
| 5015 | } else { |
| 5016 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5017 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5018 | } catch (ImsException e) { |
| 5019 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5020 | } finally { |
| 5021 | Binder.restoreCallingIdentity(identity); |
| 5022 | } |
| 5023 | } |
| 5024 | |
| 5025 | @Override |
| 5026 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5027 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5028 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5029 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5030 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5031 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5032 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5033 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5034 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5035 | if (controller != null) { |
| 5036 | ImsManager imsManager = controller.getImsManager(subId); |
| 5037 | if (imsManager != null) { |
| 5038 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5039 | } else { |
| 5040 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5041 | + " is inactive, ignoring unregister."); |
| 5042 | // If the ImsManager is not valid, just return, since the callback will already |
| 5043 | // have been removed internally. |
| 5044 | } |
| 5045 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5046 | } finally { |
| 5047 | Binder.restoreCallingIdentity(identity); |
| 5048 | } |
| 5049 | } |
| 5050 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5051 | @Override |
| 5052 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5053 | IFeatureProvisioningCallback callback) { |
| 5054 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5055 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5056 | |
| 5057 | final long identity = Binder.clearCallingIdentity(); |
| 5058 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5059 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5060 | } |
| 5061 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5062 | try { |
| 5063 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5064 | if (controller == null) { |
| 5065 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5066 | "Device does not support IMS"); |
| 5067 | } |
| 5068 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5069 | } finally { |
| 5070 | Binder.restoreCallingIdentity(identity); |
| 5071 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | @Override |
| 5075 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5076 | IFeatureProvisioningCallback callback) { |
| 5077 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5078 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5079 | |
| 5080 | final long identity = Binder.clearCallingIdentity(); |
| 5081 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5082 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5083 | } |
| 5084 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5085 | try { |
| 5086 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5087 | if (controller == null) { |
| 5088 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5089 | return; |
| 5090 | } |
| 5091 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5092 | } finally { |
| 5093 | Binder.restoreCallingIdentity(identity); |
| 5094 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5095 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5096 | |
| 5097 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5099 | message); |
| 5100 | } |
| 5101 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5102 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5103 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5104 | boolean isProvisioned) { |
| 5105 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5106 | |
| 5107 | final long identity = Binder.clearCallingIdentity(); |
| 5108 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5109 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5110 | if (controller == null) { |
| 5111 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5112 | return; |
| 5113 | } |
| 5114 | controller.setRcsProvisioningStatusForCapability( |
| 5115 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5116 | } finally { |
| 5117 | Binder.restoreCallingIdentity(identity); |
| 5118 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | |
| 5122 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5123 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5124 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5125 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5126 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5127 | final long identity = Binder.clearCallingIdentity(); |
| 5128 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5129 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5130 | if (controller == null) { |
| 5131 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5132 | |
| 5133 | // device does not support IMS, this method will return true always. |
| 5134 | return true; |
| 5135 | } |
| 5136 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5137 | } finally { |
| 5138 | Binder.restoreCallingIdentity(identity); |
| 5139 | } |
| 5140 | } |
| 5141 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5142 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5143 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5144 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5145 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5146 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5149 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5150 | if (controller == null) { |
| 5151 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5152 | return; |
| 5153 | } |
| 5154 | controller.setImsProvisioningStatusForCapability( |
| 5155 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5156 | } finally { |
| 5157 | Binder.restoreCallingIdentity(identity); |
| 5158 | } |
| 5159 | } |
| 5160 | |
| 5161 | @Override |
| 5162 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5163 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5164 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5165 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5166 | final long identity = Binder.clearCallingIdentity(); |
| 5167 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5168 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5169 | if (controller == null) { |
| 5170 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5171 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5172 | // device does not support IMS, this method will return true always. |
| 5173 | return true; |
| 5174 | } |
| 5175 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5176 | } finally { |
| 5177 | Binder.restoreCallingIdentity(identity); |
| 5178 | } |
| 5179 | } |
| 5180 | |
| 5181 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5182 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5183 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5184 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5185 | |
| 5186 | final long identity = Binder.clearCallingIdentity(); |
| 5187 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5188 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5189 | if (controller == null) { |
| 5190 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5191 | |
| 5192 | // device does not support IMS, this method will return false |
| 5193 | return false; |
| 5194 | } |
| 5195 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5196 | } finally { |
| 5197 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5198 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5202 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5203 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5204 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5205 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5206 | final long identity = Binder.clearCallingIdentity(); |
| 5207 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5208 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5209 | if (controller == null) { |
| 5210 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5211 | |
| 5212 | // device does not support IMS, this method will return false |
| 5213 | return false; |
| 5214 | } |
| 5215 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5216 | } finally { |
| 5217 | Binder.restoreCallingIdentity(identity); |
| 5218 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5219 | } |
| 5220 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5221 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5222 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5223 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5224 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5225 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5226 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5227 | mApp, subId, "getImsProvisioningInt"); |
| 5228 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5229 | final long identity = Binder.clearCallingIdentity(); |
| 5230 | try { |
| 5231 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5232 | int slotId = getSlotIndex(subId); |
| 5233 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5234 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5235 | + subId + "' for key:" + key); |
| 5236 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5237 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5238 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5239 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5240 | if (controller == null) { |
| 5241 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5242 | |
| 5243 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5244 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5245 | } |
| 5246 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5247 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5248 | return retVal; |
| 5249 | } |
| 5250 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5251 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5252 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5253 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5254 | + subId + "' for key:" + key); |
| 5255 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5256 | } finally { |
| 5257 | Binder.restoreCallingIdentity(identity); |
| 5258 | } |
| 5259 | } |
| 5260 | |
| 5261 | @Override |
| 5262 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5263 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5264 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5265 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5266 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5267 | mApp, subId, "getImsProvisioningString"); |
| 5268 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
| 5271 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5272 | int slotId = getSlotIndex(subId); |
| 5273 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5274 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5275 | + subId + "' for key:" + key); |
| 5276 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5277 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5278 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5279 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5280 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5281 | + subId + "' for key:" + key); |
| 5282 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
| 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | @Override |
| 5289 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5290 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5291 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5292 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5294 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5295 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5296 | final long identity = Binder.clearCallingIdentity(); |
| 5297 | try { |
| 5298 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5299 | int slotId = getSlotIndex(subId); |
| 5300 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5301 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5302 | + subId + "' for key:" + key); |
| 5303 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5304 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5305 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5306 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5307 | if (controller == null) { |
| 5308 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5309 | |
| 5310 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5311 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5312 | } |
| 5313 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5314 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5315 | return retVal; |
| 5316 | } |
| 5317 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5318 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5319 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5320 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5321 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5322 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5323 | } finally { |
| 5324 | Binder.restoreCallingIdentity(identity); |
| 5325 | } |
| 5326 | } |
| 5327 | |
| 5328 | @Override |
| 5329 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5330 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5331 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5332 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5333 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5334 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5335 | final long identity = Binder.clearCallingIdentity(); |
| 5336 | try { |
| 5337 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5338 | int slotId = getSlotIndex(subId); |
| 5339 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5340 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5341 | + subId + "' for key:" + key); |
| 5342 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5343 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5344 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5345 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5346 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5347 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5348 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5349 | } finally { |
| 5350 | Binder.restoreCallingIdentity(identity); |
| 5351 | } |
| 5352 | } |
| 5353 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5354 | /** |
| 5355 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5356 | * for the given slot ID or no ImsResolver instance has been created. |
| 5357 | * @param slotId The slot ID that the IMS service is created for. |
| 5358 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5359 | */ |
| 5360 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5361 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5362 | ImsFeature.FEATURE_MMTEL)) { |
| 5363 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5364 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5365 | } |
| 5366 | } |
| 5367 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5368 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5369 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5370 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5371 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5372 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5373 | } |
| 5374 | return slotId; |
| 5375 | } |
| 5376 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5377 | private int getSlotIndex(int subId) { |
| 5378 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5379 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5380 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5381 | } |
| 5382 | return slotId; |
| 5383 | } |
| 5384 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5385 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5386 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5387 | */ |
| 5388 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5389 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5390 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5391 | try { |
| 5392 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5393 | } catch (SecurityException se) { |
| 5394 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5395 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5396 | + Binder.getCallingUid()); |
| 5397 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5398 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5399 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5400 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5401 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5402 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5403 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5404 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5405 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5406 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5407 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5408 | final long identity = Binder.clearCallingIdentity(); |
| 5409 | try { |
| 5410 | final Phone phone = getPhone(subId); |
| 5411 | if (phone != null) { |
| 5412 | return phone.getServiceState().getDataNetworkType(); |
| 5413 | } else { |
| 5414 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5415 | } |
| 5416 | } finally { |
| 5417 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5418 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5419 | } |
| 5420 | |
| 5421 | /** |
| 5422 | * Returns the data network type |
| 5423 | */ |
| 5424 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5425 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5426 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5427 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | /** |
| 5431 | * Returns the data network type for a subId |
| 5432 | */ |
| 5433 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5434 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5435 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5436 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5437 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5438 | mApp, functionName)) { |
| 5439 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5440 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5441 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5442 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5443 | } |
| 5444 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5445 | final long identity = Binder.clearCallingIdentity(); |
| 5446 | try { |
| 5447 | final Phone phone = getPhone(subId); |
| 5448 | if (phone != null) { |
| 5449 | return phone.getServiceState().getDataNetworkType(); |
| 5450 | } else { |
| 5451 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5452 | } |
| 5453 | } finally { |
| 5454 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5455 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5459 | * Returns the Voice network type for a subId |
| 5460 | */ |
| 5461 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5462 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5463 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5464 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5465 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5466 | mApp, functionName)) { |
| 5467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5468 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5469 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5470 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5471 | } |
| 5472 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5473 | final long identity = Binder.clearCallingIdentity(); |
| 5474 | try { |
| 5475 | final Phone phone = getPhone(subId); |
| 5476 | if (phone != null) { |
| 5477 | return phone.getServiceState().getVoiceNetworkType(); |
| 5478 | } else { |
| 5479 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5480 | } |
| 5481 | } finally { |
| 5482 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | /** |
| 5487 | * @return true if a ICC card is present |
| 5488 | */ |
| 5489 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5490 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5491 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5492 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5496 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5497 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5498 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5499 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5500 | final long identity = Binder.clearCallingIdentity(); |
| 5501 | try { |
| 5502 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5503 | if (phone != null) { |
| 5504 | return phone.getIccCard().hasIccCard(); |
| 5505 | } else { |
| 5506 | return false; |
| 5507 | } |
| 5508 | } finally { |
| 5509 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | /** |
| 5514 | * Return if the current radio is LTE on CDMA. This |
| 5515 | * is a tri-state return value as for a period of time |
| 5516 | * the mode may be unknown. |
| 5517 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5518 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5519 | * @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] | 5520 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5521 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5522 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5523 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5524 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5525 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5526 | } |
| 5527 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5528 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5529 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5530 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5531 | try { |
| 5532 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5533 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5534 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5535 | } |
| 5536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5537 | final long identity = Binder.clearCallingIdentity(); |
| 5538 | try { |
| 5539 | final Phone phone = getPhone(subId); |
| 5540 | if (phone == null) { |
| 5541 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5542 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5543 | return TelephonyProperties.lte_on_cdma_device() |
| 5544 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5545 | } |
| 5546 | } finally { |
| 5547 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5548 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5549 | } |
| 5550 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5551 | /** |
| 5552 | * {@hide} |
| 5553 | * Returns Default subId, 0 in the case of single standby. |
| 5554 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5555 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5556 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5557 | } |
| 5558 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5559 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5560 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5561 | } |
| 5562 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5563 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5564 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5565 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5566 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5567 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5568 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5569 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5570 | } |
| 5571 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5572 | /** |
| 5573 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5574 | */ |
| 5575 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5576 | final long identity = Binder.clearCallingIdentity(); |
| 5577 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5578 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5579 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5580 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5581 | } finally { |
| 5582 | Binder.restoreCallingIdentity(identity); |
| 5583 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | /** |
| 5587 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5588 | */ |
| 5589 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | final long identity = Binder.clearCallingIdentity(); |
| 5591 | try { |
| 5592 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5593 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5594 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5595 | } finally { |
| 5596 | Binder.restoreCallingIdentity(identity); |
| 5597 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5598 | } |
| 5599 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5600 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5601 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5602 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5603 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5604 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5605 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5606 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5607 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5608 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5609 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5610 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5611 | } |
| 5612 | return PhoneFactory.getPhone(phoneId); |
| 5613 | } |
| 5614 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5615 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5616 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5617 | @NonNull IccLogicalChannelRequest request) { |
| 5618 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5619 | /*message=*/ "iccOpenLogicalChannel"); |
| 5620 | |
| 5621 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5622 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5623 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5624 | |
| 5625 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5626 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5627 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5628 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5629 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5630 | Phone phone; |
| 5631 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5633 | mApp, request.subId, message); |
| 5634 | phone = getPhoneFromSubId(request.subId); |
| 5635 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5636 | enforceModifyPermission(); |
| 5637 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5638 | } else { |
| 5639 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5640 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5641 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5645 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5646 | final long identity = Binder.clearCallingIdentity(); |
| 5647 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5648 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5650 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5651 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5652 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5653 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5654 | loge("The calling package is not allowed to access ISD-R."); |
| 5655 | throw new SecurityException( |
| 5656 | "The calling package is not allowed to access ISD-R."); |
| 5657 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5658 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5659 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5660 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5661 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5662 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5663 | return response; |
| 5664 | } finally { |
| 5665 | Binder.restoreCallingIdentity(identity); |
| 5666 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5670 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5671 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5672 | /*message=*/"iccCloseLogicalChannel"); |
| 5673 | |
| 5674 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5675 | |
| 5676 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5677 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5678 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5679 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5680 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5681 | // before this feature is enabled, this API should only return false if |
| 5682 | // the operation fails instead of throwing runtime exception for |
| 5683 | // backward-compatibility. |
| 5684 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5685 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | final long identity = Binder.clearCallingIdentity(); |
| 5687 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5688 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5689 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5690 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5691 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5692 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5693 | Boolean success = false; |
| 5694 | if (result instanceof RuntimeException) { |
| 5695 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5696 | if (shouldThrowExceptionOnFailure) { |
| 5697 | throw (RuntimeException) result; |
| 5698 | } else { |
| 5699 | return false; |
| 5700 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5701 | } else if (result instanceof Boolean) { |
| 5702 | success = (Boolean) result; |
| 5703 | } else { |
| 5704 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5705 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5706 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5707 | return success; |
| 5708 | } finally { |
| 5709 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5710 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5711 | } |
| 5712 | |
| 5713 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5714 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5715 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5717 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5718 | if (DBG) { |
| 5719 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5720 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5721 | + p3 + " data=" + data); |
| 5722 | } |
| 5723 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5724 | command, p1, p2, p3, data); |
| 5725 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5726 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5727 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5728 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5729 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5730 | enforceModifyPermission(); |
| 5731 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5732 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5733 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5734 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5735 | } |
| 5736 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5737 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5738 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5739 | } |
| 5740 | |
| 5741 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5742 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5743 | final long identity = Binder.clearCallingIdentity(); |
| 5744 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5745 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5746 | return ""; |
| 5747 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5748 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5749 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5750 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5751 | null /* workSource */); |
| 5752 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5753 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5754 | // Append the returned status code to the end of the response payload. |
| 5755 | String s = Integer.toHexString( |
| 5756 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5757 | if (response.payload != null) { |
| 5758 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5759 | } |
| 5760 | return s; |
| 5761 | } finally { |
| 5762 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5763 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5764 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5765 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5766 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5767 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5768 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5770 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5772 | if (DBG) { |
| 5773 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5774 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5775 | } |
| 5776 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5777 | cla, command, p1, p2, p3, data); |
| 5778 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5779 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5780 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5781 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5782 | 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] | 5783 | enforceModifyPermission(); |
| 5784 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5785 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5786 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5787 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5788 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5792 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5793 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5794 | } |
| 5795 | |
| 5796 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5797 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5798 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | final long identity = Binder.clearCallingIdentity(); |
| 5800 | try { |
| 5801 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5802 | && TextUtils.equals(ISDR_AID, data)) { |
| 5803 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5804 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5805 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | if (bestComponent == null |
| 5807 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5808 | loge("The calling package is not allowed to select ISD-R."); |
| 5809 | throw new SecurityException( |
| 5810 | "The calling package is not allowed to select ISD-R."); |
| 5811 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5812 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5813 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5814 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5815 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5816 | null /* workSource */); |
| 5817 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5818 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5819 | // Append the returned status code to the end of the response payload. |
| 5820 | String s = Integer.toHexString( |
| 5821 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5822 | if (response.payload != null) { |
| 5823 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5824 | } |
| 5825 | return s; |
| 5826 | } finally { |
| 5827 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5828 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5832 | 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] | 5833 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5834 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5835 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5836 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5837 | final long identity = Binder.clearCallingIdentity(); |
| 5838 | try { |
| 5839 | if (DBG) { |
| 5840 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5841 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5842 | } |
| 5843 | |
| 5844 | IccIoResult response = |
| 5845 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5846 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5847 | subId); |
| 5848 | |
| 5849 | if (DBG) { |
| 5850 | log("Exchange SIM_IO [R]" + response); |
| 5851 | } |
| 5852 | |
| 5853 | byte[] result = null; |
| 5854 | int length = 2; |
| 5855 | if (response.payload != null) { |
| 5856 | length = 2 + response.payload.length; |
| 5857 | result = new byte[length]; |
| 5858 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5859 | } else { |
| 5860 | result = new byte[length]; |
| 5861 | } |
| 5862 | |
| 5863 | result[length - 1] = (byte) response.sw2; |
| 5864 | result[length - 2] = (byte) response.sw1; |
| 5865 | return result; |
| 5866 | } finally { |
| 5867 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5868 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5869 | } |
| 5870 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5871 | /** |
| 5872 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5873 | * on a particular subscription |
| 5874 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5875 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5876 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5877 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5878 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5879 | return null; |
| 5880 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | |
| 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
| 5884 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5885 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5886 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5887 | return null; |
| 5888 | } |
| 5889 | Object response = sendRequest( |
| 5890 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5891 | if (response instanceof String[]) { |
| 5892 | return (String[]) response; |
| 5893 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5894 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5895 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5896 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | } finally { |
| 5898 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5899 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5900 | } |
| 5901 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5902 | /** |
| 5903 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5904 | * subscription. |
| 5905 | * |
| 5906 | * @param subId the id of the subscription. |
| 5907 | * @param appType the uicc app type, must be USIM or SIM. |
| 5908 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5909 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5910 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5911 | * @return number of fplmns that is successfully written to the SIM. |
| 5912 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5913 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5914 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5915 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5916 | mApp, subId, "setForbiddenPlmns"); |
| 5917 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5918 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5919 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5920 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5921 | } |
| 5922 | if (fplmns == null) { |
| 5923 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5924 | } |
| 5925 | for (String fplmn : fplmns) { |
| 5926 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5927 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5928 | } |
| 5929 | } |
| 5930 | final long identity = Binder.clearCallingIdentity(); |
| 5931 | try { |
| 5932 | Object response = sendRequest( |
| 5933 | CMD_SET_FORBIDDEN_PLMNS, |
| 5934 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5935 | subId); |
| 5936 | return (int) response; |
| 5937 | } finally { |
| 5938 | Binder.restoreCallingIdentity(identity); |
| 5939 | } |
| 5940 | } |
| 5941 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5942 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5943 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5945 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5946 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | final long identity = Binder.clearCallingIdentity(); |
| 5948 | try { |
| 5949 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5950 | if (response.payload == null) { |
| 5951 | return ""; |
| 5952 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5953 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5954 | // Append the returned status code to the end of the response payload. |
| 5955 | String s = Integer.toHexString( |
| 5956 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5957 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5958 | return s; |
| 5959 | } finally { |
| 5960 | Binder.restoreCallingIdentity(identity); |
| 5961 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5962 | } |
| 5963 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5964 | /** |
| 5965 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5966 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5967 | * |
| 5968 | * @param itemID the ID of the item to read |
| 5969 | * @return the NV item as a String, or null on error. |
| 5970 | */ |
| 5971 | @Override |
| 5972 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5973 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5975 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5976 | |
| 5977 | final long identity = Binder.clearCallingIdentity(); |
| 5978 | try { |
| 5979 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5980 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5982 | return value; |
| 5983 | } finally { |
| 5984 | Binder.restoreCallingIdentity(identity); |
| 5985 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | /** |
| 5989 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5990 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5991 | * |
| 5992 | * @param itemID the ID of the item to read |
| 5993 | * @param itemValue the value to write, as a String |
| 5994 | * @return true on success; false on any failure |
| 5995 | */ |
| 5996 | @Override |
| 5997 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5998 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6000 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | |
| 6002 | final long identity = Binder.clearCallingIdentity(); |
| 6003 | try { |
| 6004 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6005 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6006 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6007 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6008 | return success; |
| 6009 | } finally { |
| 6010 | Binder.restoreCallingIdentity(identity); |
| 6011 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6012 | } |
| 6013 | |
| 6014 | /** |
| 6015 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6016 | * Used for device configuration by some CDMA operators. |
| 6017 | * |
| 6018 | * @param preferredRoamingList byte array containing the new PRL |
| 6019 | * @return true on success; false on any failure |
| 6020 | */ |
| 6021 | @Override |
| 6022 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6023 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6024 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6025 | |
| 6026 | final long identity = Binder.clearCallingIdentity(); |
| 6027 | try { |
| 6028 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6029 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6030 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6031 | return success; |
| 6032 | } finally { |
| 6033 | Binder.restoreCallingIdentity(identity); |
| 6034 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6038 | * 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] | 6039 | * Used for device configuration by some CDMA operators. |
| 6040 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6041 | * @param slotIndex - device slot. |
| 6042 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6043 | * @return true on success; false on any failure |
| 6044 | */ |
| 6045 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6046 | public boolean resetModemConfig(int slotIndex) { |
| 6047 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6048 | if (phone != null) { |
| 6049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6050 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6051 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6052 | final long identity = Binder.clearCallingIdentity(); |
| 6053 | try { |
| 6054 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6055 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6056 | return success; |
| 6057 | } finally { |
| 6058 | Binder.restoreCallingIdentity(identity); |
| 6059 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6060 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6061 | return false; |
| 6062 | } |
| 6063 | |
| 6064 | /** |
| 6065 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6066 | * |
| 6067 | * @param slotIndex - device slot. |
| 6068 | * |
| 6069 | * @return true on success; false on any failure |
| 6070 | */ |
| 6071 | @Override |
| 6072 | public boolean rebootModem(int slotIndex) { |
| 6073 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6074 | if (phone != null) { |
| 6075 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6076 | mApp, phone.getSubId(), "rebootModem"); |
| 6077 | |
| 6078 | final long identity = Binder.clearCallingIdentity(); |
| 6079 | try { |
| 6080 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6081 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6082 | return success; |
| 6083 | } finally { |
| 6084 | Binder.restoreCallingIdentity(identity); |
| 6085 | } |
| 6086 | } |
| 6087 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6088 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6089 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6090 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6091 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6092 | * {@link #disableIms(int)}. |
| 6093 | * @param slotIndex device slot. |
| 6094 | */ |
| 6095 | public void resetIms(int slotIndex) { |
| 6096 | enforceModifyPermission(); |
| 6097 | |
| 6098 | final long identity = Binder.clearCallingIdentity(); |
| 6099 | try { |
| 6100 | if (mImsResolver == null) { |
| 6101 | // may happen if the does not support IMS. |
| 6102 | return; |
| 6103 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6104 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6105 | } finally { |
| 6106 | Binder.restoreCallingIdentity(identity); |
| 6107 | } |
| 6108 | } |
| 6109 | |
| 6110 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6111 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6112 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6113 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6114 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6115 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6116 | |
| 6117 | final long identity = Binder.clearCallingIdentity(); |
| 6118 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6119 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6120 | // may happen if the device does not support IMS. |
| 6121 | return; |
| 6122 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6123 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6124 | } finally { |
| 6125 | Binder.restoreCallingIdentity(identity); |
| 6126 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6130 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6131 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6132 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6133 | public void disableIms(int slotId) { |
| 6134 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | |
| 6136 | final long identity = Binder.clearCallingIdentity(); |
| 6137 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6138 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6139 | // may happen if the device does not support IMS. |
| 6140 | return; |
| 6141 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6142 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6143 | } finally { |
| 6144 | Binder.restoreCallingIdentity(identity); |
| 6145 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6146 | } |
| 6147 | |
| 6148 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6149 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6150 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6151 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6152 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6153 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6154 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6155 | |
| 6156 | final long identity = Binder.clearCallingIdentity(); |
| 6157 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6158 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6159 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6160 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6161 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6162 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6163 | } finally { |
| 6164 | Binder.restoreCallingIdentity(identity); |
| 6165 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6166 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6167 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6168 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6169 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6170 | @Override |
| 6171 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6172 | enforceModifyPermission(); |
| 6173 | |
| 6174 | final long identity = Binder.clearCallingIdentity(); |
| 6175 | try { |
| 6176 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6177 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(identity); |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6184 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6185 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6186 | */ |
| 6187 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6188 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6189 | |
| 6190 | final long identity = Binder.clearCallingIdentity(); |
| 6191 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6192 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6193 | // may happen if the device does not support IMS. |
| 6194 | return null; |
| 6195 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6196 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6197 | } finally { |
| 6198 | Binder.restoreCallingIdentity(identity); |
| 6199 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6200 | } |
| 6201 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6202 | /** |
| 6203 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6204 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6205 | */ |
| 6206 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6207 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6208 | |
| 6209 | final long identity = Binder.clearCallingIdentity(); |
| 6210 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6211 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6212 | // may happen if the device does not support IMS. |
| 6213 | return null; |
| 6214 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6215 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | } finally { |
| 6217 | Binder.restoreCallingIdentity(identity); |
| 6218 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6219 | } |
| 6220 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6221 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6222 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6223 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6224 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6225 | * @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] | 6226 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6227 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6228 | * @param packageName The name of the package that the current configuration will be replaced |
| 6229 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6230 | * @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] | 6231 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6232 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6233 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6234 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6236 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6237 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6238 | final long identity = Binder.clearCallingIdentity(); |
| 6239 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6240 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6241 | // may happen if the device does not support IMS. |
| 6242 | return false; |
| 6243 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6244 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6245 | for (int featureType : featureTypes) { |
| 6246 | featureConfig.put(featureType, packageName); |
| 6247 | } |
| 6248 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6249 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6250 | } finally { |
| 6251 | Binder.restoreCallingIdentity(identity); |
| 6252 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6256 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6257 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6258 | * |
| 6259 | * This should only be used for testing. |
| 6260 | * |
| 6261 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6262 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6263 | */ |
| 6264 | @Override |
| 6265 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6266 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6267 | "clearCarrierImsServiceOverride"); |
| 6268 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6269 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6270 | |
| 6271 | final long identity = Binder.clearCallingIdentity(); |
| 6272 | try { |
| 6273 | if (mImsResolver == null) { |
| 6274 | // may happen if the device does not support IMS. |
| 6275 | return false; |
| 6276 | } |
| 6277 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6278 | } finally { |
| 6279 | Binder.restoreCallingIdentity(identity); |
| 6280 | } |
| 6281 | } |
| 6282 | |
| 6283 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6284 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6285 | * |
| 6286 | * @param slotId The slot that the ImsService is associated with. |
| 6287 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6288 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6289 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6290 | * @return the package name of the ImsService configuration. |
| 6291 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6292 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6293 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6294 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6295 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6296 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | final long identity = Binder.clearCallingIdentity(); |
| 6299 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6300 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6301 | // may happen if the device does not support IMS. |
| 6302 | return ""; |
| 6303 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6304 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6305 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6306 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6307 | } finally { |
| 6308 | Binder.restoreCallingIdentity(identity); |
| 6309 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6310 | } |
| 6311 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6312 | /** |
| 6313 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6314 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6315 | * @param callback A callback with an integer containing the |
| 6316 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6317 | */ |
| 6318 | @Override |
| 6319 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6320 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6321 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6322 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6323 | "IMS not available on device."); |
| 6324 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6325 | final long token = Binder.clearCallingIdentity(); |
| 6326 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6327 | int slotId = getSlotIndex(subId); |
| 6328 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6329 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6330 | + subId + "'"); |
| 6331 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6332 | } |
| 6333 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6334 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6335 | try { |
| 6336 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6337 | } catch (RemoteException e) { |
| 6338 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6339 | + "Ignore"); |
| 6340 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6341 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6342 | } catch (ImsException e) { |
| 6343 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6344 | } finally { |
| 6345 | Binder.restoreCallingIdentity(token); |
| 6346 | } |
| 6347 | } |
| 6348 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6349 | /** |
| 6350 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6351 | */ |
| 6352 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6353 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6354 | |
| 6355 | final long identity = Binder.clearCallingIdentity(); |
| 6356 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6357 | // NOTE: Before S, this method only set the default phone. |
| 6358 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6359 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6360 | phone.setImsRegistrationState(registered); |
| 6361 | } |
| 6362 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6363 | } finally { |
| 6364 | Binder.restoreCallingIdentity(identity); |
| 6365 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6369 | * Set the network selection mode to automatic. |
| 6370 | * |
| 6371 | */ |
| 6372 | @Override |
| 6373 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6375 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6376 | |
| 6377 | final long identity = Binder.clearCallingIdentity(); |
| 6378 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6379 | if (!isActiveSubscription(subId)) { |
| 6380 | return; |
| 6381 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6383 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6384 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6385 | } finally { |
| 6386 | Binder.restoreCallingIdentity(identity); |
| 6387 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6388 | } |
| 6389 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6390 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6391 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6392 | * |
| 6393 | * @param subId the id of the subscription. |
| 6394 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6395 | * the operator to attach to. |
| 6396 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6397 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6398 | * normal network selection next time. |
| 6399 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6400 | */ |
| 6401 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6402 | public boolean setNetworkSelectionModeManual( |
| 6403 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6405 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6406 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6407 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6408 | if (!isActiveSubscription(subId)) { |
| 6409 | return false; |
| 6410 | } |
| 6411 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6413 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6415 | if (DBG) { |
| 6416 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6417 | + " operator: " + operatorInfo); |
| 6418 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6419 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6420 | } finally { |
| 6421 | Binder.restoreCallingIdentity(identity); |
| 6422 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6423 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6424 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6425 | * Get the manual network selection |
| 6426 | * |
| 6427 | * @param subId the id of the subscription. |
| 6428 | * |
| 6429 | * @return the previously saved user selected PLMN |
| 6430 | */ |
| 6431 | @Override |
| 6432 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6433 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6434 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6435 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6436 | |
| 6437 | final long identity = Binder.clearCallingIdentity(); |
| 6438 | try { |
| 6439 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6440 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6441 | } |
| 6442 | |
| 6443 | final Phone phone = getPhone(subId); |
| 6444 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6445 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6446 | } |
| 6447 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6448 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6449 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6450 | } finally { |
| 6451 | Binder.restoreCallingIdentity(identity); |
| 6452 | } |
| 6453 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6454 | |
| 6455 | /** |
| 6456 | * Scans for available networks. |
| 6457 | */ |
| 6458 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6459 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6460 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6462 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6463 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6464 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6465 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6466 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6467 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6468 | .setCallingPid(Binder.getCallingPid()) |
| 6469 | .setCallingUid(Binder.getCallingUid()) |
| 6470 | .setMethod("getCellNetworkScanResults") |
| 6471 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6472 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6473 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6474 | .build()); |
| 6475 | switch (locationResult) { |
| 6476 | case DENIED_HARD: |
| 6477 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6478 | case DENIED_SOFT: |
| 6479 | return null; |
| 6480 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6481 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6482 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6483 | try { |
| 6484 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6485 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6486 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6487 | } finally { |
| 6488 | Binder.restoreCallingIdentity(identity); |
| 6489 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6493 | * Get the call forwarding info, given the call forwarding reason. |
| 6494 | */ |
| 6495 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6496 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6497 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6498 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6499 | long identity = Binder.clearCallingIdentity(); |
| 6500 | try { |
| 6501 | if (DBG) { |
| 6502 | log("getCallForwarding: subId " + subId |
| 6503 | + " callForwardingReason" + callForwardingReason); |
| 6504 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6505 | |
| 6506 | Phone phone = getPhone(subId); |
| 6507 | if (phone == null) { |
| 6508 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6509 | callback.onError( |
| 6510 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6511 | } catch (RemoteException e) { |
| 6512 | // ignore |
| 6513 | } |
| 6514 | return; |
| 6515 | } |
| 6516 | |
| 6517 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6518 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6519 | @Override |
| 6520 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6521 | try { |
| 6522 | callback.onCallForwardingInfoAvailable(info); |
| 6523 | } catch (RemoteException e) { |
| 6524 | // ignore |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | @Override |
| 6529 | public void onError(int error) { |
| 6530 | try { |
| 6531 | callback.onError(error); |
| 6532 | } catch (RemoteException e) { |
| 6533 | // ignore |
| 6534 | } |
| 6535 | } |
| 6536 | }); |
| 6537 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6538 | } finally { |
| 6539 | Binder.restoreCallingIdentity(identity); |
| 6540 | } |
| 6541 | } |
| 6542 | |
| 6543 | /** |
| 6544 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6545 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6546 | */ |
| 6547 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6548 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6549 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6550 | enforceModifyPermission(); |
| 6551 | long identity = Binder.clearCallingIdentity(); |
| 6552 | try { |
| 6553 | if (DBG) { |
| 6554 | log("setCallForwarding: subId " + subId |
| 6555 | + " callForwardingInfo" + callForwardingInfo); |
| 6556 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6557 | |
| 6558 | Phone phone = getPhone(subId); |
| 6559 | if (phone == null) { |
| 6560 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6561 | callback.accept( |
| 6562 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6563 | } catch (RemoteException e) { |
| 6564 | // ignore |
| 6565 | } |
| 6566 | return; |
| 6567 | } |
| 6568 | |
| 6569 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6570 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6571 | |
| 6572 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6573 | } finally { |
| 6574 | Binder.restoreCallingIdentity(identity); |
| 6575 | } |
| 6576 | } |
| 6577 | |
| 6578 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6579 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6580 | */ |
| 6581 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6582 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6583 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6584 | long identity = Binder.clearCallingIdentity(); |
| 6585 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6586 | Phone phone = getPhone(subId); |
| 6587 | if (phone == null) { |
| 6588 | try { |
| 6589 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6590 | } catch (RemoteException e) { |
| 6591 | // ignore |
| 6592 | } |
| 6593 | return; |
| 6594 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6595 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6596 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6597 | boolean requireUssd = c.getBoolean( |
| 6598 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6599 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6600 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6601 | if (requireUssd) { |
| 6602 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6603 | getSubscriptionCarrierId(subId)); |
| 6604 | String newUssdCommand = ""; |
| 6605 | try { |
| 6606 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6607 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6608 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6609 | } catch (NullPointerException e) { |
| 6610 | loge("Failed to generate USSD number" + e); |
| 6611 | } |
| 6612 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6613 | mMainThreadHandler, callback, carrierXmlParser, |
| 6614 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6615 | final String ussdCommand = newUssdCommand; |
| 6616 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6617 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6618 | }); |
| 6619 | } else { |
| 6620 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6621 | callback::accept); |
| 6622 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6623 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6624 | } finally { |
| 6625 | Binder.restoreCallingIdentity(identity); |
| 6626 | } |
| 6627 | } |
| 6628 | |
| 6629 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6630 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6631 | */ |
| 6632 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6633 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6634 | enforceModifyPermission(); |
| 6635 | long identity = Binder.clearCallingIdentity(); |
| 6636 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6637 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6638 | |
| 6639 | Phone phone = getPhone(subId); |
| 6640 | if (phone == null) { |
| 6641 | try { |
| 6642 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6643 | } catch (RemoteException e) { |
| 6644 | // ignore |
| 6645 | } |
| 6646 | return; |
| 6647 | } |
| 6648 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6649 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6650 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6651 | boolean requireUssd = c.getBoolean( |
| 6652 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6653 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6654 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6655 | if (requireUssd) { |
| 6656 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6657 | getSubscriptionCarrierId(subId)); |
| 6658 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6659 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6660 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6661 | String newUssdCommand = ""; |
| 6662 | try { |
| 6663 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6664 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6665 | .makeCommand(ssAction, null); |
| 6666 | } catch (NullPointerException e) { |
| 6667 | loge("Failed to generate USSD number" + e); |
| 6668 | } |
| 6669 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6670 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6671 | final String ussdCommand = newUssdCommand; |
| 6672 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6673 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6674 | }); |
| 6675 | } else { |
| 6676 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6677 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6678 | |
| 6679 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6680 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6681 | } finally { |
| 6682 | Binder.restoreCallingIdentity(identity); |
| 6683 | } |
| 6684 | } |
| 6685 | |
| 6686 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6687 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6688 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6689 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6690 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6691 | * location related information which will be sent if the caller already possess |
| 6692 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6693 | * @param request contains the radio access networks with bands/channels to scan |
| 6694 | * @param messenger callback messenger for scan results or errors |
| 6695 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6696 | * @return the id of the requested scan which can be used to stop the scan. |
| 6697 | */ |
| 6698 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6699 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6700 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6701 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6702 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6703 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6704 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6705 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6706 | if (!renounceFineLocationAccess) { |
| 6707 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6708 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6709 | .setCallingPackage(callingPackage) |
| 6710 | .setCallingFeatureId(callingFeatureId) |
| 6711 | .setCallingPid(Binder.getCallingPid()) |
| 6712 | .setCallingUid(Binder.getCallingUid()) |
| 6713 | .setMethod("requestNetworkScan") |
| 6714 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6715 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6716 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6717 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6718 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6719 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6720 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6721 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6722 | if (e != null) { |
| 6723 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6724 | throw e; |
| 6725 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6726 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6727 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6728 | } |
| 6729 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6730 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6731 | int callingUid = Binder.getCallingUid(); |
| 6732 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
| 6735 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6736 | renounceFineLocationAccess, request, messenger, binder, |
| 6737 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6738 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6739 | } finally { |
| 6740 | Binder.restoreCallingIdentity(identity); |
| 6741 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6742 | } |
| 6743 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6744 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6745 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6746 | boolean hasCarrierPriv; |
| 6747 | final long identity = Binder.clearCallingIdentity(); |
| 6748 | try { |
| 6749 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6750 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6751 | } finally { |
| 6752 | Binder.restoreCallingIdentity(identity); |
| 6753 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6754 | boolean hasNetworkScanPermission = |
| 6755 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6756 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6757 | |
| 6758 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6759 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6760 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6764 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6765 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6766 | return new SecurityException("Specific channels must not be" |
| 6767 | + " scanned without location access."); |
| 6768 | } |
| 6769 | } |
| 6770 | } |
| 6771 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6772 | return null; |
| 6773 | } |
| 6774 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6775 | /** |
| 6776 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6777 | * |
| 6778 | * @param subId id of the subscription |
| 6779 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6780 | */ |
| 6781 | @Override |
| 6782 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6784 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6785 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6786 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6787 | final long identity = Binder.clearCallingIdentity(); |
| 6788 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6789 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6790 | } finally { |
| 6791 | Binder.restoreCallingIdentity(identity); |
| 6792 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6793 | } |
| 6794 | |
| 6795 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6796 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6797 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6798 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6799 | */ |
| 6800 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6801 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6802 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6803 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6804 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6805 | |
| 6806 | final long identity = Binder.clearCallingIdentity(); |
| 6807 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6808 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6809 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6810 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6811 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6812 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6813 | } finally { |
| 6814 | Binder.restoreCallingIdentity(identity); |
| 6815 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6816 | } |
| 6817 | |
| 6818 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6819 | * Get the allowed network types for certain reason. |
| 6820 | * |
| 6821 | * @param subId the id of the subscription. |
| 6822 | * @param reason the reason the allowed network type change is taking place |
| 6823 | * @return the allowed network types. |
| 6824 | */ |
| 6825 | @Override |
| 6826 | public long getAllowedNetworkTypesForReason(int subId, |
| 6827 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6828 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6829 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6830 | final long identity = Binder.clearCallingIdentity(); |
| 6831 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6832 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6833 | } finally { |
| 6834 | Binder.restoreCallingIdentity(identity); |
| 6835 | } |
| 6836 | } |
| 6837 | |
| 6838 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6839 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6840 | * @param subId subscription id of the sim card |
| 6841 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6842 | * This can be passed following states |
| 6843 | * <ol> |
| 6844 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6845 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6846 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6847 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6848 | * </ol> |
| 6849 | * @return operation result. |
| 6850 | */ |
| 6851 | @Override |
| 6852 | public int setNrDualConnectivityState(int subId, |
| 6853 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6855 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6856 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6857 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6858 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6859 | } |
| 6860 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6861 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6862 | final long identity = Binder.clearCallingIdentity(); |
| 6863 | try { |
| 6864 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6865 | nrDualConnectivityState, subId, |
| 6866 | workSource); |
| 6867 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6868 | return result; |
| 6869 | } finally { |
| 6870 | Binder.restoreCallingIdentity(identity); |
| 6871 | } |
| 6872 | } |
| 6873 | |
| 6874 | /** |
| 6875 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6876 | * @return true if dual connectivity is enabled else false |
| 6877 | */ |
| 6878 | @Override |
| 6879 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6880 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6881 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6882 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6883 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6884 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6885 | return false; |
| 6886 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6887 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6888 | final long identity = Binder.clearCallingIdentity(); |
| 6889 | try { |
| 6890 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6891 | null, subId, workSource); |
| 6892 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6893 | return isEnabled; |
| 6894 | } finally { |
| 6895 | Binder.restoreCallingIdentity(identity); |
| 6896 | } |
| 6897 | } |
| 6898 | |
| 6899 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6900 | * Set the allowed network types of the device and |
| 6901 | * provide the reason triggering the allowed network change. |
| 6902 | * |
| 6903 | * @param subId the id of the subscription. |
| 6904 | * @param reason the reason the allowed network type change is taking place |
| 6905 | * @param allowedNetworkTypes the allowed network types. |
| 6906 | * @return true on success; false on any failure. |
| 6907 | */ |
| 6908 | @Override |
| 6909 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6910 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6911 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6913 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6914 | // If the caller only has carrier privileges, then they should not be able to override |
| 6915 | // any network types which were set for security reasons. |
| 6916 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6917 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6918 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6919 | throw new SecurityException( |
| 6920 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6921 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6922 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6923 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6924 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6925 | return false; |
| 6926 | } |
| 6927 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6928 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6929 | return false; |
| 6930 | } |
| 6931 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6932 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6933 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6934 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6935 | Phone phone = getPhone(subId); |
| 6936 | if (phone == null) { |
| 6937 | return false; |
| 6938 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6939 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6940 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6941 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6942 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6943 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6944 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6945 | final long identity = Binder.clearCallingIdentity(); |
| 6946 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6947 | Boolean success = (Boolean) sendRequest( |
| 6948 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6949 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6950 | |
| 6951 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6952 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6953 | } finally { |
| 6954 | Binder.restoreCallingIdentity(identity); |
| 6955 | } |
| 6956 | } |
| 6957 | |
| 6958 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6959 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6960 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6961 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6962 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6963 | * @hide |
| 6964 | */ |
| 6965 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6966 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6967 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6968 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6969 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6970 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6971 | if (phone != null) { |
| 6972 | return phone.hasMatchedTetherApnSetting(); |
| 6973 | } else { |
| 6974 | return false; |
| 6975 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6976 | } finally { |
| 6977 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6978 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6982 | * Get the user enabled state of Mobile Data. |
| 6983 | * |
| 6984 | * TODO: remove and use isUserDataEnabled. |
| 6985 | * This can't be removed now because some vendor codes |
| 6986 | * calls through ITelephony directly while they should |
| 6987 | * use TelephonyManager. |
| 6988 | * |
| 6989 | * @return true on enabled |
| 6990 | */ |
| 6991 | @Override |
| 6992 | public boolean getDataEnabled(int subId) { |
| 6993 | return isUserDataEnabled(subId); |
| 6994 | } |
| 6995 | |
| 6996 | /** |
| 6997 | * Get whether mobile data is enabled per user setting. |
| 6998 | * |
| 6999 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7000 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7001 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7002 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7003 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7004 | * |
| 7005 | * @return {@code true} if data is enabled else {@code false} |
| 7006 | */ |
| 7007 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7008 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7009 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7010 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7011 | try { |
| 7012 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7013 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7014 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7015 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7016 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7017 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7019 | mApp, subId, functionName); |
| 7020 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7021 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7022 | |
| 7023 | final long identity = Binder.clearCallingIdentity(); |
| 7024 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7025 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7026 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7027 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7028 | if (phone != null) { |
| 7029 | boolean retVal = phone.isUserDataEnabled(); |
| 7030 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7031 | return retVal; |
| 7032 | } else { |
| 7033 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7034 | return false; |
| 7035 | } |
| 7036 | } finally { |
| 7037 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7038 | } |
| 7039 | } |
| 7040 | |
| 7041 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7042 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7043 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7044 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7045 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7046 | * @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] | 7047 | */ |
| 7048 | @Override |
| 7049 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7050 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7051 | try { |
| 7052 | try { |
| 7053 | mApp.enforceCallingOrSelfPermission( |
| 7054 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7055 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7056 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7057 | try { |
| 7058 | mApp.enforceCallingOrSelfPermission( |
| 7059 | android.Manifest.permission.READ_PHONE_STATE, |
| 7060 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7061 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7062 | mApp.enforceCallingOrSelfPermission( |
| 7063 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7064 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7065 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7066 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7067 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7068 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7069 | |
| 7070 | final long identity = Binder.clearCallingIdentity(); |
| 7071 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7072 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7074 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7075 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7076 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7077 | return retVal; |
| 7078 | } else { |
| 7079 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7080 | return false; |
| 7081 | } |
| 7082 | } finally { |
| 7083 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7084 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7085 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7086 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7087 | /** |
| 7088 | * Check if data is enabled for a specific reason |
| 7089 | * @param subId Subscription index |
| 7090 | * @param reason the reason the data enable change is taking place |
| 7091 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7092 | */ |
| 7093 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7094 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7095 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7096 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7097 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7098 | try { |
| 7099 | mApp.enforceCallingOrSelfPermission( |
| 7100 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7101 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7102 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7103 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7104 | functionName); |
| 7105 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7106 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7107 | try { |
| 7108 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7109 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7110 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7111 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7112 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7113 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7114 | } |
| 7115 | |
| 7116 | |
| 7117 | final long identity = Binder.clearCallingIdentity(); |
| 7118 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7119 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7120 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7121 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7122 | + " reason=" + reason); |
| 7123 | } |
| 7124 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7125 | if (phone != null) { |
| 7126 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7127 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7128 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7129 | return retVal; |
| 7130 | } else { |
| 7131 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7132 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7133 | + subId + " retVal=false"); |
| 7134 | } |
| 7135 | return false; |
| 7136 | } |
| 7137 | } finally { |
| 7138 | Binder.restoreCallingIdentity(identity); |
| 7139 | } |
| 7140 | } |
| 7141 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7142 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7143 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7144 | // No permission needed; this only lets the caller inspect their own status. |
| 7145 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7146 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7147 | |
| 7148 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7149 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7150 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7151 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7152 | } |
| 7153 | |
| 7154 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7155 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7156 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7157 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7158 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7159 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7160 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7161 | if (cpt == null) { |
| 7162 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7163 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7164 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7165 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7169 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7170 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7171 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7172 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7173 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7174 | Phone phone = getPhone(subId); |
| 7175 | if (phone == null) { |
| 7176 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7177 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7178 | } |
| 7179 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7180 | if (cpt == null) { |
| 7181 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7182 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7183 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7184 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7185 | } |
| 7186 | |
| 7187 | @Override |
| 7188 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7189 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7190 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7191 | } |
| 7192 | |
| 7193 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7194 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7195 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7196 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7197 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7198 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7199 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7200 | if (phone == null) { |
| 7201 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7202 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7203 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7204 | if (cpt == null) { |
| 7205 | continue; |
| 7206 | } |
| 7207 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7208 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7209 | break; |
| 7210 | } |
| 7211 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7212 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7213 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7214 | |
| 7215 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7216 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7217 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7218 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7219 | if (phone == null) { |
| 7220 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7221 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7222 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7223 | if (cpt == null) { |
| 7224 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7225 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7226 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7227 | } |
| 7228 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7229 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7230 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7231 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7232 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7233 | if (phone == null) { |
| 7234 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7235 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7236 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7237 | if (cpt == null) { |
| 7238 | return Collections.emptyList(); |
| 7239 | } |
| 7240 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7241 | } |
| 7242 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7243 | @Override |
| 7244 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7245 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7246 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7247 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7248 | try { |
| 7249 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7250 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7251 | } |
| 7252 | } finally { |
| 7253 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7254 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7255 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7256 | } |
| 7257 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7258 | @Override |
| 7259 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7260 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7261 | |
| 7262 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7263 | if (phone == null) { |
| 7264 | return null; |
| 7265 | } |
| 7266 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7267 | if (cpt == null) { |
| 7268 | return null; |
| 7269 | } |
| 7270 | return cpt.getCarrierServicePackageName(); |
| 7271 | } |
| 7272 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7273 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7274 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7275 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7276 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7277 | return null; |
| 7278 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7279 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7280 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7281 | return null; |
| 7282 | } |
| 7283 | return iccId; |
| 7284 | } |
| 7285 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7286 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7287 | public void setCallComposerStatus(int subId, int status) { |
| 7288 | enforceModifyPermission(); |
| 7289 | |
| 7290 | final long identity = Binder.clearCallingIdentity(); |
| 7291 | try { |
| 7292 | Phone phone = getPhone(subId); |
| 7293 | if (phone != null) { |
| 7294 | Phone defaultPhone = phone.getImsPhone(); |
| 7295 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7296 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7297 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7298 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7299 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7300 | } |
| 7301 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7302 | } catch (ImsException e) { |
| 7303 | throw new ServiceSpecificException(e.getCode()); |
| 7304 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7305 | Binder.restoreCallingIdentity(identity); |
| 7306 | } |
| 7307 | } |
| 7308 | |
| 7309 | @Override |
| 7310 | public int getCallComposerStatus(int subId) { |
| 7311 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7312 | |
| 7313 | final long identity = Binder.clearCallingIdentity(); |
| 7314 | try { |
| 7315 | Phone phone = getPhone(subId); |
| 7316 | if (phone != null) { |
| 7317 | Phone defaultPhone = phone.getImsPhone(); |
| 7318 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7319 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7320 | return imsPhone.getCallComposerStatus(); |
| 7321 | } |
| 7322 | } |
| 7323 | } finally { |
| 7324 | Binder.restoreCallingIdentity(identity); |
| 7325 | } |
| 7326 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7327 | } |
| 7328 | |
| 7329 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7330 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7331 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7332 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7333 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7335 | final long identity = Binder.clearCallingIdentity(); |
| 7336 | try { |
| 7337 | final String iccId = getIccId(subId); |
| 7338 | final Phone phone = getPhone(subId); |
| 7339 | if (phone == null) { |
| 7340 | return false; |
| 7341 | } |
| 7342 | final String subscriberId = phone.getSubscriberId(); |
| 7343 | |
| 7344 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7345 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7346 | + subscriberId + " to " + number); |
| 7347 | } |
| 7348 | |
| 7349 | if (TextUtils.isEmpty(iccId)) { |
| 7350 | return false; |
| 7351 | } |
| 7352 | |
| 7353 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7354 | |
| 7355 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7356 | if (alphaTag == null) { |
| 7357 | editor.remove(alphaTagPrefKey); |
| 7358 | } else { |
| 7359 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7360 | } |
| 7361 | |
| 7362 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7363 | // track all merged IMSIs based on line number |
| 7364 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7365 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7366 | if (number == null) { |
| 7367 | editor.remove(numberPrefKey); |
| 7368 | editor.remove(subscriberPrefKey); |
| 7369 | } else { |
| 7370 | editor.putString(numberPrefKey, number); |
| 7371 | editor.putString(subscriberPrefKey, subscriberId); |
| 7372 | } |
| 7373 | |
| 7374 | editor.commit(); |
| 7375 | return true; |
| 7376 | } finally { |
| 7377 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7378 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7382 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7383 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7384 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7385 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7386 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7387 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7388 | return null; |
| 7389 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7390 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7391 | final long identity = Binder.clearCallingIdentity(); |
| 7392 | try { |
| 7393 | String iccId = getIccId(subId); |
| 7394 | if (iccId != null) { |
| 7395 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7396 | if (DBG_MERGE) { |
| 7397 | log("getLine1NumberForDisplay returning " |
| 7398 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7399 | } |
| 7400 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7401 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7402 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7403 | return null; |
| 7404 | } finally { |
| 7405 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7406 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7407 | } |
| 7408 | |
| 7409 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7410 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7411 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7412 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7413 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7414 | return null; |
| 7415 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7417 | final long identity = Binder.clearCallingIdentity(); |
| 7418 | try { |
| 7419 | String iccId = getIccId(subId); |
| 7420 | if (iccId != null) { |
| 7421 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7422 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7423 | } |
| 7424 | return null; |
| 7425 | } finally { |
| 7426 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7427 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7428 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7429 | |
| 7430 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7431 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7432 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7433 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7434 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7435 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7436 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7437 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7438 | return null; |
| 7439 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7440 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7441 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7442 | // the process, where TelephonyManager was instantiated. |
| 7443 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7444 | final long identity = Binder.clearCallingIdentity(); |
| 7445 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7446 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7447 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7448 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7449 | |
| 7450 | // Figure out what subscribers are currently active |
| 7451 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7452 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7453 | // Only consider subs which match the current subId |
| 7454 | // This logic can be simplified. See b/131189269 for progress. |
| 7455 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7456 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7457 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7458 | |
| 7459 | // First pass, find a number override for an active subscriber |
| 7460 | String mergeNumber = null; |
| 7461 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7462 | for (String key : prefs.keySet()) { |
| 7463 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7464 | final String subscriberId = (String) prefs.get(key); |
| 7465 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7466 | final String iccId = key.substring( |
| 7467 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7468 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7469 | mergeNumber = (String) prefs.get(numberKey); |
| 7470 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7471 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7472 | + " for active subscriber " + subscriberId); |
| 7473 | } |
| 7474 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7475 | break; |
| 7476 | } |
| 7477 | } |
| 7478 | } |
| 7479 | } |
| 7480 | |
| 7481 | // Shortcut when no active merged subscribers |
| 7482 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7483 | return null; |
| 7484 | } |
| 7485 | |
| 7486 | // Second pass, find all subscribers under that line override |
| 7487 | final ArraySet<String> result = new ArraySet<>(); |
| 7488 | for (String key : prefs.keySet()) { |
| 7489 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7490 | final String number = (String) prefs.get(key); |
| 7491 | if (mergeNumber.equals(number)) { |
| 7492 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7493 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7494 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7495 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7496 | result.add(subscriberId); |
| 7497 | } |
| 7498 | } |
| 7499 | } |
| 7500 | } |
| 7501 | |
| 7502 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7503 | Arrays.sort(resultArray); |
| 7504 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7505 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7507 | } |
| 7508 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7509 | } finally { |
| 7510 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7511 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7512 | } |
| 7513 | |
| 7514 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7515 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7516 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7517 | |
| 7518 | final long identity = Binder.clearCallingIdentity(); |
| 7519 | try { |
| 7520 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7521 | TelephonyManager.class); |
| 7522 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7523 | if (subscriberId == null) { |
| 7524 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7525 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7526 | + subId); |
| 7527 | } |
| 7528 | return null; |
| 7529 | } |
| 7530 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7531 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7532 | .getSubscriptionInfo(subId); |
| 7533 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7534 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7535 | if (groupUuid == null) { |
| 7536 | return new String[]{subscriberId}; |
| 7537 | } |
| 7538 | |
| 7539 | // Get all subscriberIds from the group. |
| 7540 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7541 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7542 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7543 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7544 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7545 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7546 | if (subscriberId != null) { |
| 7547 | mergedSubscriberIds.add(subscriberId); |
| 7548 | } |
| 7549 | } |
| 7550 | |
| 7551 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7552 | } finally { |
| 7553 | Binder.restoreCallingIdentity(identity); |
| 7554 | |
| 7555 | } |
| 7556 | } |
| 7557 | |
| 7558 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7559 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7560 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7561 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7562 | |
| 7563 | final long identity = Binder.clearCallingIdentity(); |
| 7564 | try { |
| 7565 | final Phone phone = getPhone(subId); |
| 7566 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7567 | } finally { |
| 7568 | Binder.restoreCallingIdentity(identity); |
| 7569 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7570 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7571 | |
| 7572 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7573 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7574 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7575 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7576 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7577 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7578 | |
| 7579 | final long identity = Binder.clearCallingIdentity(); |
| 7580 | try { |
| 7581 | final Phone phone = getPhone(subId); |
| 7582 | if (phone == null) { |
| 7583 | return false; |
| 7584 | } |
| 7585 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7586 | cdmaNonRoamingList); |
| 7587 | } finally { |
| 7588 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7589 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7590 | } |
| 7591 | |
| 7592 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7593 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7594 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7595 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7596 | if (phone == null) { |
| 7597 | return raf; |
| 7598 | } |
| 7599 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7600 | try { |
| 7601 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7602 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7603 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7604 | } catch (SecurityException e) { |
| 7605 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7606 | throw e; |
| 7607 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7608 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7609 | final long identity = Binder.clearCallingIdentity(); |
| 7610 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7611 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7612 | } finally { |
| 7613 | Binder.restoreCallingIdentity(identity); |
| 7614 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7615 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7616 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7617 | |
| 7618 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7619 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7620 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7621 | try { |
| 7622 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7623 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7624 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7625 | } |
| 7626 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7627 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7628 | } |
| 7629 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7630 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7631 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7632 | throw new SecurityException("App must be the dialer role holder to" |
| 7633 | + " upload a call composer pic"); |
| 7634 | } |
| 7635 | |
| 7636 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7637 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7638 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7639 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7640 | boolean readUntilEnd = false; |
| 7641 | int totalBytesRead = 0; |
| 7642 | byte[] buffer = new byte[16 * 1024]; |
| 7643 | while (true) { |
| 7644 | int numRead; |
| 7645 | try { |
| 7646 | numRead = input.read(buffer); |
| 7647 | } catch (IOException e) { |
| 7648 | try { |
| 7649 | fd.checkError(); |
| 7650 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7651 | null); |
| 7652 | } catch (IOException e1) { |
| 7653 | // This means that the other side closed explicitly with an error. If this |
| 7654 | // happens, log and ignore. |
| 7655 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7656 | } |
| 7657 | break; |
| 7658 | } |
| 7659 | if (numRead == -1) { |
| 7660 | readUntilEnd = true; |
| 7661 | break; |
| 7662 | } |
| 7663 | totalBytesRead += numRead; |
| 7664 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7665 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7666 | try { |
| 7667 | input.close(); |
| 7668 | } catch (IOException e) { |
| 7669 | // ignore |
| 7670 | } |
| 7671 | break; |
| 7672 | } |
| 7673 | output.write(buffer, 0, numRead); |
| 7674 | } |
| 7675 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7676 | // close is above, where the picture size is too big. |
| 7677 | |
| 7678 | try { |
| 7679 | fd.checkError(); |
| 7680 | } catch (IOException e) { |
| 7681 | loge("Remote end for call composer closed with an error: " + e); |
| 7682 | return; |
| 7683 | } |
| 7684 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7685 | if (!readUntilEnd) { |
| 7686 | loge("Did not finish reading entire image; aborting"); |
| 7687 | return; |
| 7688 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7689 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7690 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7691 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7692 | new CallComposerPictureTransfer.Factory() {}, |
| 7693 | imageData, |
| 7694 | (result) -> { |
| 7695 | if (result.first != null) { |
| 7696 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7697 | Bundle outputResult = new Bundle(); |
| 7698 | outputResult.putParcelable( |
| 7699 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7700 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7701 | outputResult); |
| 7702 | } else { |
| 7703 | callback.send(result.second, null); |
| 7704 | } |
| 7705 | } |
| 7706 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7707 | }); |
| 7708 | } |
| 7709 | |
| 7710 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7711 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7712 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7713 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7714 | |
| 7715 | final long identity = Binder.clearCallingIdentity(); |
| 7716 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7717 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7718 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7719 | } finally { |
| 7720 | Binder.restoreCallingIdentity(identity); |
| 7721 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7722 | } |
| 7723 | |
| 7724 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7725 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7726 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7727 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7728 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7729 | return false; |
| 7730 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7731 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | final long identity = Binder.clearCallingIdentity(); |
| 7733 | try { |
| 7734 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7735 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7736 | // In the long run, we may instead need to check if there exists a connection service |
| 7737 | // which can support video calling. |
| 7738 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7739 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7740 | return imsManager.isVtEnabledByPlatform() |
| 7741 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7742 | && imsManager.isVtEnabledByUser(); |
| 7743 | } finally { |
| 7744 | Binder.restoreCallingIdentity(identity); |
| 7745 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7746 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7747 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7748 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7749 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7750 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7751 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7752 | mApp, subId, callingPackage, callingFeatureId, |
| 7753 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7754 | return false; |
| 7755 | } |
| 7756 | |
| 7757 | final long identity = Binder.clearCallingIdentity(); |
| 7758 | try { |
| 7759 | CarrierConfigManager configManager = |
| 7760 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7761 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7762 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7763 | } finally { |
| 7764 | Binder.restoreCallingIdentity(identity); |
| 7765 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7766 | } |
| 7767 | |
| 7768 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7769 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7770 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7771 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | return false; |
| 7773 | } |
| 7774 | |
| 7775 | final long identity = Binder.clearCallingIdentity(); |
| 7776 | try { |
| 7777 | CarrierConfigManager configManager = |
| 7778 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7779 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7780 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7781 | } finally { |
| 7782 | Binder.restoreCallingIdentity(identity); |
| 7783 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7784 | } |
| 7785 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7786 | @Override |
| 7787 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7788 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7789 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7790 | } |
| 7791 | |
| 7792 | @Override |
| 7793 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7794 | final long identity = Binder.clearCallingIdentity(); |
| 7795 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7796 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | } finally { |
| 7798 | Binder.restoreCallingIdentity(identity); |
| 7799 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7800 | } |
| 7801 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7802 | /** |
| 7803 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7804 | * support for the feature and device firmware support. |
| 7805 | * |
| 7806 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7807 | */ |
| 7808 | @Override |
| 7809 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7810 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7811 | final Phone phone = getPhone(subscriptionId); |
| 7812 | if (phone == null) { |
| 7813 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7814 | return false; |
| 7815 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7816 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7817 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7818 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7819 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7820 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7821 | return isCarrierSupported && isDeviceSupported; |
| 7822 | } finally { |
| 7823 | Binder.restoreCallingIdentity(identity); |
| 7824 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7825 | } |
| 7826 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7827 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7828 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7829 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7830 | * 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] | 7831 | */ |
| 7832 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7833 | final long identity = Binder.clearCallingIdentity(); |
| 7834 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7835 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7836 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7837 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7838 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7839 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7840 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7841 | } finally { |
| 7842 | Binder.restoreCallingIdentity(identity); |
| 7843 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7844 | } |
| 7845 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7846 | @Deprecated |
| 7847 | @Override |
| 7848 | public String getDeviceId(String callingPackage) { |
| 7849 | return getDeviceIdWithFeature(callingPackage, null); |
| 7850 | } |
| 7851 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7852 | /** |
| 7853 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7854 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7855 | * |
| 7856 | * <p>Requires Permission: |
| 7857 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7858 | */ |
| 7859 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7860 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7861 | try { |
| 7862 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7863 | } catch (SecurityException se) { |
| 7864 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7865 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7866 | + Binder.getCallingUid()); |
| 7867 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7868 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7869 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7870 | return null; |
| 7871 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7872 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7873 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7874 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7875 | return null; |
| 7876 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7877 | |
| 7878 | final long identity = Binder.clearCallingIdentity(); |
| 7879 | try { |
| 7880 | return phone.getDeviceId(); |
| 7881 | } finally { |
| 7882 | Binder.restoreCallingIdentity(identity); |
| 7883 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7884 | } |
| 7885 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7886 | /** |
| 7887 | * {@hide} |
| 7888 | * Returns the IMS Registration Status on a particular subid |
| 7889 | * |
| 7890 | * @param subId |
| 7891 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7892 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7893 | Phone phone = getPhone(subId); |
| 7894 | if (phone != null) { |
| 7895 | return phone.isImsRegistered(); |
| 7896 | } else { |
| 7897 | return false; |
| 7898 | } |
| 7899 | } |
| 7900 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7901 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7902 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7903 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7904 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7905 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7906 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7907 | } |
| 7908 | final long identity = Binder.clearCallingIdentity(); |
| 7909 | try { |
| 7910 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7911 | } finally { |
| 7912 | Binder.restoreCallingIdentity(identity); |
| 7913 | } |
| 7914 | } |
| 7915 | |
| 7916 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7917 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7918 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7919 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7920 | mApp, |
| 7921 | subscriptionId, |
| 7922 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7923 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7924 | final long identity = Binder.clearCallingIdentity(); |
| 7925 | try { |
| 7926 | Phone phone = getPhone(subscriptionId); |
| 7927 | if (phone == null) { |
| 7928 | return null; |
| 7929 | } |
| 7930 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7931 | } finally { |
| 7932 | Binder.restoreCallingIdentity(identity); |
| 7933 | } |
| 7934 | } |
| 7935 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7936 | /** |
| 7937 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7938 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7939 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7940 | final long identity = Binder.clearCallingIdentity(); |
| 7941 | try { |
| 7942 | Phone phone = getPhone(subId); |
| 7943 | if (phone != null) { |
| 7944 | return phone.isWifiCallingEnabled(); |
| 7945 | } else { |
| 7946 | return false; |
| 7947 | } |
| 7948 | } finally { |
| 7949 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7950 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7951 | } |
| 7952 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7953 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7954 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7955 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7956 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7957 | final long identity = Binder.clearCallingIdentity(); |
| 7958 | try { |
| 7959 | Phone phone = getPhone(subId); |
| 7960 | if (phone != null) { |
| 7961 | return phone.isVideoEnabled(); |
| 7962 | } else { |
| 7963 | return false; |
| 7964 | } |
| 7965 | } finally { |
| 7966 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7967 | } |
| 7968 | } |
| 7969 | |
| 7970 | /** |
| 7971 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7972 | * defined in {@link ImsRegistrationImplBase}. |
| 7973 | */ |
| 7974 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7975 | final long identity = Binder.clearCallingIdentity(); |
| 7976 | try { |
| 7977 | Phone phone = getPhone(subId); |
| 7978 | if (phone != null) { |
| 7979 | return phone.getImsRegistrationTech(); |
| 7980 | } else { |
| 7981 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7982 | } |
| 7983 | } finally { |
| 7984 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7985 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7986 | } |
| 7987 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7988 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7989 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7990 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7991 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7992 | return; |
| 7993 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7994 | Phone defaultPhone = getDefaultPhone(); |
| 7995 | if (defaultPhone != null) { |
| 7996 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7997 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7998 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7999 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8000 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8001 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8002 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8003 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8004 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8005 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8006 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8007 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8008 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8009 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8010 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8011 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8012 | // There has been issues when Sms raw table somehow stores orphan |
| 8013 | // fragments. They lead to garbled message when new fragments come |
| 8014 | // in and combined with those stale ones. In case this happens again, |
| 8015 | // user can reset all network settings which will clean up this table. |
| 8016 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8017 | // Clean up IMS settings as well here. |
| 8018 | int slotId = getSlotIndex(subId); |
| 8019 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8020 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8021 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8022 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8023 | if (defaultPhone == null) { |
| 8024 | return; |
| 8025 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8026 | // Erase modem config if erase modem on network setting is enabled. |
| 8027 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8028 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8029 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8030 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8031 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8032 | |
| 8033 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8034 | } finally { |
| 8035 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8036 | } |
| 8037 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8038 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8039 | @VisibleForTesting |
| 8040 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8041 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8042 | return; |
| 8043 | } |
| 8044 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8045 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8046 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8047 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8048 | "user=" + defaultNetworkType); |
| 8049 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8050 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8051 | defaultNetworkType, null); |
| 8052 | } |
| 8053 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8054 | private void cleanUpSmsRawTable(Context context) { |
| 8055 | ContentResolver resolver = context.getContentResolver(); |
| 8056 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8057 | resolver.delete(uri, null, null); |
| 8058 | } |
| 8059 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8060 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8061 | public String getSimLocaleForSubscriber(int subId) { |
| 8062 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8063 | final Phone phone = getPhone(subId); |
| 8064 | if (phone == null) { |
| 8065 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8066 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8067 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8068 | final long identity = Binder.clearCallingIdentity(); |
| 8069 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8070 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8071 | phone.getContext().getOpPackageName(), |
| 8072 | phone.getContext().getAttributionTag()); |
| 8073 | if (info == null) { |
| 8074 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8075 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8076 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8077 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8078 | // preferences (EF-PL and EF-LI)... |
| 8079 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8080 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8081 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8082 | if (localeFromDefaultSim != null) { |
| 8083 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8084 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8085 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8086 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8087 | } else { |
| 8088 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8089 | } |
| 8090 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8091 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8092 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8093 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8094 | // the SIM and carrier preferences does not include a country we add the country |
| 8095 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8096 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8097 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8098 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8099 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8100 | } |
| 8101 | |
| 8102 | if (DBG) log("No locale found - returning null"); |
| 8103 | return null; |
| 8104 | } finally { |
| 8105 | Binder.restoreCallingIdentity(identity); |
| 8106 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8107 | } |
| 8108 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8109 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8110 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8111 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8112 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8113 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8114 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8115 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8116 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8117 | return localeTag; |
| 8118 | } |
| 8119 | } |
| 8120 | return inputLocale.toLanguageTag(); |
| 8121 | } |
| 8122 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8123 | /** |
| 8124 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8125 | */ |
| 8126 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8127 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8128 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8129 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8130 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8131 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8132 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8133 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8134 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8135 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8136 | * representing the state of the modem. |
| 8137 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8138 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8139 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8140 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8141 | */ |
| 8142 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8143 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8144 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8145 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8146 | |
| 8147 | final long identity = Binder.clearCallingIdentity(); |
| 8148 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8149 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8150 | } finally { |
| 8151 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8152 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8153 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8154 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8155 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8156 | // less than total activity duration. |
| 8157 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8158 | if (info == null) { |
| 8159 | return false; |
| 8160 | } |
| 8161 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8162 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8163 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8164 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8165 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8166 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8167 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8168 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8169 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8170 | } |
| 8171 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8172 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8173 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8174 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8175 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8176 | |
| 8177 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8178 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8179 | } |
| 8180 | |
| 8181 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8182 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8183 | rat, |
| 8184 | freq, |
| 8185 | info.getReceiveTimeMillis(rat, freq) |
| 8186 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8187 | } |
| 8188 | |
| 8189 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8190 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8191 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8192 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8193 | |
| 8194 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8195 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8196 | } |
| 8197 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8198 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8199 | rat, |
| 8200 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8201 | } |
| 8202 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8203 | /** |
| 8204 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8205 | * @param info recent ModemActivityInfo |
| 8206 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8207 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8208 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8209 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8210 | boolean matched; |
| 8211 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8212 | matched = false; |
| 8213 | int rat = info.getSpecificInfoRat(i); |
| 8214 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8215 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8216 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8217 | //if it already exists |
| 8218 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8219 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8220 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8221 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8222 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8223 | updateLastModemActivityInfo(info, rat, freq); |
| 8224 | matched = true; |
| 8225 | } |
| 8226 | } else { |
| 8227 | updateLastModemActivityInfo(info, rat); |
| 8228 | matched = true; |
| 8229 | } |
| 8230 | } |
| 8231 | } |
| 8232 | |
| 8233 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8234 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8235 | new ActivityStatsTechSpecificInfo( |
| 8236 | rat, |
| 8237 | freq, |
| 8238 | info.getTransmitTimeMillis(rat, freq), |
| 8239 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8240 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8241 | } |
| 8242 | } |
| 8243 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8244 | mLastModemActivitySpecificInfo = |
| 8245 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8246 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8247 | |
| 8248 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8249 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8250 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8251 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8252 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8253 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8254 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8255 | |
| 8256 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8257 | new ModemActivityInfo( |
| 8258 | mLastModemActivityInfo.getTimestampMillis(), |
| 8259 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8260 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8261 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8262 | } |
| 8263 | |
| 8264 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8265 | ActivityStatsTechSpecificInfo[] info) { |
| 8266 | int infoSize = info.length; |
| 8267 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8268 | for (int i = 0; i < infoSize; i++) { |
| 8269 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8270 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8271 | info[i].getTransmitTimeMillis(), |
| 8272 | (int) info[i].getReceiveTimeMillis()); |
| 8273 | } |
| 8274 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8275 | } |
| 8276 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8277 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8278 | * Returns the service state information on specified subscription. |
| 8279 | */ |
| 8280 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8281 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8282 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8283 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8284 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8285 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8286 | return null; |
| 8287 | } |
| 8288 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8289 | boolean hasFinePermission = false; |
| 8290 | boolean hasCoarsePermission = false; |
| 8291 | if (!renounceFineLocationAccess) { |
| 8292 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8293 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8294 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8295 | .setCallingPackage(callingPackage) |
| 8296 | .setCallingFeatureId(callingFeatureId) |
| 8297 | .setCallingPid(Binder.getCallingPid()) |
| 8298 | .setCallingUid(Binder.getCallingUid()) |
| 8299 | .setMethod("getServiceStateForSubscriber") |
| 8300 | .setLogAsInfo(true) |
| 8301 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8302 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8303 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8304 | .build()); |
| 8305 | hasFinePermission = |
| 8306 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8307 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8308 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8309 | if (!renounceCoarseLocationAccess) { |
| 8310 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8311 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8312 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8313 | .setCallingPackage(callingPackage) |
| 8314 | .setCallingFeatureId(callingFeatureId) |
| 8315 | .setCallingPid(Binder.getCallingPid()) |
| 8316 | .setCallingUid(Binder.getCallingUid()) |
| 8317 | .setMethod("getServiceStateForSubscriber") |
| 8318 | .setLogAsInfo(true) |
| 8319 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8320 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8321 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8322 | .build()); |
| 8323 | hasCoarsePermission = |
| 8324 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8325 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8326 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8327 | final Phone phone = getPhone(subId); |
| 8328 | if (phone == null) { |
| 8329 | return null; |
| 8330 | } |
| 8331 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8332 | final long identity = Binder.clearCallingIdentity(); |
| 8333 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8334 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8335 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8336 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8337 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8338 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8339 | .getSubscriptionInfoInternal(subId); |
| 8340 | if (subInfo == null || !subInfo.isActive()) { |
| 8341 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8342 | + "subId=" + subId); |
| 8343 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8344 | } |
| 8345 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8346 | ServiceState ss = phone.getServiceState(); |
| 8347 | |
| 8348 | // Scrub out the location info in ServiceState depending on what level of access |
| 8349 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8350 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8351 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8352 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8353 | } finally { |
| 8354 | Binder.restoreCallingIdentity(identity); |
| 8355 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8356 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8357 | |
| 8358 | /** |
| 8359 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8360 | * |
| 8361 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8362 | * voicemail ringtone. |
| 8363 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8364 | * PhoneAccount. |
| 8365 | */ |
| 8366 | @Override |
| 8367 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8368 | final long identity = Binder.clearCallingIdentity(); |
| 8369 | try { |
| 8370 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8371 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8372 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8373 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8374 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8375 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8376 | } finally { |
| 8377 | Binder.restoreCallingIdentity(identity); |
| 8378 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8379 | } |
| 8380 | |
| 8381 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8382 | * Sets the per-account voicemail ringtone. |
| 8383 | * |
| 8384 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8385 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8386 | * |
| 8387 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8388 | * voicemail ringtone. |
| 8389 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8390 | * PhoneAccount. |
| 8391 | */ |
| 8392 | @Override |
| 8393 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8394 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8395 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8396 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8397 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8398 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8400 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8401 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8402 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8403 | |
| 8404 | final long identity = Binder.clearCallingIdentity(); |
| 8405 | try { |
| 8406 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8407 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8408 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8409 | } |
| 8410 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8411 | } finally { |
| 8412 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8413 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8414 | } |
| 8415 | |
| 8416 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8417 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8418 | * |
| 8419 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8420 | * voicemail vibration setting. |
| 8421 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8422 | */ |
| 8423 | @Override |
| 8424 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8425 | final long identity = Binder.clearCallingIdentity(); |
| 8426 | try { |
| 8427 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8428 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8429 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8430 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8432 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8433 | } finally { |
| 8434 | Binder.restoreCallingIdentity(identity); |
| 8435 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8436 | } |
| 8437 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8438 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8439 | * Sets the per-account voicemail vibration. |
| 8440 | * |
| 8441 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8442 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8443 | * |
| 8444 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8445 | * voicemail vibration setting. |
| 8446 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8447 | * specific PhoneAccount. |
| 8448 | */ |
| 8449 | @Override |
| 8450 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8451 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8452 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8453 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8454 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8455 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8456 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8457 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8458 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8459 | } |
| 8460 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8461 | final long identity = Binder.clearCallingIdentity(); |
| 8462 | try { |
| 8463 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8464 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8465 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8466 | } |
| 8467 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8468 | } finally { |
| 8469 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8470 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8471 | } |
| 8472 | |
| 8473 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8474 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8475 | * |
| 8476 | * @throws SecurityException if the caller does not have the required permission |
| 8477 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8478 | @VisibleForTesting |
| 8479 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8480 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8481 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8482 | } |
| 8483 | |
| 8484 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8485 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8486 | * permission. |
| 8487 | * |
| 8488 | * @throws SecurityException if the caller does not have the required permission |
| 8489 | */ |
| 8490 | private void enforceSendSmsPermission() { |
| 8491 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8492 | } |
| 8493 | |
| 8494 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8495 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8496 | * users permission. |
| 8497 | * |
| 8498 | * @throws SecurityException if the caller does not have the required permission |
| 8499 | */ |
| 8500 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8501 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8502 | } |
| 8503 | |
| 8504 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8505 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8506 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8507 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8508 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8509 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8510 | final long identity = Binder.clearCallingIdentity(); |
| 8511 | try { |
| 8512 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8513 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8514 | if (componentName == null) { |
| 8515 | throw new SecurityException( |
| 8516 | "Caller not current active visual voicemail package[null]"); |
| 8517 | } |
| 8518 | String vvmPackage = componentName.getPackageName(); |
| 8519 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8520 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8521 | } |
| 8522 | } finally { |
| 8523 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8524 | } |
| 8525 | } |
| 8526 | |
| 8527 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8528 | * Return the application ID for the app type. |
| 8529 | * |
| 8530 | * @param subId the subscription ID that this request applies to. |
| 8531 | * @param appType the uicc app type. |
| 8532 | * @return Application ID for specificied app type, or null if no uicc. |
| 8533 | */ |
| 8534 | @Override |
| 8535 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8536 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8537 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8538 | |
| 8539 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8540 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8541 | if (phone == null) { |
| 8542 | return null; |
| 8543 | } |
| 8544 | String aid = null; |
| 8545 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8546 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8547 | .getApplicationByType(appType).getAid(); |
| 8548 | } catch (Exception e) { |
| 8549 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8550 | } |
| 8551 | return aid; |
| 8552 | } finally { |
| 8553 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8554 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8555 | } |
| 8556 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8557 | /** |
| 8558 | * Return the Electronic Serial Number. |
| 8559 | * |
| 8560 | * @param subId the subscription ID that this request applies to. |
| 8561 | * @return ESN or null if error. |
| 8562 | */ |
| 8563 | @Override |
| 8564 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8565 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8566 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8567 | |
| 8568 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8569 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8570 | if (phone == null) { |
| 8571 | return null; |
| 8572 | } |
| 8573 | String esn = null; |
| 8574 | try { |
| 8575 | esn = phone.getEsn(); |
| 8576 | } catch (Exception e) { |
| 8577 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8578 | } |
| 8579 | return esn; |
| 8580 | } finally { |
| 8581 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8582 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8583 | } |
| 8584 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8585 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8586 | * Return the Preferred Roaming List Version. |
| 8587 | * |
| 8588 | * @param subId the subscription ID that this request applies to. |
| 8589 | * @return PRLVersion or null if error. |
| 8590 | */ |
| 8591 | @Override |
| 8592 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8593 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8594 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8595 | |
| 8596 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8597 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8598 | if (phone == null) { |
| 8599 | return null; |
| 8600 | } |
| 8601 | String cdmaPrlVersion = null; |
| 8602 | try { |
| 8603 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8604 | } catch (Exception e) { |
| 8605 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8606 | } |
| 8607 | return cdmaPrlVersion; |
| 8608 | } finally { |
| 8609 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8610 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8611 | } |
| 8612 | |
| 8613 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8614 | * Get snapshot of Telephony histograms |
| 8615 | * @return List of Telephony histograms |
| 8616 | * @hide |
| 8617 | */ |
| 8618 | @Override |
| 8619 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8621 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8622 | |
| 8623 | final long identity = Binder.clearCallingIdentity(); |
| 8624 | try { |
| 8625 | return RIL.getTelephonyRILTimingHistograms(); |
| 8626 | } finally { |
| 8627 | Binder.restoreCallingIdentity(identity); |
| 8628 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8629 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8630 | |
| 8631 | /** |
| 8632 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8633 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8634 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8635 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8636 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8637 | * @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] | 8638 | */ |
| 8639 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8640 | @TelephonyManager.SetCarrierRestrictionResult |
| 8641 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8642 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8643 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8644 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8645 | if (carrierRestrictionRules == null) { |
| 8646 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8647 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8648 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8649 | final long identity = Binder.clearCallingIdentity(); |
| 8650 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8651 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8652 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8653 | } finally { |
| 8654 | Binder.restoreCallingIdentity(identity); |
| 8655 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8656 | } |
| 8657 | |
| 8658 | /** |
| 8659 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8660 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8661 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8662 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8663 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8664 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8665 | */ |
| 8666 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8667 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8668 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8669 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8670 | |
| 8671 | final long identity = Binder.clearCallingIdentity(); |
| 8672 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8673 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8674 | if (response instanceof CarrierRestrictionRules) { |
| 8675 | return (CarrierRestrictionRules) response; |
| 8676 | } |
| 8677 | // Response is an Exception of some kind, |
| 8678 | // which is signalled to the user as a NULL retval |
| 8679 | return null; |
| 8680 | } catch (Exception e) { |
| 8681 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8682 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8683 | } finally { |
| 8684 | Binder.restoreCallingIdentity(identity); |
| 8685 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8686 | } |
| 8687 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8688 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8689 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8690 | * through the callback. |
| 8691 | * |
| 8692 | * @param callback The callback that will be used to send the result. |
| 8693 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8694 | * the caller is not allowlisted. |
| 8695 | */ |
| 8696 | @Override |
| 8697 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8698 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8699 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8700 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8701 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8702 | throw new SecurityException("Not an authorized caller"); |
| 8703 | } |
| 8704 | final long identity = Binder.clearCallingIdentity(); |
| 8705 | try { |
| 8706 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8707 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8708 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8709 | } finally { |
| 8710 | Binder.restoreCallingIdentity(identity); |
| 8711 | } |
| 8712 | } |
| 8713 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 8714 | @Override |
| 8715 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 8716 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 8717 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8718 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 8719 | } |
| 8720 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8721 | @VisibleForTesting |
| 8722 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8723 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8724 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8725 | } |
| 8726 | |
| 8727 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8728 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8729 | * @param subId the subscription ID that this action applies to. |
| 8730 | * @param enabled control enable or disable radio. |
| 8731 | * {@hide} |
| 8732 | */ |
| 8733 | @Override |
| 8734 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8735 | enforceModifyPermission(); |
| 8736 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8737 | |
| 8738 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8739 | if (phone == null) { |
| 8740 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8741 | return; |
| 8742 | } |
| 8743 | try { |
| 8744 | phone.carrierActionSetRadioEnabled(enabled); |
| 8745 | } catch (Exception e) { |
| 8746 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8747 | } finally { |
| 8748 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8749 | } |
| 8750 | } |
| 8751 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8752 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8753 | * Enable or disable Voice over NR (VoNR) |
| 8754 | * @param subId the subscription ID that this action applies to. |
| 8755 | * @param enabled enable or disable VoNR. |
| 8756 | * @return operation result. |
| 8757 | */ |
| 8758 | @Override |
| 8759 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8760 | enforceModifyPermission(); |
| 8761 | final Phone phone = getPhone(subId); |
| 8762 | |
| 8763 | final long identity = Binder.clearCallingIdentity(); |
| 8764 | if (phone == null) { |
| 8765 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8766 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8767 | } |
| 8768 | |
| 8769 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8770 | try { |
| 8771 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8772 | workSource); |
| 8773 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8774 | |
| 8775 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8776 | if (DBG) { |
| 8777 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8778 | } |
| 8779 | SubscriptionManager.setSubscriptionProperty( |
| 8780 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8781 | (enabled ? "1" : "0")); |
| 8782 | } |
| 8783 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8784 | return result; |
| 8785 | } finally { |
| 8786 | Binder.restoreCallingIdentity(identity); |
| 8787 | } |
| 8788 | } |
| 8789 | |
| 8790 | /** |
| 8791 | * Is voice over NR enabled |
| 8792 | * @return true if VoNR is enabled else false |
| 8793 | */ |
| 8794 | @Override |
| 8795 | public boolean isVoNrEnabled(int subId) { |
| 8796 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8797 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8798 | final long identity = Binder.clearCallingIdentity(); |
| 8799 | try { |
| 8800 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8801 | null, subId, workSource); |
| 8802 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8803 | return isEnabled; |
| 8804 | } finally { |
| 8805 | Binder.restoreCallingIdentity(identity); |
| 8806 | } |
| 8807 | } |
| 8808 | |
| 8809 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8810 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8811 | * network status based on which carrier apps could apply actions accordingly, |
| 8812 | * enable/disable default url handler for example. |
| 8813 | * |
| 8814 | * @param subId the subscription ID that this action applies to. |
| 8815 | * @param report control start/stop reporting the default network status. |
| 8816 | * {@hide} |
| 8817 | */ |
| 8818 | @Override |
| 8819 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8820 | enforceModifyPermission(); |
| 8821 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8822 | |
| 8823 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8824 | if (phone == null) { |
| 8825 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8826 | return; |
| 8827 | } |
| 8828 | try { |
| 8829 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8830 | } catch (Exception e) { |
| 8831 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8832 | } finally { |
| 8833 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8834 | } |
| 8835 | } |
| 8836 | |
| 8837 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8838 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8839 | * @param subId the subscription ID that this action applies to. |
| 8840 | * {@hide} |
| 8841 | */ |
| 8842 | @Override |
| 8843 | public void carrierActionResetAll(int subId) { |
| 8844 | enforceModifyPermission(); |
| 8845 | final Phone phone = getPhone(subId); |
| 8846 | if (phone == null) { |
| 8847 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8848 | return; |
| 8849 | } |
| 8850 | try { |
| 8851 | phone.carrierActionResetAll(); |
| 8852 | } catch (Exception e) { |
| 8853 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8854 | } |
| 8855 | } |
| 8856 | |
| 8857 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8858 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8859 | * bug report is being generated. |
| 8860 | */ |
| 8861 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8862 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8863 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8864 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8865 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8866 | + Binder.getCallingPid() |
| 8867 | + ", uid=" + Binder.getCallingUid() |
| 8868 | + "without permission " |
| 8869 | + android.Manifest.permission.DUMP); |
| 8870 | return; |
| 8871 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8872 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8873 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8874 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8875 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8876 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8877 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8878 | @NonNull String[] args) { |
| 8879 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8880 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8881 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8882 | } |
| 8883 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8884 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8885 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8886 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8887 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8888 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8889 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8890 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8891 | */ |
| 8892 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8893 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8894 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8895 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8896 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8897 | try { |
| 8898 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8899 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8900 | } catch (SecurityException se) { |
| 8901 | enforceModifyPermission(); |
| 8902 | } |
| 8903 | } else { |
| 8904 | enforceModifyPermission(); |
| 8905 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8906 | |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 8907 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 8908 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 8909 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(), |
| 8910 | callingPackage, null, null); |
| 8911 | } |
| 8912 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8913 | final long identity = Binder.clearCallingIdentity(); |
| 8914 | try { |
| 8915 | Phone phone = getPhone(subId); |
| 8916 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8917 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8918 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8919 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8920 | phone.getDataSettingsManager().setDataEnabled( |
| 8921 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8922 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8923 | } |
| 8924 | } finally { |
| 8925 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8926 | } |
| 8927 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8928 | |
| 8929 | /** |
| 8930 | * Get Client request stats |
| 8931 | * @return List of Client Request Stats |
| 8932 | * @hide |
| 8933 | */ |
| 8934 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8935 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8936 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8937 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8938 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8939 | return null; |
| 8940 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8941 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8942 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8943 | final long identity = Binder.clearCallingIdentity(); |
| 8944 | try { |
| 8945 | if (phone != null) { |
| 8946 | return phone.getClientRequestStats(); |
| 8947 | } |
| 8948 | |
| 8949 | return null; |
| 8950 | } finally { |
| 8951 | Binder.restoreCallingIdentity(identity); |
| 8952 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8953 | } |
| 8954 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8955 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8956 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8957 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8958 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8959 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8960 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8961 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8962 | // commands that plumb through the RIL as root, like so: |
| 8963 | // $ adb root |
| 8964 | // $ adb shell cmd phone ... |
| 8965 | packageName = "root"; |
| 8966 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8967 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8968 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8969 | |
| 8970 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8971 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8972 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8973 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8974 | * @param state State of SIM (power down, power up, pass through) |
| 8975 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8976 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8977 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8978 | * |
| 8979 | **/ |
| 8980 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8981 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8982 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8983 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8984 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8985 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8986 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8987 | final long identity = Binder.clearCallingIdentity(); |
| 8988 | try { |
| 8989 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8990 | phone.setSimPowerState(state, null, workSource); |
| 8991 | } |
| 8992 | } finally { |
| 8993 | Binder.restoreCallingIdentity(identity); |
| 8994 | } |
| 8995 | } |
| 8996 | |
| 8997 | /** |
| 8998 | * Set SIM card power state. |
| 8999 | * |
| 9000 | * @param slotIndex SIM slot id. |
| 9001 | * @param state State of SIM (power down, power up, pass through) |
| 9002 | * @param callback callback to trigger after success or failure |
| 9003 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9004 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9005 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9006 | * |
| 9007 | **/ |
| 9008 | @Override |
| 9009 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9010 | IIntegerConsumer callback) { |
| 9011 | enforceModifyPermission(); |
| 9012 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9013 | |
| 9014 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9015 | |
| 9016 | final long identity = Binder.clearCallingIdentity(); |
| 9017 | try { |
| 9018 | if (phone != null) { |
| 9019 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9020 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9021 | } |
| 9022 | } finally { |
| 9023 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9024 | } |
| 9025 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9026 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9027 | private boolean isUssdApiAllowed(int subId) { |
| 9028 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9029 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9030 | if (configManager == null) { |
| 9031 | return false; |
| 9032 | } |
| 9033 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9034 | if (pb == null) { |
| 9035 | return false; |
| 9036 | } |
| 9037 | return pb.getBoolean( |
| 9038 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9039 | } |
| 9040 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9041 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9042 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9043 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9044 | * @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] | 9045 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9046 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9047 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9048 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9049 | final long identity = Binder.clearCallingIdentity(); |
| 9050 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9051 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9052 | } finally { |
| 9053 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9054 | } |
| 9055 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9056 | |
| 9057 | /** |
| 9058 | * Get the current signal strength information for the given subscription. |
| 9059 | * Because this information is not updated when the device is in a low power state |
| 9060 | * it should not be relied-upon to be current. |
| 9061 | * @param subId Subscription index |
| 9062 | * @return the most recent cached signal strength info from the modem |
| 9063 | */ |
| 9064 | @Override |
| 9065 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9066 | final long identity = Binder.clearCallingIdentity(); |
| 9067 | try { |
| 9068 | Phone p = getPhone(subId); |
| 9069 | if (p == null) { |
| 9070 | return null; |
| 9071 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9072 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9073 | return p.getSignalStrength(); |
| 9074 | } finally { |
| 9075 | Binder.restoreCallingIdentity(identity); |
| 9076 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9077 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9078 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9079 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9080 | * Get the current modem radio state for the given slot. |
| 9081 | * @param slotIndex slot index. |
| 9082 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9083 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9084 | * @return the current radio power state from the modem |
| 9085 | */ |
| 9086 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9087 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9088 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9089 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9090 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9091 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9092 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9093 | } |
| 9094 | |
| 9095 | final long identity = Binder.clearCallingIdentity(); |
| 9096 | try { |
| 9097 | return phone.getRadioPowerState(); |
| 9098 | } finally { |
| 9099 | Binder.restoreCallingIdentity(identity); |
| 9100 | } |
| 9101 | } |
| 9102 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9103 | } |
| 9104 | |
| 9105 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9106 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9107 | * |
| 9108 | * <p>Requires one of the following permissions: |
| 9109 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9110 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9111 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9112 | * privileges. |
| 9113 | * |
| 9114 | * @param subId subscription id |
| 9115 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9116 | * {@code false}. |
| 9117 | */ |
| 9118 | @Override |
| 9119 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9120 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9121 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9122 | try { |
| 9123 | mApp.enforceCallingOrSelfPermission( |
| 9124 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9125 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9126 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9127 | mApp.enforceCallingOrSelfPermission( |
| 9128 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9129 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9130 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9131 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9132 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9133 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9134 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9135 | boolean isEnabled = false; |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9137 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9138 | Phone phone = getPhone(subId); |
| 9139 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9140 | } finally { |
| 9141 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9142 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9143 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9144 | } |
| 9145 | |
| 9146 | |
| 9147 | /** |
| 9148 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9149 | * |
| 9150 | * <p> Requires permission: |
| 9151 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9152 | * privileges. |
| 9153 | * |
| 9154 | * @param subId subscription id |
| 9155 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9156 | */ |
| 9157 | @Override |
| 9158 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9160 | mApp, subId, "setDataRoamingEnabled"); |
| 9161 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9162 | final long identity = Binder.clearCallingIdentity(); |
| 9163 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9164 | Phone phone = getPhone(subId); |
| 9165 | if (phone != null) { |
| 9166 | phone.setDataRoamingEnabled(isEnabled); |
| 9167 | } |
| 9168 | } finally { |
| 9169 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9170 | } |
| 9171 | } |
| 9172 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9173 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9174 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9175 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9176 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9177 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9178 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9179 | boolean isAllowed = true; |
| 9180 | final long identity = Binder.clearCallingIdentity(); |
| 9181 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9182 | Phone phone = getPhone(subId); |
| 9183 | if (phone != null) { |
| 9184 | isAllowed = phone.isCspPlmnEnabled(); |
| 9185 | } |
| 9186 | } finally { |
| 9187 | Binder.restoreCallingIdentity(identity); |
| 9188 | } |
| 9189 | return isAllowed; |
| 9190 | } |
| 9191 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9192 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9193 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9194 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9195 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9196 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9197 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9198 | if (phone == null) { |
| 9199 | return false; |
| 9200 | } |
| 9201 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9202 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9203 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9204 | } |
| 9205 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9206 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9207 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9208 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9209 | mApp.getSystemService(AppOpsManager.class) |
| 9210 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9211 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9212 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9213 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9214 | try { |
| 9215 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9216 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9217 | } catch (SecurityException e) { |
| 9218 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9219 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9220 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9221 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9222 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9223 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9224 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9225 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9226 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9227 | Binder.getCallingUid())) { |
| 9228 | isIccIdAccessRestricted = true; |
| 9229 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9230 | final long identity = Binder.clearCallingIdentity(); |
| 9231 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9232 | UiccController uiccController = UiccController.getInstance(); |
| 9233 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9234 | if (hasReadPermission) { |
| 9235 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9236 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9237 | |
| 9238 | // Remove private info if the caller doesn't have access |
| 9239 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9240 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9241 | //setting the value after compatibility check |
| 9242 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9243 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9244 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9245 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9246 | if (card == null) { |
| 9247 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9248 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9249 | continue; |
| 9250 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9251 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9252 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9253 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9254 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9255 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9256 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9257 | for (UiccPortInfo portInfo : portInfos) { |
| 9258 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9259 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9260 | if (port == null) { |
| 9261 | // assume no access if port is null |
| 9262 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9263 | continue; |
| 9264 | } |
| 9265 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9266 | uiccPortInfos.add(portInfo); |
| 9267 | } else { |
| 9268 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9269 | } |
| 9270 | } |
| 9271 | filteredInfos.add(new UiccCardInfo( |
| 9272 | cardInfo.isEuicc(), |
| 9273 | cardInfo.getCardId(), |
| 9274 | null, |
| 9275 | cardInfo.getPhysicalSlotIndex(), |
| 9276 | cardInfo.isRemovable(), |
| 9277 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9278 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9279 | } |
| 9280 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9281 | } finally { |
| 9282 | Binder.restoreCallingIdentity(identity); |
| 9283 | } |
| 9284 | } |
| 9285 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9286 | /** |
| 9287 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9288 | * generally private and require carrier privileges to view. |
| 9289 | * |
| 9290 | * @hide |
| 9291 | */ |
| 9292 | @NonNull |
| 9293 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9294 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9295 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9296 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9297 | } |
| 9298 | return new UiccCardInfo( |
| 9299 | cardInfo.isEuicc(), |
| 9300 | cardInfo.getCardId(), |
| 9301 | null, |
| 9302 | cardInfo.getPhysicalSlotIndex(), |
| 9303 | cardInfo.isRemovable(), |
| 9304 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9305 | portinfo |
| 9306 | ); |
| 9307 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9308 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9309 | /** |
| 9310 | * @hide |
| 9311 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9312 | * These values are generally private and require carrier privileges to view. |
| 9313 | */ |
| 9314 | @NonNull |
| 9315 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9316 | return new UiccPortInfo( |
| 9317 | UiccPortInfo.ICCID_REDACTED, |
| 9318 | portInfo.getPortIndex(), |
| 9319 | portInfo.getLogicalSlotIndex(), |
| 9320 | portInfo.isActive() |
| 9321 | ); |
| 9322 | } |
| 9323 | @Override |
| 9324 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9325 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9326 | mApp.getSystemService(AppOpsManager.class) |
| 9327 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9328 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9329 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9330 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9331 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9332 | // we are reading iccId which is PII data. |
| 9333 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9334 | |
| 9335 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9336 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9337 | Binder.getCallingUid())) { |
| 9338 | isLogicalSlotAccessRestricted = true; |
| 9339 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9340 | final long identity = Binder.clearCallingIdentity(); |
| 9341 | try { |
| 9342 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9343 | if (slots == null || slots.length == 0) { |
| 9344 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9345 | return null; |
| 9346 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9347 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9348 | for (int i = 0; i < slots.length; i++) { |
| 9349 | UiccSlot slot = slots[i]; |
| 9350 | if (slot == null) { |
| 9351 | continue; |
| 9352 | } |
| 9353 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9354 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9355 | UiccCard card = slot.getUiccCard(); |
| 9356 | if (card != null) { |
| 9357 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9358 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9359 | cardId = slot.getEid(); |
| 9360 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9361 | // If cardId is null, use iccId of default port as cardId. |
| 9362 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9363 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9364 | } |
| 9365 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9366 | if (cardId != null) { |
| 9367 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9368 | // if cardId is an EID, it's all digits so this is fine |
| 9369 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9370 | } |
| 9371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9372 | int cardState = 0; |
| 9373 | switch (slot.getCardState()) { |
| 9374 | case CARDSTATE_ABSENT: |
| 9375 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9376 | break; |
| 9377 | case CARDSTATE_PRESENT: |
| 9378 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9379 | break; |
| 9380 | case CARDSTATE_ERROR: |
| 9381 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9382 | break; |
| 9383 | case CARDSTATE_RESTRICTED: |
| 9384 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9385 | break; |
| 9386 | default: |
| 9387 | break; |
| 9388 | |
| 9389 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9390 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9391 | int[] portIndexes = slot.getPortList(); |
| 9392 | for (int portIdx : portIndexes) { |
| 9393 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9394 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9395 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9396 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9397 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9398 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9399 | slot.isEuicc(), |
| 9400 | cardId, |
| 9401 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9402 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9403 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9404 | //setting the value after compatibility check |
| 9405 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9406 | } |
| 9407 | return infos; |
| 9408 | } finally { |
| 9409 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9410 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9411 | } |
| 9412 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9413 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9414 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9415 | boolean hasReadPermission) { |
| 9416 | String iccId = slot.getIccId(portIndex); |
| 9417 | if (hasReadPermission) { // if has read permission |
| 9418 | return iccId; |
| 9419 | } else { |
| 9420 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9421 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9422 | // if no read permission, checking carrier privilege access |
| 9423 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9424 | return iccId; |
| 9425 | } |
| 9426 | } |
| 9427 | } |
| 9428 | // No read permission or carrier privilege access. |
| 9429 | return UiccPortInfo.ICCID_REDACTED; |
| 9430 | } |
| 9431 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9432 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9433 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9434 | public boolean switchSlots(int[] physicalSlots) { |
| 9435 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9436 | |
| 9437 | final long identity = Binder.clearCallingIdentity(); |
| 9438 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9439 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9440 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9441 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9442 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9443 | physicalSlots[i], i)); |
| 9444 | } |
| 9445 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9446 | } finally { |
| 9447 | Binder.restoreCallingIdentity(identity); |
| 9448 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9449 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9450 | |
| 9451 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9452 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9453 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9454 | enforceModifyPermission(); |
| 9455 | |
| 9456 | final long identity = Binder.clearCallingIdentity(); |
| 9457 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9458 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9459 | } finally { |
| 9460 | Binder.restoreCallingIdentity(identity); |
| 9461 | } |
| 9462 | } |
| 9463 | |
| 9464 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9465 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9466 | final long identity = Binder.clearCallingIdentity(); |
| 9467 | try { |
| 9468 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9469 | } finally { |
| 9470 | Binder.restoreCallingIdentity(identity); |
| 9471 | } |
| 9472 | } |
| 9473 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9474 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9475 | * A test API to reload the UICC profile. |
| 9476 | * |
| 9477 | * <p>Requires that the calling app has permission |
| 9478 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9479 | * @hide |
| 9480 | */ |
| 9481 | @Override |
| 9482 | public void refreshUiccProfile(int subId) { |
| 9483 | enforceModifyPermission(); |
| 9484 | |
| 9485 | final long identity = Binder.clearCallingIdentity(); |
| 9486 | try { |
| 9487 | Phone phone = getPhone(subId); |
| 9488 | if (phone == null) { |
| 9489 | return; |
| 9490 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9491 | UiccPort uiccPort = phone.getUiccPort(); |
| 9492 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9493 | return; |
| 9494 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9495 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9496 | if (uiccProfile == null) { |
| 9497 | return; |
| 9498 | } |
| 9499 | uiccProfile.refresh(); |
| 9500 | } finally { |
| 9501 | Binder.restoreCallingIdentity(identity); |
| 9502 | } |
| 9503 | } |
| 9504 | |
| 9505 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9506 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9507 | */ |
| 9508 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9509 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9510 | } |
| 9511 | |
| 9512 | /** |
| 9513 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9514 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9515 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9516 | */ |
| 9517 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9518 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9519 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9520 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9521 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9522 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9523 | return isDataRoamingEnabled; |
| 9524 | } |
| 9525 | |
| 9526 | /** |
| 9527 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9528 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9529 | */ |
| 9530 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9531 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9532 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9533 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9534 | return list.get(phoneId); |
| 9535 | } |
| 9536 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9537 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9538 | |
| 9539 | @Override |
| 9540 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9541 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9542 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9543 | |
| 9544 | final long identity = Binder.clearCallingIdentity(); |
| 9545 | try { |
| 9546 | final Phone phone = getPhone(subId); |
| 9547 | if (phone == null) { |
| 9548 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9549 | return; |
| 9550 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9551 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9552 | if (cpt != null) { |
| 9553 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9554 | } |
| 9555 | // 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] | 9556 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9557 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9558 | if (carrierPrivilegeRules == null) { |
| 9559 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9560 | } else { |
| 9561 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9562 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9563 | } finally { |
| 9564 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9565 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9566 | } |
| 9567 | |
| 9568 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9569 | public void setCarrierServicePackageOverride( |
| 9570 | int subId, String carrierServicePackage, String callingPackage) { |
| 9571 | TelephonyPermissions.enforceShellOnly( |
| 9572 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9573 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9574 | final long identity = Binder.clearCallingIdentity(); |
| 9575 | try { |
| 9576 | final Phone phone = getPhone(subId); |
| 9577 | if (phone == null || phone.getSubId() != subId) { |
| 9578 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9579 | throw new IllegalArgumentException("No phone for subid"); |
| 9580 | } |
| 9581 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9582 | if (cpt == null) { |
| 9583 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9584 | throw new IllegalStateException("No CPT for phone"); |
| 9585 | } |
| 9586 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9587 | } finally { |
| 9588 | Binder.restoreCallingIdentity(identity); |
| 9589 | } |
| 9590 | } |
| 9591 | |
| 9592 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9593 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9594 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9595 | |
| 9596 | final long identity = Binder.clearCallingIdentity(); |
| 9597 | try { |
| 9598 | final Phone phone = getPhone(subId); |
| 9599 | if (phone == null) { |
| 9600 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9601 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9602 | } |
| 9603 | return phone.getCarrierIdListVersion(); |
| 9604 | } finally { |
| 9605 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9606 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9607 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9608 | |
| 9609 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9610 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9611 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9612 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9613 | mApp, subId, callingPackage, callingFeatureId, |
| 9614 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9615 | return -1; |
| 9616 | } |
| 9617 | |
| 9618 | final long identity = Binder.clearCallingIdentity(); |
| 9619 | try { |
| 9620 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9621 | } finally { |
| 9622 | Binder.restoreCallingIdentity(identity); |
| 9623 | } |
| 9624 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9625 | |
| 9626 | @Override |
| 9627 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9628 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9629 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9630 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9631 | |
| 9632 | final long identity = Binder.clearCallingIdentity(); |
| 9633 | try { |
| 9634 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9635 | } finally { |
| 9636 | Binder.restoreCallingIdentity(identity); |
| 9637 | } |
| 9638 | } |
| 9639 | |
| 9640 | @Override |
| 9641 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9643 | mApp, subId, "setCdmaRoamingMode"); |
| 9644 | |
| 9645 | final long identity = Binder.clearCallingIdentity(); |
| 9646 | try { |
| 9647 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9648 | } finally { |
| 9649 | Binder.restoreCallingIdentity(identity); |
| 9650 | } |
| 9651 | } |
| 9652 | |
| 9653 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9654 | public int getCdmaSubscriptionMode(int subId) { |
| 9655 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9656 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9657 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9658 | |
| 9659 | final long identity = Binder.clearCallingIdentity(); |
| 9660 | try { |
| 9661 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9662 | } finally { |
| 9663 | Binder.restoreCallingIdentity(identity); |
| 9664 | } |
| 9665 | } |
| 9666 | |
| 9667 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9668 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9670 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9671 | |
| 9672 | final long identity = Binder.clearCallingIdentity(); |
| 9673 | try { |
| 9674 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9675 | } finally { |
| 9676 | Binder.restoreCallingIdentity(identity); |
| 9677 | } |
| 9678 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9679 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9680 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9681 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9682 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9683 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9684 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9685 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9686 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9687 | } |
| 9688 | final long identity = Binder.clearCallingIdentity(); |
| 9689 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9690 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9691 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9692 | if (phone.getEmergencyNumberTracker() != null |
| 9693 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9694 | emergencyNumberListInternal.put( |
| 9695 | phone.getSubId(), |
| 9696 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9697 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9698 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9699 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9700 | } finally { |
| 9701 | Binder.restoreCallingIdentity(identity); |
| 9702 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9703 | } |
| 9704 | |
| 9705 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9706 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9707 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9708 | if (!exactMatch) { |
| 9709 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9710 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9711 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9712 | } |
| 9713 | final long identity = Binder.clearCallingIdentity(); |
| 9714 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9715 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9716 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9717 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9718 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9719 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9720 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9721 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9722 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9723 | } |
| 9724 | return false; |
| 9725 | } finally { |
| 9726 | Binder.restoreCallingIdentity(identity); |
| 9727 | } |
| 9728 | } |
| 9729 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9730 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9731 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9732 | */ |
| 9733 | @Override |
| 9734 | public void startEmergencyCallbackMode() { |
| 9735 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9736 | "startEmergencyCallbackMode"); |
| 9737 | enforceModifyPermission(); |
| 9738 | final long identity = Binder.clearCallingIdentity(); |
| 9739 | try { |
| 9740 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9741 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9742 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9743 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9744 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9745 | gsmCdmaPhone.obtainMessage( |
| 9746 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9747 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9748 | } |
| 9749 | } |
| 9750 | } finally { |
| 9751 | Binder.restoreCallingIdentity(identity); |
| 9752 | } |
| 9753 | } |
| 9754 | |
| 9755 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9756 | * Update emergency number list for test mode. |
| 9757 | */ |
| 9758 | @Override |
| 9759 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9760 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9761 | "updateEmergencyNumberListTestMode"); |
| 9762 | |
| 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
| 9765 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9766 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9767 | if (tracker != null) { |
| 9768 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9769 | } |
| 9770 | } |
| 9771 | } finally { |
| 9772 | Binder.restoreCallingIdentity(identity); |
| 9773 | } |
| 9774 | } |
| 9775 | |
| 9776 | /** |
| 9777 | * Get the full emergency number list for test mode. |
| 9778 | */ |
| 9779 | @Override |
| 9780 | public List<String> getEmergencyNumberListTestMode() { |
| 9781 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9782 | "getEmergencyNumberListTestMode"); |
| 9783 | |
| 9784 | final long identity = Binder.clearCallingIdentity(); |
| 9785 | try { |
| 9786 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9787 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9788 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9789 | if (tracker != null) { |
| 9790 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9791 | emergencyNumbers.add(num.getNumber()); |
| 9792 | } |
| 9793 | } |
| 9794 | } |
| 9795 | return new ArrayList<>(emergencyNumbers); |
| 9796 | } finally { |
| 9797 | Binder.restoreCallingIdentity(identity); |
| 9798 | } |
| 9799 | } |
| 9800 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9801 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9802 | public int getEmergencyNumberDbVersion(int subId) { |
| 9803 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9804 | |
| 9805 | final long identity = Binder.clearCallingIdentity(); |
| 9806 | try { |
| 9807 | final Phone phone = getPhone(subId); |
| 9808 | if (phone == null) { |
| 9809 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9810 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9811 | } |
| 9812 | return phone.getEmergencyNumberDbVersion(); |
| 9813 | } finally { |
| 9814 | Binder.restoreCallingIdentity(identity); |
| 9815 | } |
| 9816 | } |
| 9817 | |
| 9818 | @Override |
| 9819 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9820 | enforceModifyPermission(); |
| 9821 | |
| 9822 | final long identity = Binder.clearCallingIdentity(); |
| 9823 | try { |
| 9824 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9825 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9826 | if (tracker != null) { |
| 9827 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9828 | } |
| 9829 | } |
| 9830 | } finally { |
| 9831 | Binder.restoreCallingIdentity(identity); |
| 9832 | } |
| 9833 | } |
| 9834 | |
| 9835 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9836 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9837 | enforceActiveEmergencySessionPermission(); |
| 9838 | |
| 9839 | final long identity = Binder.clearCallingIdentity(); |
| 9840 | try { |
| 9841 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9842 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9843 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9844 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9845 | } |
| 9846 | } |
| 9847 | } finally { |
| 9848 | Binder.restoreCallingIdentity(identity); |
| 9849 | } |
| 9850 | } |
| 9851 | |
| 9852 | @Override |
| 9853 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9854 | enforceActiveEmergencySessionPermission(); |
| 9855 | |
| 9856 | final long identity = Binder.clearCallingIdentity(); |
| 9857 | try { |
| 9858 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9859 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9860 | if (tracker != null) { |
| 9861 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9862 | } |
| 9863 | } |
| 9864 | } finally { |
| 9865 | Binder.restoreCallingIdentity(identity); |
| 9866 | } |
| 9867 | } |
| 9868 | |
| 9869 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9870 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9871 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9872 | Phone phone = getPhone(subId); |
| 9873 | if (phone == null) { |
| 9874 | return null; |
| 9875 | } |
| 9876 | final long identity = Binder.clearCallingIdentity(); |
| 9877 | try { |
| 9878 | UiccProfile profile = UiccController.getInstance() |
| 9879 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9880 | if (profile != null) { |
| 9881 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9882 | } |
| 9883 | } finally { |
| 9884 | Binder.restoreCallingIdentity(identity); |
| 9885 | } |
| 9886 | return null; |
| 9887 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9888 | |
| 9889 | /** |
| 9890 | * Enable or disable a modem stack. |
| 9891 | */ |
| 9892 | @Override |
| 9893 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9894 | enforceModifyPermission(); |
| 9895 | |
| 9896 | final long identity = Binder.clearCallingIdentity(); |
| 9897 | try { |
| 9898 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9899 | if (phone == null) { |
| 9900 | return false; |
| 9901 | } else { |
| 9902 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9903 | } |
| 9904 | } finally { |
| 9905 | Binder.restoreCallingIdentity(identity); |
| 9906 | } |
| 9907 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9908 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9909 | /** |
| 9910 | * Whether a modem stack is enabled or not. |
| 9911 | */ |
| 9912 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9913 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9914 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9915 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9916 | if (phone == null) return false; |
| 9917 | |
| 9918 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9919 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9920 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9921 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9922 | } |
| 9923 | |
| 9924 | final long identity = Binder.clearCallingIdentity(); |
| 9925 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9926 | try { |
| 9927 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9928 | } catch (NoSuchElementException ex) { |
| 9929 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9930 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9931 | } finally { |
| 9932 | Binder.restoreCallingIdentity(identity); |
| 9933 | } |
| 9934 | } |
| 9935 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9936 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9937 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9938 | enforceModifyPermission(); |
| 9939 | |
| 9940 | final long identity = Binder.clearCallingIdentity(); |
| 9941 | try { |
| 9942 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9943 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9944 | .commit(); |
| 9945 | } finally { |
| 9946 | Binder.restoreCallingIdentity(identity); |
| 9947 | } |
| 9948 | } |
| 9949 | |
| 9950 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9951 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9952 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9953 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9954 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9955 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9956 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9957 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9958 | |
| 9959 | final long identity = Binder.clearCallingIdentity(); |
| 9960 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9961 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9962 | } finally { |
| 9963 | Binder.restoreCallingIdentity(identity); |
| 9964 | } |
| 9965 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9966 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9967 | @TelephonyManager.IsMultiSimSupportedResult |
| 9968 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9969 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9970 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9971 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9972 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9973 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9974 | } |
| 9975 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9976 | // supported by the modem, indicate that it is restricted. |
| 9977 | PhoneCapability staticCapability = |
| 9978 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9979 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9980 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9981 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9982 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9983 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9984 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9985 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9986 | } |
| 9987 | // Check if support of multiple SIMs is restricted by carrier |
| 9988 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9989 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9990 | } |
| 9991 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9992 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9993 | } |
| 9994 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9995 | /** |
| 9996 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9997 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9998 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9999 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10000 | * @param numOfSims number of active sims we want to switch to |
| 10001 | */ |
| 10002 | @Override |
| 10003 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10004 | if (numOfSims == 1) { |
| 10005 | enforceModifyPermission(); |
| 10006 | } else { |
| 10007 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10008 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10009 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10010 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10011 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10012 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10013 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10014 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10015 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10016 | return; |
| 10017 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10018 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10019 | } finally { |
| 10020 | Binder.restoreCallingIdentity(identity); |
| 10021 | } |
| 10022 | } |
| 10023 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10024 | @Override |
| 10025 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10026 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10027 | Phone phone = getPhone(subId); |
| 10028 | if (phone == null) { |
| 10029 | return false; |
| 10030 | } |
| 10031 | final long identity = Binder.clearCallingIdentity(); |
| 10032 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10033 | UiccPort uiccPort = phone.getUiccPort(); |
| 10034 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10035 | return false; |
| 10036 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10037 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10038 | if (uiccProfile == null) { |
| 10039 | return false; |
| 10040 | } |
| 10041 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10042 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10043 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10044 | } |
| 10045 | return false; |
| 10046 | } finally { |
| 10047 | Binder.restoreCallingIdentity(identity); |
| 10048 | } |
| 10049 | } |
| 10050 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10051 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10052 | * Get whether making changes to modem configurations will trigger reboot. |
| 10053 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10054 | */ |
| 10055 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10056 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10057 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10058 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10059 | mApp, subId, callingPackage, callingFeatureId, |
| 10060 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10061 | return false; |
| 10062 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10063 | final long identity = Binder.clearCallingIdentity(); |
| 10064 | try { |
| 10065 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10066 | } finally { |
| 10067 | Binder.restoreCallingIdentity(identity); |
| 10068 | } |
| 10069 | } |
| 10070 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10071 | private void updateModemStateMetrics() { |
| 10072 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10073 | // TODO: check the state for each modem if the api is ready. |
| 10074 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10075 | } |
| 10076 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10077 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10078 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10079 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10080 | // Verify that the callingPackage belongs to the calling UID |
| 10081 | mApp.getSystemService(AppOpsManager.class) |
| 10082 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10083 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10084 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10085 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10086 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10087 | if (slotInfos != null) { |
| 10088 | for (int i = 0; i < slotInfos.length; i++) { |
| 10089 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10090 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10091 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10092 | portInfo.getLogicalSlotIndex())); |
| 10093 | } |
| 10094 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10095 | } |
| 10096 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10097 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10098 | } finally { |
| 10099 | Binder.restoreCallingIdentity(identity); |
| 10100 | } |
| 10101 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10102 | |
| 10103 | /** |
| 10104 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10105 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10106 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10107 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10108 | @Override |
| 10109 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10110 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10111 | } |
| 10112 | |
| 10113 | /** |
| 10114 | * Get the HAL Version of a specific service |
| 10115 | */ |
| 10116 | @Override |
| 10117 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10118 | Phone phone = getDefaultPhone(); |
| 10119 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10120 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10121 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10122 | return hv.major * 100 + hv.minor; |
| 10123 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10124 | |
| 10125 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10126 | * Get the current calling package name. |
| 10127 | * @return the current calling package name |
| 10128 | */ |
| 10129 | @Override |
| 10130 | public String getCurrentPackageName() { |
| 10131 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10132 | } |
| 10133 | |
| 10134 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10135 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10136 | * corresponding network requests on a subId. |
| 10137 | * |
| 10138 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10139 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10140 | * 2) APN is un-metered for this subscription, or |
| 10141 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10142 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10143 | * |
| 10144 | * @return whether data is allowed for a apn type. |
| 10145 | * |
| 10146 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10147 | */ |
| 10148 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10149 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10150 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10151 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10152 | |
| 10153 | // Now that all security checks passes, perform the operation as ourselves. |
| 10154 | final long identity = Binder.clearCallingIdentity(); |
| 10155 | try { |
| 10156 | Phone phone = getPhone(subId); |
| 10157 | if (phone == null) return false; |
| 10158 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10159 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10160 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10161 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10162 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10163 | phone.getServiceState().getDataRoaming()); |
| 10164 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10165 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10166 | } finally { |
| 10167 | Binder.restoreCallingIdentity(identity); |
| 10168 | } |
| 10169 | } |
| 10170 | |
| 10171 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10172 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10173 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10174 | |
| 10175 | // Now that all security checks passes, perform the operation as ourselves. |
| 10176 | final long identity = Binder.clearCallingIdentity(); |
| 10177 | try { |
| 10178 | Phone phone = getPhone(subId); |
| 10179 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10180 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10181 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10182 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10183 | } finally { |
| 10184 | Binder.restoreCallingIdentity(identity); |
| 10185 | } |
| 10186 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10187 | |
| 10188 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10189 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10190 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10191 | enforceModifyPermission(); |
| 10192 | long token = Binder.clearCallingIdentity(); |
| 10193 | try { |
| 10194 | Phone phone = getPhone(subscriptionId); |
| 10195 | if (phone == null) { |
| 10196 | try { |
| 10197 | if (resultCallback != null) { |
| 10198 | resultCallback.accept(false); |
| 10199 | } |
| 10200 | } catch (RemoteException e) { |
| 10201 | // ignore |
| 10202 | } |
| 10203 | return; |
| 10204 | } |
| 10205 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10206 | Pair.create(specifiers, (x) -> { |
| 10207 | try { |
| 10208 | if (resultCallback != null) { |
| 10209 | resultCallback.accept(x); |
| 10210 | } |
| 10211 | } catch (RemoteException e) { |
| 10212 | // ignore |
| 10213 | } |
| 10214 | }); |
| 10215 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10216 | } finally { |
| 10217 | Binder.restoreCallingIdentity(token); |
| 10218 | } |
| 10219 | } |
| 10220 | |
| 10221 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10222 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10223 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10224 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10225 | mApp, subId, "getSystemSelectionChannels"); |
| 10226 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10227 | final long identity = Binder.clearCallingIdentity(); |
| 10228 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10229 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10230 | if (result instanceof IllegalStateException) { |
| 10231 | throw (IllegalStateException) result; |
| 10232 | } |
| 10233 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10234 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10235 | return specifiers; |
| 10236 | } finally { |
| 10237 | Binder.restoreCallingIdentity(identity); |
| 10238 | } |
| 10239 | } |
| 10240 | |
| 10241 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10242 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10243 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10244 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10245 | } |
| 10246 | |
| 10247 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10248 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10249 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10250 | if (callingPackage == null) { |
| 10251 | callingPackage = getCurrentPackageName(); |
| 10252 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10253 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10254 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10255 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10256 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10257 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10258 | } |
| 10259 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10260 | Intent intent = new Intent(); |
| 10261 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10262 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10263 | // Bring up choose default SMS subscription dialog right now |
| 10264 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10265 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10266 | mApp.startActivity(intent); |
| 10267 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10268 | |
| 10269 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10270 | public void showSwitchToManagedProfileDialog() { |
| 10271 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10272 | try { |
| 10273 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10274 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10275 | // for work telephony. |
| 10276 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10277 | intent.setData(Uri.parse("smsto:")); |
| 10278 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10279 | mApp.startActivity(intent); |
| 10280 | } catch (ActivityNotFoundException e) { |
| 10281 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10282 | Intent intent = new Intent(); |
| 10283 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10284 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10285 | mApp.startActivity(intent); |
| 10286 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10287 | } |
| 10288 | |
| 10289 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10290 | public String getMmsUAProfUrl(int subId) { |
| 10291 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10292 | final long identity = Binder.clearCallingIdentity(); |
| 10293 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10294 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10295 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10296 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10297 | return carrierUAProfUrl; |
| 10298 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10299 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10300 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10301 | } finally { |
| 10302 | Binder.restoreCallingIdentity(identity); |
| 10303 | } |
| 10304 | } |
| 10305 | |
| 10306 | @Override |
| 10307 | public String getMmsUserAgent(int subId) { |
| 10308 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10309 | final long identity = Binder.clearCallingIdentity(); |
| 10310 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10311 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10312 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10313 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10314 | return carrierUserAgent; |
| 10315 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10316 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10317 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10318 | } finally { |
| 10319 | Binder.restoreCallingIdentity(identity); |
| 10320 | } |
| 10321 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10322 | |
| 10323 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10324 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10325 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10326 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10327 | final long identity = Binder.clearCallingIdentity(); |
| 10328 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10329 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10330 | if (phone == null) return false; |
| 10331 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10332 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10333 | } finally { |
| 10334 | Binder.restoreCallingIdentity(identity); |
| 10335 | } |
| 10336 | } |
| 10337 | |
| 10338 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10339 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10340 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10341 | enforceModifyPermission(); |
| 10342 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10343 | final long identity = Binder.clearCallingIdentity(); |
| 10344 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10345 | Phone phone = getPhone(subscriptionId); |
| 10346 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10347 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10348 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10349 | } finally { |
| 10350 | Binder.restoreCallingIdentity(identity); |
| 10351 | } |
| 10352 | } |
| 10353 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10354 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10355 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10356 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10357 | * otherwise. |
| 10358 | */ |
| 10359 | @Override |
| 10360 | public void setCepEnabled(boolean isCepEnabled) { |
| 10361 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10362 | |
| 10363 | final long identity = Binder.clearCallingIdentity(); |
| 10364 | try { |
| 10365 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10366 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10367 | Phone defaultPhone = phone.getImsPhone(); |
| 10368 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10369 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10370 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10371 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10372 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10373 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10374 | + imsPhone.getMsisdn()); |
| 10375 | } |
| 10376 | } |
| 10377 | } finally { |
| 10378 | Binder.restoreCallingIdentity(identity); |
| 10379 | } |
| 10380 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10381 | |
| 10382 | /** |
| 10383 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10384 | * |
| 10385 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10386 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10387 | * before being read. |
| 10388 | */ |
| 10389 | @Override |
| 10390 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10391 | isCompressed) { |
| 10392 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10393 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10394 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10395 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10396 | } |
| 10397 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10398 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10399 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10400 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10401 | } |
| 10402 | |
| 10403 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10404 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10405 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10406 | } finally { |
| 10407 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10408 | } |
| 10409 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10410 | |
| 10411 | @Override |
| 10412 | public boolean isIccLockEnabled(int subId) { |
| 10413 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10414 | |
| 10415 | // Now that all security checks passes, perform the operation as ourselves. |
| 10416 | final long identity = Binder.clearCallingIdentity(); |
| 10417 | try { |
| 10418 | Phone phone = getPhone(subId); |
| 10419 | if (phone != null && phone.getIccCard() != null) { |
| 10420 | return phone.getIccCard().getIccLockEnabled(); |
| 10421 | } else { |
| 10422 | return false; |
| 10423 | } |
| 10424 | } finally { |
| 10425 | Binder.restoreCallingIdentity(identity); |
| 10426 | } |
| 10427 | } |
| 10428 | |
| 10429 | /** |
| 10430 | * Set the ICC pin lock enabled or disabled. |
| 10431 | * |
| 10432 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10433 | * three cases: |
| 10434 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10435 | * successfully. |
| 10436 | * - Positive number and zero for remaining password attempts. |
| 10437 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10438 | * |
| 10439 | */ |
| 10440 | @Override |
| 10441 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10442 | enforceModifyPermission(); |
| 10443 | |
| 10444 | Phone phone = getPhone(subId); |
| 10445 | if (phone == null) { |
| 10446 | return 0; |
| 10447 | } |
| 10448 | // Now that all security checks passes, perform the operation as ourselves. |
| 10449 | final long identity = Binder.clearCallingIdentity(); |
| 10450 | try { |
| 10451 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10452 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10453 | return attemptsRemaining; |
| 10454 | |
| 10455 | } catch (Exception e) { |
| 10456 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10457 | } finally { |
| 10458 | Binder.restoreCallingIdentity(identity); |
| 10459 | } |
| 10460 | return 0; |
| 10461 | } |
| 10462 | |
| 10463 | /** |
| 10464 | * Change the ICC password used in ICC pin lock. |
| 10465 | * |
| 10466 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10467 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10468 | * - Positive number and zero for remaining password attempts. |
| 10469 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10470 | * |
| 10471 | */ |
| 10472 | @Override |
| 10473 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10474 | enforceModifyPermission(); |
| 10475 | |
| 10476 | Phone phone = getPhone(subId); |
| 10477 | if (phone == null) { |
| 10478 | return 0; |
| 10479 | } |
| 10480 | // Now that all security checks passes, perform the operation as ourselves. |
| 10481 | final long identity = Binder.clearCallingIdentity(); |
| 10482 | try { |
| 10483 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10484 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10485 | return attemptsRemaining; |
| 10486 | |
| 10487 | } catch (Exception e) { |
| 10488 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10489 | } finally { |
| 10490 | Binder.restoreCallingIdentity(identity); |
| 10491 | } |
| 10492 | return 0; |
| 10493 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10494 | |
| 10495 | /** |
| 10496 | * Request for receiving user activity notification |
| 10497 | */ |
| 10498 | @Override |
| 10499 | public void requestUserActivityNotification() { |
| 10500 | if (!mNotifyUserActivity.get() |
| 10501 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10502 | mNotifyUserActivity.set(true); |
| 10503 | } |
| 10504 | } |
| 10505 | |
| 10506 | /** |
| 10507 | * Called when userActivity is signalled in the power manager. |
| 10508 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10509 | */ |
| 10510 | @Override |
| 10511 | public void userActivity() { |
| 10512 | // *************************************** |
| 10513 | // * Inherited from PhoneWindowManager * |
| 10514 | // *************************************** |
| 10515 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10516 | // WITH ITS LOCKS HELD. |
| 10517 | // |
| 10518 | // This code must be VERY careful about the locks |
| 10519 | // it acquires. |
| 10520 | // In fact, the current code acquires way too many, |
| 10521 | // and probably has lurking deadlocks. |
| 10522 | |
| 10523 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10524 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10525 | } |
| 10526 | |
| 10527 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10528 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10529 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10530 | } |
| 10531 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10532 | |
| 10533 | @Override |
| 10534 | public boolean canConnectTo5GInDsdsMode() { |
| 10535 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10536 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10537 | |
| 10538 | @Override |
| 10539 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10540 | String callingFeatureId) { |
| 10541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10542 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10543 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10544 | } |
| 10545 | |
| 10546 | Phone phone = getPhone(subId); |
| 10547 | if (phone == null) { |
| 10548 | throw new RuntimeException("phone is not available"); |
| 10549 | } |
| 10550 | // Now that all security checks passes, perform the operation as ourselves. |
| 10551 | final long identity = Binder.clearCallingIdentity(); |
| 10552 | try { |
| 10553 | return phone.getEquivalentHomePlmns(); |
| 10554 | } finally { |
| 10555 | Binder.restoreCallingIdentity(identity); |
| 10556 | } |
| 10557 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10558 | |
| 10559 | @Override |
| 10560 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10561 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10562 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10563 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10564 | if (radioInterfaceCapabilities == null) { |
| 10565 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10566 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10567 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10568 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10569 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10570 | @Override |
| 10571 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10572 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10573 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10574 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10575 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10576 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10577 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10578 | if (DBG) { |
| 10579 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10580 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10581 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10582 | } |
| 10583 | |
| 10584 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10585 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10586 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10587 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10588 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10589 | if (callback != null) { |
| 10590 | try { |
| 10591 | callback.onAuthenticationFailure( |
| 10592 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10593 | } catch (RemoteException exception) { |
| 10594 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10595 | } |
| 10596 | return; |
| 10597 | } |
| 10598 | } |
| 10599 | |
| 10600 | final long token = Binder.clearCallingIdentity(); |
| 10601 | try { |
| 10602 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10603 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10604 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10605 | } finally { |
| 10606 | Binder.restoreCallingIdentity(token); |
| 10607 | } |
| 10608 | } |
| 10609 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10610 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10611 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10612 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10613 | * requested radio power state will actually be set. See {@link |
| 10614 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10615 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10616 | * @param enable {@code true} if trying to turn radio on. |
| 10617 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10618 | * false}. |
| 10619 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10620 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10621 | boolean isPhoneAvailable = false; |
| 10622 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10623 | Phone phone = PhoneFactory.getPhone(i); |
| 10624 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10625 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10626 | isPhoneAvailable = true; |
| 10627 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10628 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10629 | |
| 10630 | // return true if successfully informed the phone object about the thermal radio power |
| 10631 | // request. |
| 10632 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10633 | } |
| 10634 | |
| 10635 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10636 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10637 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10638 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10639 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10640 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10641 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10642 | } |
| 10643 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10644 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10645 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10646 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10647 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10648 | } |
| 10649 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10650 | setDataEnabledForReason( |
| 10651 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10652 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10653 | if (isDataThrottlingSupported) { |
| 10654 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10655 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10656 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10657 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10658 | } else if (thermalMitigationResult |
| 10659 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10660 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10661 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10662 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10663 | } |
| 10664 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10665 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10666 | |
| 10667 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10668 | } |
| 10669 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10670 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10671 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10672 | for (String pckg : context.getResources() |
| 10673 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10674 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10675 | } |
| 10676 | } |
| 10677 | |
| 10678 | return sThermalMitigationAllowlistedPackages; |
| 10679 | } |
| 10680 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10681 | private boolean isAnyPhoneInEmergencyState() { |
| 10682 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10683 | if (tm.isInEmergencyCall()) { |
| 10684 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10685 | return true; |
| 10686 | } |
| 10687 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10688 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10689 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10690 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10691 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10692 | return true; |
| 10693 | } |
| 10694 | } |
| 10695 | |
| 10696 | return false; |
| 10697 | } |
| 10698 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10699 | /** |
| 10700 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10701 | * @param packageName name of package to be allowlisted |
| 10702 | * @param context |
| 10703 | */ |
| 10704 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10705 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10706 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10707 | } |
| 10708 | |
| 10709 | /** |
| 10710 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10711 | * @param packageName name of package to remove from allowlist |
| 10712 | * @param context |
| 10713 | */ |
| 10714 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10715 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10716 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10717 | } |
| 10718 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10719 | /** |
| 10720 | * Thermal mitigation request to control functionalities at modem. |
| 10721 | * |
| 10722 | * @param subId the id of the subscription. |
| 10723 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10724 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10725 | * |
| 10726 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10727 | */ |
| 10728 | @Override |
| 10729 | @ThermalMitigationResult |
| 10730 | public int sendThermalMitigationRequest( |
| 10731 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10732 | ThermalMitigationRequest thermalMitigationRequest, |
| 10733 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10734 | enforceModifyPermission(); |
| 10735 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10736 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10737 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10738 | .contains(callingPackage)) { |
| 10739 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10740 | + "calling package: " + callingPackage); |
| 10741 | } |
| 10742 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10743 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10744 | final long identity = Binder.clearCallingIdentity(); |
| 10745 | |
| 10746 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10747 | try { |
| 10748 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10749 | switch (thermalMitigationAction) { |
| 10750 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10751 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10752 | handleDataThrottlingRequest(subId, |
| 10753 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10754 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10755 | break; |
| 10756 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10757 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10758 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10759 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10760 | } |
| 10761 | |
| 10762 | // Ensure that radio is on. If not able to power on due to phone being |
| 10763 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10764 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10765 | thermalMitigationResult = |
| 10766 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10767 | break; |
| 10768 | } |
| 10769 | |
| 10770 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10771 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10772 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10773 | break; |
| 10774 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10775 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10776 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10777 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10778 | } |
| 10779 | |
| 10780 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10781 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10782 | Phone phone = getPhone(subId); |
| 10783 | if (phone == null) { |
| 10784 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10785 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10786 | break; |
| 10787 | } |
| 10788 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10789 | TelephonyConnectionService service = |
| 10790 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10791 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10792 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10793 | thermalMitigationResult = |
| 10794 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10795 | break; |
| 10796 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10797 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10798 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10799 | break; |
| 10800 | } |
| 10801 | } else { |
| 10802 | thermalMitigationResult = |
| 10803 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10804 | break; |
| 10805 | } |
| 10806 | |
| 10807 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10808 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10809 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10810 | thermalMitigationResult = |
| 10811 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10812 | break; |
| 10813 | } |
| 10814 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10815 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10816 | break; |
| 10817 | default: |
| 10818 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10819 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10820 | } |
| 10821 | } catch (IllegalArgumentException e) { |
| 10822 | throw e; |
| 10823 | } catch (Exception e) { |
| 10824 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10825 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10826 | } finally { |
| 10827 | Binder.restoreCallingIdentity(identity); |
| 10828 | } |
| 10829 | |
| 10830 | if (DBG) { |
| 10831 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10832 | + thermalMitigationResult); |
| 10833 | } |
| 10834 | |
| 10835 | return thermalMitigationResult; |
| 10836 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10837 | |
| 10838 | /** |
| 10839 | * Set the GbaService Package Name that Telephony will bind to. |
| 10840 | * |
| 10841 | * @param subId The sim that the GbaService is associated with. |
| 10842 | * @param packageName The name of the package to be replaced with. |
| 10843 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10844 | */ |
| 10845 | @Override |
| 10846 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10847 | enforceModifyPermission(); |
| 10848 | |
| 10849 | final long identity = Binder.clearCallingIdentity(); |
| 10850 | try { |
| 10851 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10852 | } finally { |
| 10853 | Binder.restoreCallingIdentity(identity); |
| 10854 | } |
| 10855 | } |
| 10856 | |
| 10857 | /** |
| 10858 | * Return the package name of the currently bound GbaService. |
| 10859 | * |
| 10860 | * @param subId The sim that the GbaService is associated with. |
| 10861 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10862 | */ |
| 10863 | @Override |
| 10864 | public String getBoundGbaService(int subId) { |
| 10865 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10866 | |
| 10867 | final long identity = Binder.clearCallingIdentity(); |
| 10868 | try { |
| 10869 | return getGbaManager(subId).getServicePackage(); |
| 10870 | } finally { |
| 10871 | Binder.restoreCallingIdentity(identity); |
| 10872 | } |
| 10873 | } |
| 10874 | |
| 10875 | /** |
| 10876 | * Set the release time for telephony to unbind GbaService. |
| 10877 | * |
| 10878 | * @param subId The sim that the GbaService is associated with. |
| 10879 | * @param interval The release time to unbind GbaService by millisecond. |
| 10880 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10881 | */ |
| 10882 | @Override |
| 10883 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10884 | enforceModifyPermission(); |
| 10885 | |
| 10886 | final long identity = Binder.clearCallingIdentity(); |
| 10887 | try { |
| 10888 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10889 | } finally { |
| 10890 | Binder.restoreCallingIdentity(identity); |
| 10891 | } |
| 10892 | } |
| 10893 | |
| 10894 | /** |
| 10895 | * Return the release time for telephony to unbind GbaService. |
| 10896 | * |
| 10897 | * @param subId The sim that the GbaService is associated with. |
| 10898 | * @return The release time to unbind GbaService by millisecond. |
| 10899 | */ |
| 10900 | @Override |
| 10901 | public int getGbaReleaseTime(int subId) { |
| 10902 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10903 | |
| 10904 | final long identity = Binder.clearCallingIdentity(); |
| 10905 | try { |
| 10906 | return getGbaManager(subId).getReleaseTime(); |
| 10907 | } finally { |
| 10908 | Binder.restoreCallingIdentity(identity); |
| 10909 | } |
| 10910 | } |
| 10911 | |
| 10912 | private GbaManager getGbaManager(int subId) { |
| 10913 | GbaManager instance = GbaManager.getInstance(subId); |
| 10914 | if (instance == null) { |
| 10915 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10916 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10917 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10918 | } |
| 10919 | return instance; |
| 10920 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10921 | |
| 10922 | /** |
| 10923 | * indicate whether the device and the carrier can support |
| 10924 | * RCS VoLTE single registration. |
| 10925 | */ |
| 10926 | @Override |
| 10927 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10928 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10929 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10930 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10931 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10932 | |
| 10933 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10934 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10935 | } |
| 10936 | |
| 10937 | final long identity = Binder.clearCallingIdentity(); |
| 10938 | try { |
| 10939 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10940 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10941 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10942 | if (isCapable != null) { |
| 10943 | return isCapable; |
| 10944 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10945 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10946 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10947 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10948 | } finally { |
| 10949 | Binder.restoreCallingIdentity(identity); |
| 10950 | } |
| 10951 | } |
| 10952 | |
| 10953 | /** |
| 10954 | * Register RCS provisioning callback. |
| 10955 | */ |
| 10956 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10957 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10958 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10959 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10960 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10961 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10962 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10963 | |
| 10964 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10965 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10966 | } |
| 10967 | if (!isImsAvailableOnDevice()) { |
| 10968 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10969 | "IMS not available on device."); |
| 10970 | } |
| 10971 | |
| 10972 | final long identity = Binder.clearCallingIdentity(); |
| 10973 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10974 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10975 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10976 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10977 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10978 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10979 | } finally { |
| 10980 | Binder.restoreCallingIdentity(identity); |
| 10981 | } |
| 10982 | } |
| 10983 | |
| 10984 | /** |
| 10985 | * Unregister RCS provisioning callback. |
| 10986 | */ |
| 10987 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10988 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10989 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10990 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10991 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10992 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10993 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10994 | |
| 10995 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10996 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10997 | } |
| 10998 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10999 | // operation failed silently |
| 11000 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11001 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11002 | } |
| 11003 | |
| 11004 | final long identity = Binder.clearCallingIdentity(); |
| 11005 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11006 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11007 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11008 | } finally { |
| 11009 | Binder.restoreCallingIdentity(identity); |
| 11010 | } |
| 11011 | } |
| 11012 | |
| 11013 | /** |
| 11014 | * trigger RCS reconfiguration. |
| 11015 | */ |
| 11016 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11017 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11018 | "triggerRcsReconfiguration", |
| 11019 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11020 | |
| 11021 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11022 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11023 | } |
| 11024 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11025 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11026 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11027 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11028 | } |
| 11029 | |
| 11030 | final long identity = Binder.clearCallingIdentity(); |
| 11031 | try { |
| 11032 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11033 | } finally { |
| 11034 | Binder.restoreCallingIdentity(identity); |
| 11035 | } |
| 11036 | } |
| 11037 | |
| 11038 | /** |
| 11039 | * Provide the client configuration parameters of the RCS application. |
| 11040 | */ |
| 11041 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11042 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11043 | "setRcsClientConfiguration", |
| 11044 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11045 | |
| 11046 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11047 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11048 | } |
| 11049 | if (!isImsAvailableOnDevice()) { |
| 11050 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11051 | "IMS not available on device."); |
| 11052 | } |
| 11053 | |
| 11054 | final long identity = Binder.clearCallingIdentity(); |
| 11055 | |
| 11056 | try { |
| 11057 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11058 | if (configBinder == null) { |
| 11059 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11060 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11061 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11062 | } else { |
| 11063 | configBinder.setRcsClientConfiguration(rcc); |
| 11064 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11065 | |
| 11066 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11067 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11068 | } catch (RemoteException e) { |
| 11069 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11070 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11071 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11072 | } finally { |
| 11073 | Binder.restoreCallingIdentity(identity); |
| 11074 | } |
| 11075 | } |
| 11076 | |
| 11077 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11078 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11079 | */ |
| 11080 | @Override |
| 11081 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11082 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11083 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11084 | |
| 11085 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11086 | } |
| 11087 | |
| 11088 | /** |
| 11089 | * Gets the test mode for RCS VoLTE single registration. |
| 11090 | */ |
| 11091 | @Override |
| 11092 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11093 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11094 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11095 | |
| 11096 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11097 | } |
| 11098 | |
| 11099 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11100 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11101 | */ |
| 11102 | @Override |
| 11103 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11104 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11105 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11106 | enforceModifyPermission(); |
| 11107 | |
| 11108 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11109 | : Boolean.parseBoolean(enabledStr); |
| 11110 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11111 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11112 | } |
| 11113 | |
| 11114 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11115 | * Sends a device to device communication message. Only usable via shell. |
| 11116 | * @param message message to send. |
| 11117 | * @param value message value. |
| 11118 | */ |
| 11119 | @Override |
| 11120 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11121 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11122 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11123 | enforceModifyPermission(); |
| 11124 | |
| 11125 | final long identity = Binder.clearCallingIdentity(); |
| 11126 | try { |
| 11127 | TelephonyConnectionService service = |
| 11128 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11129 | if (service == null) { |
| 11130 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11131 | return; |
| 11132 | } |
| 11133 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11134 | } finally { |
| 11135 | Binder.restoreCallingIdentity(identity); |
| 11136 | } |
| 11137 | } |
| 11138 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11139 | /** |
| 11140 | * Sets the specified device to device transport active. |
| 11141 | * @param transport The transport to set active. |
| 11142 | */ |
| 11143 | @Override |
| 11144 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11145 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11146 | "setActiveDeviceToDeviceTransport"); |
| 11147 | enforceModifyPermission(); |
| 11148 | |
| 11149 | final long identity = Binder.clearCallingIdentity(); |
| 11150 | try { |
| 11151 | TelephonyConnectionService service = |
| 11152 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11153 | if (service == null) { |
| 11154 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11155 | return; |
| 11156 | } |
| 11157 | service.setActiveDeviceToDeviceTransport(transport); |
| 11158 | } finally { |
| 11159 | Binder.restoreCallingIdentity(identity); |
| 11160 | } |
| 11161 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11162 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11163 | @Override |
| 11164 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11165 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11166 | "setDeviceToDeviceForceEnabled"); |
| 11167 | |
| 11168 | final long identity = Binder.clearCallingIdentity(); |
| 11169 | try { |
| 11170 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11171 | p -> { |
| 11172 | Phone thePhone = p.getImsPhone(); |
| 11173 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11174 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11175 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11176 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11177 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11178 | (ImsPhoneCallTracker) tracker; |
| 11179 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11180 | } |
| 11181 | } |
| 11182 | } |
| 11183 | ); |
| 11184 | } finally { |
| 11185 | Binder.restoreCallingIdentity(identity); |
| 11186 | } |
| 11187 | } |
| 11188 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11189 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11190 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11191 | */ |
| 11192 | @Override |
| 11193 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11194 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11195 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11196 | } |
| 11197 | |
| 11198 | /** |
| 11199 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11200 | */ |
| 11201 | @Override |
| 11202 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11203 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11204 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11205 | enforceModifyPermission(); |
| 11206 | |
| 11207 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11208 | : Boolean.parseBoolean(enabledStr); |
| 11209 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11210 | subId, enabled); |
| 11211 | } |
| 11212 | |
| 11213 | /** |
| 11214 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11215 | */ |
| 11216 | @Override |
| 11217 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11218 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11219 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11220 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11221 | |
| 11222 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11223 | * Overrides the ims feature validation result |
| 11224 | */ |
| 11225 | @Override |
| 11226 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11227 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11228 | "setImsFeatureValidationOverride"); |
| 11229 | |
| 11230 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11231 | : Boolean.parseBoolean(enabledStr); |
| 11232 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11233 | subId, enabled); |
| 11234 | } |
| 11235 | |
| 11236 | /** |
| 11237 | * Gets the ims feature validation override value |
| 11238 | */ |
| 11239 | @Override |
| 11240 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11241 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11242 | "getImsFeatureValidationOverride"); |
| 11243 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11244 | } |
| 11245 | |
| 11246 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11247 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11248 | * their mobile plan. |
| 11249 | */ |
| 11250 | @Override |
| 11251 | public String getMobileProvisioningUrl() { |
| 11252 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11253 | final long identity = Binder.clearCallingIdentity(); |
| 11254 | try { |
| 11255 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11256 | } finally { |
| 11257 | Binder.restoreCallingIdentity(identity); |
| 11258 | } |
| 11259 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11260 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11261 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11262 | * Get the EAB contact from the EAB database. |
| 11263 | */ |
| 11264 | @Override |
| 11265 | public String getContactFromEab(String contact) { |
| 11266 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11267 | enforceModifyPermission(); |
| 11268 | final long identity = Binder.clearCallingIdentity(); |
| 11269 | try { |
| 11270 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11271 | } finally { |
| 11272 | Binder.restoreCallingIdentity(identity); |
| 11273 | } |
| 11274 | } |
| 11275 | |
| 11276 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11277 | * Get the EAB capability from the EAB database. |
| 11278 | */ |
| 11279 | @Override |
| 11280 | public String getCapabilityFromEab(String contact) { |
| 11281 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11282 | enforceModifyPermission(); |
| 11283 | final long identity = Binder.clearCallingIdentity(); |
| 11284 | try { |
| 11285 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11286 | } finally { |
| 11287 | Binder.restoreCallingIdentity(identity); |
| 11288 | } |
| 11289 | } |
| 11290 | |
| 11291 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11292 | * Remove the EAB contacts from the EAB database. |
| 11293 | */ |
| 11294 | @Override |
| 11295 | public int removeContactFromEab(int subId, String contacts) { |
| 11296 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11297 | enforceModifyPermission(); |
| 11298 | final long identity = Binder.clearCallingIdentity(); |
| 11299 | try { |
| 11300 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11301 | } finally { |
| 11302 | Binder.restoreCallingIdentity(identity); |
| 11303 | } |
| 11304 | } |
| 11305 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11306 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11307 | public boolean getDeviceUceEnabled() { |
| 11308 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11309 | final long identity = Binder.clearCallingIdentity(); |
| 11310 | try { |
| 11311 | return mApp.getDeviceUceEnabled(); |
| 11312 | } finally { |
| 11313 | Binder.restoreCallingIdentity(identity); |
| 11314 | } |
| 11315 | } |
| 11316 | |
| 11317 | @Override |
| 11318 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11319 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11320 | final long identity = Binder.clearCallingIdentity(); |
| 11321 | try { |
| 11322 | mApp.setDeviceUceEnabled(isEnabled); |
| 11323 | } finally { |
| 11324 | Binder.restoreCallingIdentity(identity); |
| 11325 | } |
| 11326 | } |
| 11327 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11328 | /** |
| 11329 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11330 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11331 | */ |
| 11332 | // Used for SHELL command only right now. |
| 11333 | @Override |
| 11334 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11335 | List<String> featureTags) { |
| 11336 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11337 | "addUceRegistrationOverrideShell"); |
| 11338 | final long identity = Binder.clearCallingIdentity(); |
| 11339 | try { |
| 11340 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11341 | new ArraySet<>(featureTags)); |
| 11342 | } catch (ImsException e) { |
| 11343 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11344 | } finally { |
| 11345 | Binder.restoreCallingIdentity(identity); |
| 11346 | } |
| 11347 | } |
| 11348 | |
| 11349 | /** |
| 11350 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11351 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11352 | */ |
| 11353 | // Used for SHELL command only right now. |
| 11354 | @Override |
| 11355 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11356 | List<String> featureTags) { |
| 11357 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11358 | "removeUceRegistrationOverrideShell"); |
| 11359 | final long identity = Binder.clearCallingIdentity(); |
| 11360 | try { |
| 11361 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11362 | new ArraySet<>(featureTags)); |
| 11363 | } catch (ImsException e) { |
| 11364 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11365 | } finally { |
| 11366 | Binder.restoreCallingIdentity(identity); |
| 11367 | } |
| 11368 | } |
| 11369 | |
| 11370 | /** |
| 11371 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11372 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11373 | */ |
| 11374 | // Used for SHELL command only right now. |
| 11375 | @Override |
| 11376 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11377 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11378 | "clearUceRegistrationOverrideShell"); |
| 11379 | final long identity = Binder.clearCallingIdentity(); |
| 11380 | try { |
| 11381 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11382 | } catch (ImsException e) { |
| 11383 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11384 | } finally { |
| 11385 | Binder.restoreCallingIdentity(identity); |
| 11386 | } |
| 11387 | } |
| 11388 | |
| 11389 | /** |
| 11390 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11391 | */ |
| 11392 | // Used for SHELL command only right now. |
| 11393 | @Override |
| 11394 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11395 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11396 | "getLatestRcsContactUceCapabilityShell"); |
| 11397 | final long identity = Binder.clearCallingIdentity(); |
| 11398 | try { |
| 11399 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11400 | } catch (ImsException e) { |
| 11401 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11402 | } finally { |
| 11403 | Binder.restoreCallingIdentity(identity); |
| 11404 | } |
| 11405 | } |
| 11406 | |
| 11407 | /** |
| 11408 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11409 | * device does not have an active PUBLISH. |
| 11410 | */ |
| 11411 | // Used for SHELL command only right now. |
| 11412 | @Override |
| 11413 | public String getLastUcePidfXmlShell(int subId) { |
| 11414 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11415 | final long identity = Binder.clearCallingIdentity(); |
| 11416 | try { |
| 11417 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11418 | } catch (ImsException e) { |
| 11419 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11420 | } finally { |
| 11421 | Binder.restoreCallingIdentity(identity); |
| 11422 | } |
| 11423 | } |
| 11424 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11425 | /** |
| 11426 | * Remove UCE requests cannot be sent to the network status. |
| 11427 | */ |
| 11428 | // Used for SHELL command only right now. |
| 11429 | @Override |
| 11430 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11431 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11432 | final long identity = Binder.clearCallingIdentity(); |
| 11433 | try { |
| 11434 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11435 | } catch (ImsException e) { |
| 11436 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11437 | } finally { |
| 11438 | Binder.restoreCallingIdentity(identity); |
| 11439 | } |
| 11440 | } |
| 11441 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11442 | /** |
| 11443 | * Remove UCE requests cannot be sent to the network status. |
| 11444 | */ |
| 11445 | // Used for SHELL command only. |
| 11446 | @Override |
| 11447 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11448 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11449 | final long identity = Binder.clearCallingIdentity(); |
| 11450 | try { |
| 11451 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11452 | } catch (ImsException e) { |
| 11453 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11454 | } finally { |
| 11455 | Binder.restoreCallingIdentity(identity); |
| 11456 | } |
| 11457 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11458 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11459 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11460 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11461 | String callingPackage) { |
| 11462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11463 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11464 | |
| 11465 | final int callingUid = Binder.getCallingUid(); |
| 11466 | // Verify that tha callingPackage belongs to the calling UID |
| 11467 | mApp.getSystemService(AppOpsManager.class) |
| 11468 | .checkPackage(callingUid, callingPackage); |
| 11469 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11470 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11471 | |
| 11472 | final long identity = Binder.clearCallingIdentity(); |
| 11473 | try { |
| 11474 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11475 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11476 | |
| 11477 | if (result instanceof IllegalStateException) { |
| 11478 | throw (IllegalStateException) result; |
| 11479 | } |
| 11480 | } finally { |
| 11481 | Binder.restoreCallingIdentity(identity); |
| 11482 | } |
| 11483 | } |
| 11484 | |
| 11485 | @Override |
| 11486 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11487 | String callingPackage) { |
| 11488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11489 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11490 | |
| 11491 | final int callingUid = Binder.getCallingUid(); |
| 11492 | // Verify that tha callingPackage belongs to the calling UID |
| 11493 | mApp.getSystemService(AppOpsManager.class) |
| 11494 | .checkPackage(callingUid, callingPackage); |
| 11495 | |
| 11496 | final long identity = Binder.clearCallingIdentity(); |
| 11497 | try { |
| 11498 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11499 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11500 | |
| 11501 | if (result instanceof IllegalStateException) { |
| 11502 | throw (IllegalStateException) result; |
| 11503 | } |
| 11504 | } finally { |
| 11505 | Binder.restoreCallingIdentity(identity); |
| 11506 | } |
| 11507 | } |
| 11508 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11509 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11510 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11511 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11512 | // phone/system process do not have further restriction on request |
| 11513 | return; |
| 11514 | } |
| 11515 | |
| 11516 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11517 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11518 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11519 | context.enforceCallingOrSelfPermission( |
| 11520 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11521 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11522 | } |
| 11523 | |
| 11524 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11525 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11526 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11527 | || info.isEnabled()) { |
| 11528 | throw new IllegalArgumentException( |
| 11529 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11530 | } |
| 11531 | |
| 11532 | // Thresholds length for each RAN need in range. This has been validated in |
| 11533 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11534 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11535 | final int[] thresholds = info.getThresholds(); |
| 11536 | Objects.requireNonNull(thresholds); |
| 11537 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11538 | || thresholds.length |
| 11539 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11540 | throw new IllegalArgumentException( |
| 11541 | "thresholds length is out of range: " + thresholds.length); |
| 11542 | } |
| 11543 | } |
| 11544 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11545 | |
| 11546 | /** |
| 11547 | * Gets the current phone capability. |
| 11548 | * |
| 11549 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11550 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11551 | * It's used to evaluate possible phone config change, for example from single |
| 11552 | * SIM device to multi-SIM device. |
| 11553 | */ |
| 11554 | @Override |
| 11555 | public PhoneCapability getPhoneCapability() { |
| 11556 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11557 | final long identity = Binder.clearCallingIdentity(); |
| 11558 | try { |
| 11559 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11560 | } finally { |
| 11561 | Binder.restoreCallingIdentity(identity); |
| 11562 | } |
| 11563 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11564 | |
| 11565 | /** |
| 11566 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11567 | * required to be done shortly after the API is invoked. |
| 11568 | */ |
| 11569 | @Override |
| 11570 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11571 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11572 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11573 | enforceRebootPermission(); |
| 11574 | |
| 11575 | final long identity = Binder.clearCallingIdentity(); |
| 11576 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11577 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11578 | } finally { |
| 11579 | Binder.restoreCallingIdentity(identity); |
| 11580 | } |
| 11581 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11582 | |
| 11583 | /** |
| 11584 | * Request to get the current slicing configuration including URSP rules and |
| 11585 | * NSSAIs (configured, allowed and rejected). |
| 11586 | * |
| 11587 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11588 | */ |
| 11589 | @Override |
| 11590 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11591 | TelephonyPermissions |
| 11592 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11593 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11594 | |
| 11595 | final long identity = Binder.clearCallingIdentity(); |
| 11596 | try { |
| 11597 | Phone phone = getDefaultPhone(); |
| 11598 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11599 | } finally { |
| 11600 | Binder.restoreCallingIdentity(identity); |
| 11601 | } |
| 11602 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11603 | |
| 11604 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11605 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11606 | * |
| 11607 | * @param capability The premium capability to check. |
| 11608 | * @param subId The subId to check the premium capability for. |
| 11609 | * |
| 11610 | * @return Whether the given premium capability is available to purchase. |
| 11611 | */ |
| 11612 | @Override |
| 11613 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11614 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11615 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11616 | log("Premium capability " |
| 11617 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11618 | + " is not available for purchase due to missing permissions."); |
| 11619 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11620 | + "permission READ_BASIC_PHONE_STATE."); |
| 11621 | } |
| 11622 | |
| 11623 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11624 | if (phone == null) { |
| 11625 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11626 | return false; |
| 11627 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11628 | final long identity = Binder.clearCallingIdentity(); |
| 11629 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 11630 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11631 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11632 | } finally { |
| 11633 | Binder.restoreCallingIdentity(identity); |
| 11634 | } |
| 11635 | } |
| 11636 | |
| 11637 | /** |
| 11638 | * Purchase the given premium capability from the carrier. |
| 11639 | * |
| 11640 | * @param capability The premium capability to purchase. |
| 11641 | * @param callback The result of the purchase request. |
| 11642 | * @param subId The subId to purchase the premium capability for. |
| 11643 | */ |
| 11644 | @Override |
| 11645 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11646 | log("purchasePremiumCapability: capability=" |
| 11647 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11648 | + getCurrentPackageName()); |
| 11649 | |
| 11650 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11651 | mApp, "purchasePremiumCapability")) { |
| 11652 | log("purchasePremiumCapability " |
| 11653 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11654 | + " failed due to missing permissions."); |
| 11655 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11656 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11657 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11658 | mApp, "purchasePremiumCapability")) { |
| 11659 | log("purchasePremiumCapability " |
| 11660 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11661 | + " failed due to missing permissions."); |
| 11662 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11663 | } |
| 11664 | |
| 11665 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11666 | if (phone == null) { |
| 11667 | try { |
| 11668 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11669 | callback.accept(result); |
| 11670 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11671 | } catch (RemoteException e) { |
| 11672 | String logStr = "Purchase premium capability " |
| 11673 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11674 | + " failed due to RemoteException handling null phone: " + e; |
| 11675 | if (DBG) log(logStr); |
| 11676 | AnomalyReporter.reportAnomaly( |
| 11677 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11678 | } |
| 11679 | return; |
| 11680 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11681 | |
| 11682 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11683 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11684 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11685 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11686 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11687 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11688 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11689 | |
| 11690 | boolean isVisible = false; |
| 11691 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11692 | if (am != null) { |
| 11693 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11694 | if (processes != null) { |
| 11695 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11696 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 11697 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11698 | if (process.processName.equals(callingProcess) && process.importance |
| 11699 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11700 | isVisible = true; |
| 11701 | break; |
| 11702 | } |
| 11703 | } |
| 11704 | } |
| 11705 | } |
| 11706 | |
| 11707 | if (!isVisible) { |
| 11708 | try { |
| 11709 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11710 | callback.accept(result); |
| 11711 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11712 | } catch (RemoteException e) { |
| 11713 | String logStr = "Purchase premium capability " |
| 11714 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11715 | + " failed due to RemoteException handling background application: " + e; |
| 11716 | if (DBG) log(logStr); |
| 11717 | AnomalyReporter.reportAnomaly( |
| 11718 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11719 | } |
| 11720 | return; |
| 11721 | } |
| 11722 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11723 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11724 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11725 | } |
| 11726 | |
| 11727 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11728 | * Register an IMS connection state callback |
| 11729 | */ |
| 11730 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11731 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11732 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11733 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11734 | // ImsMmTelManager |
| 11735 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11736 | TelephonyPermissions |
| 11737 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11738 | mApp, subId, "registerImsStateCallback"); |
| 11739 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11740 | // ImsRcsManager or SipDelegateManager |
| 11741 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11742 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11743 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11744 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11745 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11746 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11747 | } |
| 11748 | |
| 11749 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11751 | "IMS not available on device."); |
| 11752 | } |
| 11753 | |
| 11754 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11756 | } |
| 11757 | |
| 11758 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11759 | if (controller == null) { |
| 11760 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11761 | "IMS not available on device."); |
| 11762 | } |
| 11763 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11764 | if (callingPackage == null) { |
| 11765 | callingPackage = getCurrentPackageName(); |
| 11766 | } |
| 11767 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11768 | final long token = Binder.clearCallingIdentity(); |
| 11769 | try { |
| 11770 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11771 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11772 | } catch (ImsException e) { |
| 11773 | throw new ServiceSpecificException(e.getCode()); |
| 11774 | } finally { |
| 11775 | Binder.restoreCallingIdentity(token); |
| 11776 | } |
| 11777 | } |
| 11778 | |
| 11779 | /** |
| 11780 | * Unregister an IMS connection state callback |
| 11781 | */ |
| 11782 | @Override |
| 11783 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11784 | final long token = Binder.clearCallingIdentity(); |
| 11785 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11786 | if (controller == null) { |
| 11787 | return; |
| 11788 | } |
| 11789 | try { |
| 11790 | controller.unregisterImsStateCallback(cb); |
| 11791 | } finally { |
| 11792 | Binder.restoreCallingIdentity(token); |
| 11793 | } |
| 11794 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11795 | |
| 11796 | /** |
| 11797 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11798 | * |
| 11799 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11800 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11801 | * SecurityException. |
| 11802 | * If there is current registered network this value will be same as the registered cell |
| 11803 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11804 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11805 | * it will be cleared and null will be returned. |
| 11806 | * |
| 11807 | */ |
| 11808 | @Override |
| 11809 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11810 | String callingFeatureId) { |
| 11811 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11812 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11813 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11814 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11815 | .setCallingPackage(callingPackage) |
| 11816 | .setCallingFeatureId(callingFeatureId) |
| 11817 | .setCallingPid(Binder.getCallingPid()) |
| 11818 | .setCallingUid(Binder.getCallingUid()) |
| 11819 | .setMethod("getLastKnownCellIdentity") |
| 11820 | .setLogAsInfo(true) |
| 11821 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11822 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11823 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11824 | .build()); |
| 11825 | |
| 11826 | boolean hasFinePermission = |
| 11827 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11828 | if (!hasFinePermission |
| 11829 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11830 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11831 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11832 | } |
| 11833 | |
| 11834 | final long identity = Binder.clearCallingIdentity(); |
| 11835 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11836 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11837 | if (sst == null) return null; |
| 11838 | return sst.getLastKnownCellIdentity(); |
| 11839 | } finally { |
| 11840 | Binder.restoreCallingIdentity(identity); |
| 11841 | } |
| 11842 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11843 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11844 | /** |
| 11845 | * Sets the modem service class Name that Telephony will bind to. |
| 11846 | * |
| 11847 | * @param serviceName The class name of the modem service. |
| 11848 | * @return true if the operation is succeed, otherwise false. |
| 11849 | */ |
| 11850 | public boolean setModemService(String serviceName) { |
| 11851 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11852 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11853 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11854 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11855 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11856 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11857 | } |
| 11858 | |
| 11859 | /** |
| 11860 | * Return the class name of the currently bounded modem service. |
| 11861 | * |
| 11862 | * @return the class name of the modem service. |
| 11863 | */ |
| 11864 | public String getModemService() { |
| 11865 | String result; |
| 11866 | Log.d(LOG_TAG, "getModemService"); |
| 11867 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11868 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11869 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11870 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11871 | "getModemService"); |
| 11872 | result = mPhoneConfigurationManager.getModemService(); |
| 11873 | Log.d(LOG_TAG, "result = " + result); |
| 11874 | return result; |
| 11875 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11876 | |
| 11877 | @Override |
| 11878 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11879 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11880 | mApp.enforceCallingOrSelfPermission( |
| 11881 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11882 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11883 | |
| 11884 | final long identity = Binder.clearCallingIdentity(); |
| 11885 | try { |
| 11886 | Phone phone = getPhone(subId); |
| 11887 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11888 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11889 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11890 | phone.setVoiceServiceStateOverride(hasService); |
| 11891 | } finally { |
| 11892 | Binder.restoreCallingIdentity(identity); |
| 11893 | } |
| 11894 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11895 | |
| 11896 | /** |
| 11897 | * set removable eSIM as default eUICC. |
| 11898 | * |
| 11899 | * @hide |
| 11900 | */ |
| 11901 | @Override |
| 11902 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11903 | enforceModifyPermission(); |
| 11904 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11905 | |
| 11906 | final long identity = Binder.clearCallingIdentity(); |
| 11907 | try { |
| 11908 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11909 | } finally { |
| 11910 | Binder.restoreCallingIdentity(identity); |
| 11911 | } |
| 11912 | } |
| 11913 | |
| 11914 | /** |
| 11915 | * Returns whether the removable eSIM is default eUICC or not. |
| 11916 | * |
| 11917 | * @hide |
| 11918 | */ |
| 11919 | @Override |
| 11920 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11921 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11922 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11923 | |
| 11924 | final long identity = Binder.clearCallingIdentity(); |
| 11925 | try { |
| 11926 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11927 | } finally { |
| 11928 | Binder.restoreCallingIdentity(identity); |
| 11929 | } |
| 11930 | } |
| 11931 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11932 | /** |
| 11933 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11934 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11935 | * application currently configured for this user. |
| 11936 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11937 | * {@code null} if the functionality is not supported. |
| 11938 | * @hide |
| 11939 | */ |
| 11940 | @Override |
| 11941 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11942 | boolean updateIfNeeded) { |
| 11943 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11944 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11945 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11946 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11947 | UserHandle userHandle = null; |
| 11948 | final long identity = Binder.clearCallingIdentity(); |
| 11949 | try { |
| 11950 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11951 | } finally { |
| 11952 | Binder.restoreCallingIdentity(identity); |
| 11953 | } |
| 11954 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11955 | updateIfNeeded, userHandle); |
| 11956 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11957 | |
| 11958 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11959 | * Set whether the device is able to connect with null ciphering or integrity |
| 11960 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11961 | * and all new subscriptions after this. |
| 11962 | * |
| 11963 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11964 | * @hide |
| 11965 | */ |
| 11966 | @Override |
| 11967 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11968 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11969 | enforceModifyPermission(); |
| 11970 | checkForNullCipherAndIntegritySupport(); |
| 11971 | |
| 11972 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11973 | // for listening to these preference changes and applying them immediately. |
| 11974 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11975 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11976 | editor.apply(); |
| 11977 | |
| 11978 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11979 | phone.handleNullCipherEnabledChange(); |
| 11980 | } |
| 11981 | } |
| 11982 | |
| 11983 | |
| 11984 | /** |
| 11985 | * Get whether the device is able to connect with null ciphering or integrity |
| 11986 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11987 | * the state of the radio. |
| 11988 | * |
| 11989 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11990 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11991 | * version for this feature. |
| 11992 | * @hide |
| 11993 | */ |
| 11994 | @Override |
| 11995 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11996 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11997 | enforceReadPermission(); |
| 11998 | checkForNullCipherAndIntegritySupport(); |
| 11999 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12000 | } |
| 12001 | |
| 12002 | private void checkForNullCipherAndIntegritySupport() { |
| 12003 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12004 | throw new UnsupportedOperationException( |
| 12005 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12006 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12007 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12008 | throw new UnsupportedOperationException( |
| 12009 | "Null cipher and integrity operations unsupported by modem"); |
| 12010 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12011 | } |
| 12012 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12013 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12014 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12015 | throw new UnsupportedOperationException( |
| 12016 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12017 | + "above"); |
| 12018 | } |
| 12019 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12020 | throw new UnsupportedOperationException( |
| 12021 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12022 | } |
| 12023 | } |
| 12024 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12025 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12026 | * Get the SIM state for the slot index. |
| 12027 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12028 | * |
| 12029 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12030 | */ |
| 12031 | @Override |
| 12032 | @SimState |
| 12033 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12034 | IccCardConstants.State simState; |
| 12035 | if (slotIndex < 0) { |
| 12036 | simState = IccCardConstants.State.UNKNOWN; |
| 12037 | } else { |
| 12038 | Phone phone = null; |
| 12039 | try { |
| 12040 | phone = PhoneFactory.getPhone(slotIndex); |
| 12041 | } catch (IllegalStateException e) { |
| 12042 | // ignore |
| 12043 | } |
| 12044 | if (phone == null) { |
| 12045 | simState = IccCardConstants.State.UNKNOWN; |
| 12046 | } else { |
| 12047 | IccCard icc = phone.getIccCard(); |
| 12048 | if (icc == null) { |
| 12049 | simState = IccCardConstants.State.UNKNOWN; |
| 12050 | } else { |
| 12051 | simState = icc.getState(); |
| 12052 | } |
| 12053 | } |
| 12054 | } |
| 12055 | return simState.ordinal(); |
| 12056 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12057 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12058 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12059 | boolean enableLogcat, |
| 12060 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12061 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12062 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 12063 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 12064 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 12065 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 12066 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 12067 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 12068 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 12069 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12070 | Executors.newCachedThreadPool(), db, |
| 12071 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 12072 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12073 | } |
| 12074 | |
| 12075 | /** |
| 12076 | * Request telephony to persist state for debugging emergency call failures. |
| 12077 | * |
| 12078 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 12079 | * @param enableLogcat whether to collect logcat output |
| 12080 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12081 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12082 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12083 | */ |
| 12084 | @Override |
| 12085 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12086 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12087 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12088 | boolean enableTelephonyDump) { |
| 12089 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12090 | "persistEmergencyCallDiagnosticData"); |
| 12091 | final long identity = Binder.clearCallingIdentity(); |
| 12092 | try { |
| 12093 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12094 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12095 | |
| 12096 | } finally { |
| 12097 | Binder.restoreCallingIdentity(identity); |
| 12098 | } |
| 12099 | } |
| 12100 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12101 | /** |
| 12102 | * Get current cell broadcast ranges. |
| 12103 | */ |
| 12104 | @Override |
| 12105 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12106 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12107 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12108 | "getCellBroadcastIdRanges"); |
| 12109 | final long identity = Binder.clearCallingIdentity(); |
| 12110 | try { |
| 12111 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12112 | } finally { |
| 12113 | Binder.restoreCallingIdentity(identity); |
| 12114 | } |
| 12115 | } |
| 12116 | |
| 12117 | /** |
| 12118 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12119 | * |
| 12120 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12121 | */ |
| 12122 | @Override |
| 12123 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12124 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12125 | @Nullable IIntegerConsumer callback) { |
| 12126 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12127 | "setCellBroadcastIdRanges"); |
| 12128 | final long identity = Binder.clearCallingIdentity(); |
| 12129 | try { |
| 12130 | Phone phone = getPhoneFromSubId(subId); |
| 12131 | if (DBG) { |
| 12132 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12133 | } |
| 12134 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12135 | if (callback != null) { |
| 12136 | try { |
| 12137 | callback.accept(result); |
| 12138 | } catch (RemoteException e) { |
| 12139 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12140 | } |
| 12141 | } |
| 12142 | }); |
| 12143 | } finally { |
| 12144 | Binder.restoreCallingIdentity(identity); |
| 12145 | } |
| 12146 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12147 | |
| 12148 | /** |
| 12149 | * Returns whether the device supports the domain selection service. |
| 12150 | * |
| 12151 | * @return {@code true} if the device supports the domain selection service. |
| 12152 | */ |
| 12153 | @Override |
| 12154 | public boolean isDomainSelectionSupported() { |
| 12155 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12156 | "isDomainSelectionSupported"); |
| 12157 | |
| 12158 | final long identity = Binder.clearCallingIdentity(); |
| 12159 | try { |
| 12160 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12161 | } finally { |
| 12162 | Binder.restoreCallingIdentity(identity); |
| 12163 | } |
| 12164 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12165 | |
| 12166 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12167 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12168 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12169 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12170 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12171 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12172 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12173 | * {@code false} to disable. |
| 12174 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12175 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12176 | * |
| 12177 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12178 | */ |
| 12179 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12180 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12181 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12182 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12183 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12184 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12185 | } |
| 12186 | |
| 12187 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12188 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12189 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12190 | * @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] | 12191 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12192 | * 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] | 12193 | * |
| 12194 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12195 | */ |
| 12196 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12197 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12198 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12199 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12200 | } |
| 12201 | |
| 12202 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12203 | * Request to get whether the satellite service demo mode is enabled. |
| 12204 | * |
| 12205 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12206 | * is enabled for. |
| 12207 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12208 | * if the request is successful or an error code if the request failed. |
| 12209 | * |
| 12210 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12211 | */ |
| 12212 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12213 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12214 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12215 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12216 | } |
| 12217 | |
| 12218 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12219 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12220 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12221 | * @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] | 12222 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12223 | * 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] | 12224 | */ |
| 12225 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12226 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12227 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12228 | } |
| 12229 | |
| 12230 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12231 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12232 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12233 | * @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] | 12234 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12235 | * 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] | 12236 | * |
| 12237 | * @throws SecurityException if the caller doesn't have required permission. |
| 12238 | */ |
| 12239 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12240 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12241 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12242 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12243 | } |
| 12244 | |
| 12245 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12246 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12247 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12248 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12249 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12250 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12251 | * @param resultCallback The callback to get the result of the request. |
| 12252 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12253 | * |
| 12254 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12255 | */ |
| 12256 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12257 | public void startSatelliteTransmissionUpdates(int subId, |
| 12258 | @NonNull IIntegerConsumer resultCallback, |
| 12259 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12260 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12261 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12262 | } |
| 12263 | |
| 12264 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12265 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12266 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12267 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12268 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12269 | * @param resultCallback The callback to get the result of the request. |
| 12270 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12271 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12272 | * |
| 12273 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12274 | */ |
| 12275 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12276 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12277 | @NonNull IIntegerConsumer resultCallback, |
| 12278 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12279 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12280 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12281 | } |
| 12282 | |
| 12283 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12284 | * Register the subscription with a satellite provider. |
| 12285 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12286 | * |
| 12287 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12288 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12289 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12290 | * @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] | 12291 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12292 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12293 | * @return The signal transport used by the caller to cancel the provision request, |
| 12294 | * or {@code null} if the request failed. |
| 12295 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12296 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12297 | */ |
| 12298 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12299 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12300 | @NonNull String token, @NonNull byte[] provisionData, |
| 12301 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12302 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12303 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 12304 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12305 | } |
| 12306 | |
| 12307 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12308 | * Unregister the device/subscription with the satellite provider. |
| 12309 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12310 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12311 | * should report as deprovisioned. |
| 12312 | * |
| 12313 | * @param subId The subId of the subscription to be deprovisioned. |
| 12314 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12315 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12316 | * |
| 12317 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12318 | */ |
| 12319 | @Override |
| 12320 | public void deprovisionSatelliteService(int subId, |
| 12321 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12322 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12323 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12324 | } |
| 12325 | |
| 12326 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12327 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12328 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12329 | * @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] | 12330 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12331 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12332 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12333 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12334 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12335 | */ |
| 12336 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12337 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 12338 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12339 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12340 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12341 | } |
| 12342 | |
| 12343 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12344 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12345 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12346 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12347 | * @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] | 12348 | * @param callback The callback that was passed to |
| 12349 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12350 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12351 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12352 | */ |
| 12353 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12354 | public void unregisterForSatelliteProvisionStateChanged( |
| 12355 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12356 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12357 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12358 | } |
| 12359 | |
| 12360 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12361 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12362 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12363 | * @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] | 12364 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12365 | * satellite provider if the request is successful or an error code if the |
| 12366 | * request failed. |
| 12367 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12368 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12369 | */ |
| 12370 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12371 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12372 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12373 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12374 | } |
| 12375 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12376 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12377 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12378 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12379 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12380 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12381 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12382 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12383 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12384 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12385 | */ |
| 12386 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12387 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12388 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12389 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12390 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12391 | } |
| 12392 | |
| 12393 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12394 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12395 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12396 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12397 | * @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] | 12398 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12399 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12400 | * |
| 12401 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12402 | */ |
| 12403 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12404 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12405 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12406 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12407 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12408 | } |
| 12409 | |
| 12410 | /** |
| 12411 | * Register to receive incoming datagrams over satellite. |
| 12412 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12413 | * @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] | 12414 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12415 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12416 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12417 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12418 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12419 | */ |
| 12420 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12421 | @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12422 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12423 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12424 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12425 | } |
| 12426 | |
| 12427 | /** |
| 12428 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12429 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12430 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12431 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12432 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12433 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12434 | * |
| 12435 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12436 | */ |
| 12437 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12438 | public void unregisterForSatelliteDatagram(int subId, |
| 12439 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12440 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12441 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12442 | } |
| 12443 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12444 | /** |
| 12445 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12446 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12447 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12448 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 12449 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12450 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12451 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12452 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12453 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12454 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12455 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12456 | @Override |
| 12457 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12458 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12459 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12460 | } |
| 12461 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12462 | /** |
| 12463 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12464 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12465 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 12466 | * input to this method. Datagram received here will be passed down to modem without any |
| 12467 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12468 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12469 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 12470 | * @param datagramType datagram type indicating whether the datagram is of type |
| 12471 | * SOS_SMS or LOCATION_SHARING. |
| 12472 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 12473 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12474 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 12475 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12476 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12477 | * |
| 12478 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12479 | */ |
| 12480 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12481 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 12482 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 12483 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12484 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12485 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 12486 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12487 | } |
| 12488 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12489 | /** |
| 12490 | * Request to get whether satellite communication is allowed for the current location. |
| 12491 | * |
| 12492 | * @param subId The subId of the subscription to check whether satellite communication is |
| 12493 | * allowed for the current location for. |
| 12494 | * @param result The result receiver that returns whether satellite communication is allowed |
| 12495 | * for the current location if the request is successful or an error code |
| 12496 | * if the request failed. |
| 12497 | * |
| 12498 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12499 | */ |
| 12500 | @Override |
| 12501 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 12502 | @NonNull ResultReceiver result) { |
| 12503 | enforceSatelliteCommunicationPermission( |
| 12504 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12505 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 12506 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12507 | } |
| 12508 | |
| 12509 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12510 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12511 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12512 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12513 | * @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] | 12514 | * be visible if the request is successful or an error code if the request failed. |
| 12515 | * |
| 12516 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12517 | */ |
| 12518 | @Override |
| 12519 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 12520 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12521 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12522 | } |
| 12523 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12524 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12525 | * Inform that Device is aligned to satellite for demo mode. |
| 12526 | * |
| 12527 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12528 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 12529 | * {@code false} Device fails to align with the satellite for demo mode. |
| 12530 | * |
| 12531 | * @throws SecurityException if the caller doesn't have required permission. |
| 12532 | */ |
| 12533 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 12534 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12535 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12536 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12537 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12538 | } |
| 12539 | |
| 12540 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 12541 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12542 | * by modem. |
| 12543 | * |
| 12544 | * @param subId The subId of the subscription to request for. |
| 12545 | * @param reason Reason for disallowing satellite communication for carrier. |
| 12546 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12547 | * operation. |
| 12548 | * |
| 12549 | * @throws SecurityException if the caller doesn't have required permission. |
| 12550 | */ |
| 12551 | public void addSatelliteAttachRestrictionForCarrier(int subId, |
| 12552 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12553 | @NonNull IIntegerConsumer callback) { |
| 12554 | enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier"); |
| 12555 | final long identity = Binder.clearCallingIdentity(); |
| 12556 | try { |
| 12557 | mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback); |
| 12558 | } finally { |
| 12559 | Binder.restoreCallingIdentity(identity); |
| 12560 | } |
| 12561 | } |
| 12562 | |
| 12563 | /** |
| 12564 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12565 | * by modem. |
| 12566 | * |
| 12567 | * @param subId The subId of the subscription to request for. |
| 12568 | * @param reason Reason for disallowing satellite communication. |
| 12569 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12570 | * operation. |
| 12571 | * |
| 12572 | * @throws SecurityException if the caller doesn't have required permission. |
| 12573 | */ |
| 12574 | public void removeSatelliteAttachRestrictionForCarrier(int subId, |
| 12575 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12576 | @NonNull IIntegerConsumer callback) { |
| 12577 | enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier"); |
| 12578 | final long identity = Binder.clearCallingIdentity(); |
| 12579 | try { |
| 12580 | mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason, |
| 12581 | callback); |
| 12582 | } finally { |
| 12583 | Binder.restoreCallingIdentity(identity); |
| 12584 | } |
| 12585 | } |
| 12586 | |
| 12587 | /** |
| 12588 | * Get reasons for disallowing satellite communication, as requested by |
| 12589 | * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
| 12590 | * |
| 12591 | * @param subId The subId of the subscription to request for. |
| 12592 | * |
| 12593 | * @return Integer array of reasons for disallowing satellite communication. |
| 12594 | * |
| 12595 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12596 | */ |
| 12597 | public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier( |
| 12598 | int subId) { |
| 12599 | enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier"); |
| 12600 | final long identity = Binder.clearCallingIdentity(); |
| 12601 | try { |
| 12602 | Set<Integer> reasonSet = |
| 12603 | mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId); |
| 12604 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 12605 | } finally { |
| 12606 | Binder.restoreCallingIdentity(identity); |
| 12607 | } |
| 12608 | } |
| 12609 | |
| 12610 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12611 | * Request to get the signal strength of the satellite connection. |
| 12612 | * |
| 12613 | * @param subId The subId of the subscription to request for. |
| 12614 | * @param result Result receiver to get the error code of the request and the current signal |
| 12615 | * strength of the satellite connection. |
| 12616 | * |
| 12617 | * @throws SecurityException if the caller doesn't have required permission. |
| 12618 | */ |
| 12619 | @Override |
| 12620 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 12621 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 12622 | final long identity = Binder.clearCallingIdentity(); |
| 12623 | try { |
| 12624 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 12625 | } finally { |
| 12626 | Binder.restoreCallingIdentity(identity); |
| 12627 | } |
| 12628 | } |
| 12629 | |
| 12630 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12631 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 12632 | * is not successful, a {@link ServiceSpecificException} that contains |
| 12633 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12634 | * |
| 12635 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12636 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 12637 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 12638 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 12639 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 12640 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12641 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12642 | * @throws SecurityException If the caller doesn't have the required permission. |
| 12643 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12644 | */ |
| 12645 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12646 | public void registerForNtnSignalStrengthChanged(int subId, |
| 12647 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12648 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 12649 | final long identity = Binder.clearCallingIdentity(); |
| 12650 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12651 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12652 | } finally { |
| 12653 | Binder.restoreCallingIdentity(identity); |
| 12654 | } |
| 12655 | } |
| 12656 | |
| 12657 | /** |
| 12658 | * Unregisters for NTN signal strength changed from satellite modem. |
| 12659 | * If callback was not registered before, the request will be ignored. |
| 12660 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12661 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 12662 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12663 | * @param callback The callback that was passed to |
| 12664 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 12665 | * |
| 12666 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12667 | */ |
| 12668 | @Override |
| 12669 | public void unregisterForNtnSignalStrengthChanged( |
| 12670 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 12671 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 12672 | final long identity = Binder.clearCallingIdentity(); |
| 12673 | try { |
| 12674 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 12675 | } finally { |
| 12676 | Binder.restoreCallingIdentity(identity); |
| 12677 | } |
| 12678 | } |
| 12679 | |
| 12680 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12681 | * Registers for satellite capabilities change event from the satellite service. |
| 12682 | * |
| 12683 | * @param subId The subId of the subscription to request for. |
| 12684 | * @param callback The callback to handle the satellite capabilities changed event. |
| 12685 | * |
| 12686 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 12687 | * |
| 12688 | * @throws SecurityException if the caller doesn't have required permission. |
| 12689 | */ |
| 12690 | @Override |
| 12691 | @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged( |
| 12692 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12693 | enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged"); |
| 12694 | final long identity = Binder.clearCallingIdentity(); |
| 12695 | try { |
| 12696 | return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback); |
| 12697 | } finally { |
| 12698 | Binder.restoreCallingIdentity(identity); |
| 12699 | } |
| 12700 | } |
| 12701 | |
| 12702 | /** |
| 12703 | * Unregisters for satellite capabilities change event from the satellite service. |
| 12704 | * If callback was not registered before, the request will be ignored. |
| 12705 | * |
| 12706 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 12707 | * @param callback The callback that was passed to. |
| 12708 | * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
| 12709 | * |
| 12710 | * @throws SecurityException if the caller doesn't have required permission. |
| 12711 | */ |
| 12712 | @Override |
| 12713 | public void unregisterForSatelliteCapabilitiesChanged( |
| 12714 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12715 | enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged"); |
| 12716 | final long identity = Binder.clearCallingIdentity(); |
| 12717 | try { |
| 12718 | mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback); |
| 12719 | } finally { |
| 12720 | Binder.restoreCallingIdentity(identity); |
| 12721 | } |
| 12722 | } |
| 12723 | |
| 12724 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 12725 | * This API can be used by only CTS to update satellite vendor service package name. |
| 12726 | * |
| 12727 | * @param servicePackageName The package name of the satellite vendor service. |
| 12728 | * @return {@code true} if the satellite vendor service is set successfully, |
| 12729 | * {@code false} otherwise. |
| 12730 | */ |
| 12731 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 12732 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 12733 | TelephonyPermissions.enforceShellOnly( |
| 12734 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 12735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12736 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12737 | "setSatelliteServicePackageName"); |
| 12738 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 12739 | } |
| 12740 | |
| 12741 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 12742 | * This API can be used by only CTS to update satellite gateway service package name. |
| 12743 | * |
| 12744 | * @param servicePackageName The package name of the satellite gateway service. |
| 12745 | * @return {@code true} if the satellite gateway service is set successfully, |
| 12746 | * {@code false} otherwise. |
| 12747 | */ |
| 12748 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 12749 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 12750 | TelephonyPermissions.enforceShellOnly( |
| 12751 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 12752 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12753 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12754 | "setSatelliteGatewayServicePackageName"); |
| 12755 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 12756 | } |
| 12757 | |
| 12758 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 12759 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 12760 | * |
| 12761 | * @param packageName The package name of the satellite pointing UI app. |
| 12762 | * @param className The class name of the satellite pointing UI app. |
| 12763 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 12764 | * {@code false} otherwise. |
| 12765 | */ |
| 12766 | public boolean setSatellitePointingUiClassName( |
| 12767 | @Nullable String packageName, @Nullable String className) { |
| 12768 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 12769 | + ", className=" + className); |
| 12770 | TelephonyPermissions.enforceShellOnly( |
| 12771 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 12772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12773 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12774 | "setSatelliteGatewayServicePackageName"); |
| 12775 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 12776 | } |
| 12777 | |
| 12778 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 12779 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 12780 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 12781 | * listening mode. |
| 12782 | * |
| 12783 | * @param timeoutMillis The timeout duration in millisecond. |
| 12784 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12785 | */ |
| 12786 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 12787 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 12788 | TelephonyPermissions.enforceShellOnly( |
| 12789 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 12790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12791 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12792 | "setSatelliteListeningTimeoutDuration"); |
| 12793 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 12794 | } |
| 12795 | |
| 12796 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12797 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 12798 | * the device is aligned with the satellite for demo mode |
| 12799 | * |
| 12800 | * @param timeoutMillis The timeout duration in millisecond. |
| 12801 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12802 | */ |
| 12803 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 12804 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 12805 | TelephonyPermissions.enforceShellOnly( |
| 12806 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 12807 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12808 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12809 | "setDeviceAlignedTimeoutDuration"); |
| 12810 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 12811 | } |
| 12812 | |
| 12813 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 12814 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 12815 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 12816 | * |
| 12817 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 12818 | * of the following values to enable the override: |
| 12819 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 12820 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 12821 | * To disable the override, use -1 for handoverType. |
| 12822 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 12823 | * delaySeconds after the emergency call starts. |
| 12824 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 12825 | */ |
| 12826 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 12827 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 12828 | TelephonyPermissions.enforceShellOnly( |
| 12829 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 12830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12831 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12832 | "setEmergencyCallToSatelliteHandoverType"); |
| 12833 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 12834 | handoverType, delaySeconds); |
| 12835 | } |
| 12836 | |
| 12837 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 12838 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 12839 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 12840 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 12841 | * |
| 12842 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 12843 | * satellite modem or not. |
| 12844 | * |
| 12845 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 12846 | */ |
| 12847 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 12848 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 12849 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 12850 | + "disabled"); |
| 12851 | return false; |
| 12852 | } |
| 12853 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 12854 | TelephonyPermissions.enforceShellOnly( |
| 12855 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 12856 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12857 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12858 | "setShouldSendDatagramToModemInDemoMode"); |
| 12859 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 12860 | shouldSendToModemInDemoMode); |
| 12861 | } |
| 12862 | |
| 12863 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12864 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 12865 | * |
| 12866 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 12867 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 12868 | * identifier is sent in the clear, which has privacy implications for the user. |
| 12869 | * |
| 12870 | * @param enable if notifications about disclosure events should be enabled |
| 12871 | * @throws SecurityException if the caller does not have the required privileges |
| 12872 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 12873 | */ |
| 12874 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 12875 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12876 | enforceModifyPermission(); |
| 12877 | checkForIdentifierDisclosureNotificationSupport(); |
| 12878 | |
| 12879 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12880 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 12881 | editor.apply(); |
| 12882 | |
| 12883 | // Each phone instance is responsible for updating its respective modem immediately |
| 12884 | // after we've made a preference change. |
| 12885 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12886 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 12887 | } |
| 12888 | } |
| 12889 | |
| 12890 | /** |
| 12891 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 12892 | * |
| 12893 | * @throws SecurityException if the caller does not have the required privileges |
| 12894 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 12895 | */ |
| 12896 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 12897 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12898 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 12899 | checkForIdentifierDisclosureNotificationSupport(); |
| 12900 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 12901 | } |
| 12902 | |
| 12903 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12904 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12905 | * |
| 12906 | * <p>This method behaves in one of the following ways: |
| 12907 | * <ul> |
| 12908 | * <li>return true : if the calling package has the appop permission {@link |
| 12909 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12910 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12911 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12912 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12913 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12914 | * </ul> |
| 12915 | */ |
| 12916 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12917 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12918 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12919 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12920 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12921 | return true; |
| 12922 | } |
| 12923 | } |
| 12924 | return false; |
| 12925 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12926 | |
| 12927 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12928 | * @return The subscription manager service instance. |
| 12929 | */ |
| 12930 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12931 | return SubscriptionManagerService.getInstance(); |
| 12932 | } |
| 12933 | |
| 12934 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12935 | * Class binds the consumer[callback] and carrierId. |
| 12936 | */ |
| 12937 | private static class CallerCallbackInfo { |
| 12938 | private final Consumer<Integer> mConsumer; |
| 12939 | private final int mCarrierId; |
| 12940 | |
| 12941 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12942 | mConsumer = consumer; |
| 12943 | mCarrierId = carrierId; |
| 12944 | } |
| 12945 | |
| 12946 | public Consumer<Integer> getConsumer() { |
| 12947 | return mConsumer; |
| 12948 | } |
| 12949 | |
| 12950 | public int getCarrierId() { |
| 12951 | return mCarrierId; |
| 12952 | } |
| 12953 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12954 | } |