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; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame^] | 406 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 407 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 408 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 409 | /** The singleton instance. */ |
| 410 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 411 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 412 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 413 | private final PhoneGlobals mApp; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 414 | private final FeatureFlags mFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 415 | private final CallManager mCM; |
| 416 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 417 | |
| 418 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 419 | private final UserManager mUserManager; |
| 420 | private final AppOpsManager mAppOps; |
| 421 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 422 | private final SharedPreferences mTelephonySharedPreferences; |
| 423 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 424 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 426 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 427 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 428 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 429 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 430 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 431 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 432 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 433 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 434 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 435 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 436 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 437 | // String to store multi SIM allowed |
| 438 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 439 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 440 | // The AID of ISD-R. |
| 441 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 442 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 443 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 444 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 445 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 446 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 447 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 448 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 449 | 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] | 450 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 451 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 452 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 453 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 454 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 455 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 456 | */ |
| 457 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 458 | "reset_network_erase_modem_config_enabled"; |
| 459 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 460 | 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] | 461 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 462 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 463 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 464 | /** |
| 465 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 466 | * one ICCID active at the same time. |
| 467 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 468 | * |
| 469 | * @hide |
| 470 | */ |
| 471 | @ChangeId |
| 472 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 473 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 474 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 475 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 476 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 477 | * operation fails. |
| 478 | */ |
| 479 | @ChangeId |
| 480 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 481 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 482 | |
| 483 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 484 | * A request object to use for transmitting data to an ICC. |
| 485 | */ |
| 486 | private static final class IccAPDUArgument { |
| 487 | public int channel, cla, command, p1, p2, p3; |
| 488 | public String data; |
| 489 | |
| 490 | public IccAPDUArgument(int channel, int cla, int command, |
| 491 | int p1, int p2, int p3, String data) { |
| 492 | this.channel = channel; |
| 493 | this.cla = cla; |
| 494 | this.command = command; |
| 495 | this.p1 = p1; |
| 496 | this.p2 = p2; |
| 497 | this.p3 = p3; |
| 498 | this.data = data; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 503 | * A request object to use for transmitting data to an ICC. |
| 504 | */ |
| 505 | private static final class ManualNetworkSelectionArgument { |
| 506 | public OperatorInfo operatorInfo; |
| 507 | public boolean persistSelection; |
| 508 | |
| 509 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 510 | this.operatorInfo = operatorInfo; |
| 511 | this.persistSelection = persistSelection; |
| 512 | } |
| 513 | } |
| 514 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 515 | private static final class PurchasePremiumCapabilityArgument { |
| 516 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 517 | public @NonNull IIntegerConsumer callback; |
| 518 | |
| 519 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 520 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 521 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 522 | this.callback = callback; |
| 523 | } |
| 524 | } |
| 525 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 526 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 527 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 528 | * request after sending. The main thread will notify the request when it is complete. |
| 529 | */ |
| 530 | private static final class MainThreadRequest { |
| 531 | /** The argument to use for the request */ |
| 532 | public Object argument; |
| 533 | /** The result of the request that is run on the main thread */ |
| 534 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 535 | // The subscriber id that this request applies to. Defaults to |
| 536 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 537 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 538 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 539 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 540 | public Phone phone; |
| 541 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 542 | public WorkSource workSource; |
| 543 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 544 | public MainThreadRequest(Object argument) { |
| 545 | this.argument = argument; |
| 546 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 547 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 548 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 549 | this.argument = argument; |
| 550 | if (phone != null) { |
| 551 | this.phone = phone; |
| 552 | } |
| 553 | this.workSource = workSource; |
| 554 | } |
| 555 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 556 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 557 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 558 | if (subId != null) { |
| 559 | this.subId = subId; |
| 560 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 561 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 562 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 565 | private static final class IncomingThirdPartyCallArgs { |
| 566 | public final ComponentName component; |
| 567 | public final String callId; |
| 568 | public final String callerDisplayName; |
| 569 | |
| 570 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 571 | String callerDisplayName) { |
| 572 | this.component = component; |
| 573 | this.callId = callId; |
| 574 | this.callerDisplayName = callerDisplayName; |
| 575 | } |
| 576 | } |
| 577 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 578 | /** |
| 579 | * A handler that processes messages on the main thread in the phone process. Since many |
| 580 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 581 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 582 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 583 | * on, which will be notified when the operation completes and will contain the result of the |
| 584 | * request. |
| 585 | * |
| 586 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 587 | * note that request.result must be set to something non-null for the calling thread to |
| 588 | * unblock. |
| 589 | */ |
| 590 | private final class MainThreadHandler extends Handler { |
| 591 | @Override |
| 592 | public void handleMessage(Message msg) { |
| 593 | MainThreadRequest request; |
| 594 | Message onCompleted; |
| 595 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 596 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 598 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 599 | |
| 600 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 601 | case CMD_HANDLE_USSD_REQUEST: { |
| 602 | request = (MainThreadRequest) msg.obj; |
| 603 | final Phone phone = getPhoneFromRequest(request); |
| 604 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 605 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 607 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 608 | if (!isUssdApiAllowed(request.subId)) { |
| 609 | // Carrier does not support use of this API, return failure. |
| 610 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 611 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 612 | Bundle returnData = new Bundle(); |
| 613 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 614 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 615 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | request.result = true; |
| 617 | notifyRequester(request); |
| 618 | return; |
| 619 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 620 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | try { |
| 622 | request.result = phone != null |
| 623 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 624 | } catch (CallStateException cse) { |
| 625 | request.result = false; |
| 626 | } |
| 627 | // Wake up the requesting thread |
| 628 | notifyRequester(request); |
| 629 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 632 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 633 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 634 | final Phone phone = getPhoneFromRequest(request); |
| 635 | request.result = phone != null ? |
| 636 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 637 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 638 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 639 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 640 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 641 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 642 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 643 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 645 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 646 | uiccPort = getUiccPortFromRequest(request); |
| 647 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 648 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 649 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 650 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 651 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 652 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 653 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 654 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 655 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 656 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 657 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 658 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | break; |
| 660 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | ar = (AsyncResult) msg.obj; |
| 663 | request = (MainThreadRequest) ar.userObj; |
| 664 | if (ar.exception == null && ar.result != null) { |
| 665 | request.result = ar.result; |
| 666 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 667 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | if (ar.result == null) { |
| 669 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 670 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 672 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | } else { |
| 674 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 675 | } |
| 676 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 677 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | break; |
| 679 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 681 | request = (MainThreadRequest) msg.obj; |
| 682 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 683 | uiccPort = getUiccPortFromRequest(request); |
| 684 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 686 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 687 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 688 | } else { |
| 689 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 690 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 691 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 692 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 693 | iccArgument.p2, |
| 694 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | } |
| 696 | break; |
| 697 | |
| 698 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 699 | ar = (AsyncResult) msg.obj; |
| 700 | request = (MainThreadRequest) ar.userObj; |
| 701 | if (ar.exception == null && ar.result != null) { |
| 702 | request.result = ar.result; |
| 703 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 704 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 705 | if (ar.result == null) { |
| 706 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 707 | } else if (ar.exception instanceof CommandException) { |
| 708 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 709 | ar.exception); |
| 710 | } else { |
| 711 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 712 | } |
| 713 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 714 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 715 | break; |
| 716 | |
| 717 | case CMD_EXCHANGE_SIM_IO: |
| 718 | request = (MainThreadRequest) msg.obj; |
| 719 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 720 | uiccPort = getUiccPortFromRequest(request); |
| 721 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 722 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 723 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 724 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 725 | } else { |
| 726 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 727 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 728 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 729 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 730 | iccArgument.data, onCompleted); |
| 731 | } |
| 732 | break; |
| 733 | |
| 734 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 735 | ar = (AsyncResult) msg.obj; |
| 736 | request = (MainThreadRequest) ar.userObj; |
| 737 | if (ar.exception == null && ar.result != null) { |
| 738 | request.result = ar.result; |
| 739 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 740 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 741 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 743 | break; |
| 744 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 745 | case CMD_SEND_ENVELOPE: |
| 746 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 747 | uiccPort = getUiccPortFromRequest(request); |
| 748 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 749 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 750 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 751 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 752 | } else { |
| 753 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 754 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 755 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_SEND_ENVELOPE_DONE: |
| 759 | ar = (AsyncResult) msg.obj; |
| 760 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 761 | if (ar.exception == null && ar.result != null) { |
| 762 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 763 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 764 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 765 | if (ar.result == null) { |
| 766 | loge("sendEnvelopeWithStatus: Empty response"); |
| 767 | } else if (ar.exception instanceof CommandException) { |
| 768 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 769 | ar.exception); |
| 770 | } else { |
| 771 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 772 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 773 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 774 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 777 | case CMD_OPEN_CHANNEL: |
| 778 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 779 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 780 | IccLogicalChannelRequest openChannelRequest = |
| 781 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 782 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 783 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 784 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 785 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 786 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 787 | } else { |
| 788 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 789 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 790 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 791 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 792 | break; |
| 793 | |
| 794 | case EVENT_OPEN_CHANNEL_DONE: |
| 795 | ar = (AsyncResult) msg.obj; |
| 796 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 797 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 798 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 799 | int[] result = (int[]) ar.result; |
| 800 | int channelId = result[0]; |
| 801 | byte[] selectResponse = null; |
| 802 | if (result.length > 1) { |
| 803 | selectResponse = new byte[result.length - 1]; |
| 804 | for (int i = 1; i < result.length; ++i) { |
| 805 | selectResponse[i - 1] = (byte) result[i]; |
| 806 | } |
| 807 | } |
| 808 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 809 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 810 | |
| 811 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 812 | if (uiccPort == null) { |
| 813 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 814 | } else { |
| 815 | IccLogicalChannelRequest channelRequest = |
| 816 | (IccLogicalChannelRequest) request.argument; |
| 817 | channelRequest.channel = channelId; |
| 818 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 819 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 820 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 821 | if (ar.result == null) { |
| 822 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 823 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 824 | if (ar.exception != null) { |
| 825 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 826 | } |
| 827 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 828 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 829 | if (ar.exception instanceof CommandException) { |
| 830 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 831 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 832 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 833 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 834 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 835 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 839 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 840 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 841 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 842 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 843 | break; |
| 844 | |
| 845 | case CMD_CLOSE_CHANNEL: |
| 846 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 847 | uiccPort = getUiccPortFromRequest(request); |
| 848 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 849 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 850 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 851 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 852 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 853 | } else { |
| 854 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 855 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 856 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 857 | break; |
| 858 | |
| 859 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 860 | ar = (AsyncResult) msg.obj; |
| 861 | request = (MainThreadRequest) ar.userObj; |
| 862 | if (ar.exception == null) { |
| 863 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 864 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 865 | if (uiccPort == null) { |
| 866 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 867 | } else { |
| 868 | final int channelId = (Integer) request.argument; |
| 869 | uiccPort.onLogicalChannelClosed(channelId); |
| 870 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 871 | } else { |
| 872 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 873 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 874 | if (ar.exception instanceof CommandException) { |
| 875 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 876 | CommandException.Error error = |
| 877 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 878 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 879 | // should only throw exceptions from the binder threads. |
| 880 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 881 | "iccCloseLogicalChannel: invalid argument "); |
| 882 | } |
| 883 | } else { |
| 884 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 885 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 886 | request.result = (exception != null) ? exception : |
| 887 | new IllegalStateException( |
| 888 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 889 | } |
| 890 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 891 | break; |
| 892 | |
| 893 | case CMD_NV_READ_ITEM: |
| 894 | request = (MainThreadRequest) msg.obj; |
| 895 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 896 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 897 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 898 | break; |
| 899 | |
| 900 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 901 | ar = (AsyncResult) msg.obj; |
| 902 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 903 | if (ar.exception == null && ar.result != null) { |
| 904 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 905 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 906 | request.result = ""; |
| 907 | if (ar.result == null) { |
| 908 | loge("nvReadItem: Empty response"); |
| 909 | } else if (ar.exception instanceof CommandException) { |
| 910 | loge("nvReadItem: CommandException: " + |
| 911 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 912 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 913 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 914 | } |
| 915 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 916 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 917 | break; |
| 918 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 919 | case CMD_NV_WRITE_ITEM: |
| 920 | request = (MainThreadRequest) msg.obj; |
| 921 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 922 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 923 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 924 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 925 | break; |
| 926 | |
| 927 | case EVENT_NV_WRITE_ITEM_DONE: |
| 928 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 929 | break; |
| 930 | |
| 931 | case CMD_NV_WRITE_CDMA_PRL: |
| 932 | request = (MainThreadRequest) msg.obj; |
| 933 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 934 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 935 | break; |
| 936 | |
| 937 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 938 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 939 | break; |
| 940 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 941 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 942 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 943 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 944 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 945 | break; |
| 946 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 947 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 948 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 949 | break; |
| 950 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 951 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 952 | request = (MainThreadRequest) msg.obj; |
| 953 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 954 | request); |
| 955 | Phone phone = getPhoneFromRequest(request); |
| 956 | if (phone != null) { |
| 957 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 958 | } else { |
| 959 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 960 | request.result = false; |
| 961 | notifyRequester(request); |
| 962 | } |
| 963 | break; |
| 964 | } |
| 965 | |
| 966 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 967 | ar = (AsyncResult) msg.obj; |
| 968 | request = (MainThreadRequest) ar.userObj; |
| 969 | if (ar.exception == null && ar.result != null) { |
| 970 | request.result = ar.result; |
| 971 | } else { |
| 972 | // request.result must be set to something non-null |
| 973 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 974 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 975 | request.result = ar.result; |
| 976 | } else { |
| 977 | request.result = false; |
| 978 | } |
| 979 | if (ar.result == null) { |
| 980 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 981 | } else if (ar.exception instanceof CommandException) { |
| 982 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 983 | + ar.exception); |
| 984 | } else { |
| 985 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 986 | } |
| 987 | } |
| 988 | notifyRequester(request); |
| 989 | break; |
| 990 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 991 | case CMD_IS_VONR_ENABLED: { |
| 992 | request = (MainThreadRequest) msg.obj; |
| 993 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 994 | request); |
| 995 | Phone phone = getPhoneFromRequest(request); |
| 996 | if (phone != null) { |
| 997 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 998 | } else { |
| 999 | loge("isVoNrEnabled: No phone object"); |
| 1000 | request.result = false; |
| 1001 | notifyRequester(request); |
| 1002 | } |
| 1003 | break; |
| 1004 | } |
| 1005 | |
| 1006 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1007 | ar = (AsyncResult) msg.obj; |
| 1008 | request = (MainThreadRequest) ar.userObj; |
| 1009 | if (ar.exception == null && ar.result != null) { |
| 1010 | request.result = ar.result; |
| 1011 | } else { |
| 1012 | // request.result must be set to something non-null |
| 1013 | // for the calling thread to unblock |
| 1014 | if (ar.result != null) { |
| 1015 | request.result = ar.result; |
| 1016 | } else { |
| 1017 | request.result = false; |
| 1018 | } |
| 1019 | if (ar.result == null) { |
| 1020 | loge("isVoNrEnabled: Empty response"); |
| 1021 | } else if (ar.exception instanceof CommandException) { |
| 1022 | loge("isVoNrEnabled: CommandException: " |
| 1023 | + ar.exception); |
| 1024 | } else { |
| 1025 | loge("isVoNrEnabled: Unknown exception"); |
| 1026 | } |
| 1027 | } |
| 1028 | notifyRequester(request); |
| 1029 | break; |
| 1030 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1031 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1032 | request = (MainThreadRequest) msg.obj; |
| 1033 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1034 | Phone phone = getPhoneFromRequest(request); |
| 1035 | if (phone != null) { |
| 1036 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1037 | request.workSource); |
| 1038 | } else { |
| 1039 | loge("enableNrDualConnectivity: No phone object"); |
| 1040 | request.result = |
| 1041 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1042 | notifyRequester(request); |
| 1043 | } |
| 1044 | break; |
| 1045 | } |
| 1046 | |
| 1047 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1048 | ar = (AsyncResult) msg.obj; |
| 1049 | request = (MainThreadRequest) ar.userObj; |
| 1050 | if (ar.exception == null) { |
| 1051 | request.result = |
| 1052 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1053 | } else { |
| 1054 | request.result = |
| 1055 | TelephonyManager |
| 1056 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1057 | if (ar.exception instanceof CommandException) { |
| 1058 | CommandException.Error error = |
| 1059 | ((CommandException) (ar.exception)).getCommandError(); |
| 1060 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1061 | request.result = |
| 1062 | TelephonyManager |
| 1063 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1064 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1065 | request.result = |
| 1066 | TelephonyManager |
| 1067 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1068 | } |
| 1069 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1070 | + ar.exception); |
| 1071 | } else { |
| 1072 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1073 | } |
| 1074 | } |
| 1075 | notifyRequester(request); |
| 1076 | break; |
| 1077 | } |
| 1078 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1079 | case CMD_ENABLE_VONR: { |
| 1080 | request = (MainThreadRequest) msg.obj; |
| 1081 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1082 | Phone phone = getPhoneFromRequest(request); |
| 1083 | if (phone != null) { |
| 1084 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1085 | request.workSource); |
| 1086 | } else { |
| 1087 | loge("setVoNrEnabled: No phone object"); |
| 1088 | request.result = |
| 1089 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1090 | notifyRequester(request); |
| 1091 | } |
| 1092 | break; |
| 1093 | } |
| 1094 | |
| 1095 | case EVENT_ENABLE_VONR_DONE: { |
| 1096 | ar = (AsyncResult) msg.obj; |
| 1097 | request = (MainThreadRequest) ar.userObj; |
| 1098 | if (ar.exception == null) { |
| 1099 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1100 | } else { |
| 1101 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1102 | if (ar.exception instanceof CommandException) { |
| 1103 | CommandException.Error error = |
| 1104 | ((CommandException) (ar.exception)).getCommandError(); |
| 1105 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1106 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1107 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1108 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1109 | } else { |
| 1110 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1111 | } |
| 1112 | loge("setVoNrEnabled" + ": CommandException: " |
| 1113 | + ar.exception); |
| 1114 | } else { |
| 1115 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1116 | } |
| 1117 | } |
| 1118 | notifyRequester(request); |
| 1119 | break; |
| 1120 | } |
| 1121 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1122 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1123 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1124 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1125 | request); |
| 1126 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1129 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1130 | ar = (AsyncResult) msg.obj; |
| 1131 | request = (MainThreadRequest) ar.userObj; |
| 1132 | if (ar.exception == null && ar.result != null) { |
| 1133 | request.result = ar.result; // Integer |
| 1134 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1135 | // request.result must be set to something non-null |
| 1136 | // for the calling thread to unblock |
| 1137 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1138 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1139 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1140 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1141 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1142 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1143 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1144 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1145 | } |
| 1146 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1147 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1148 | break; |
| 1149 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1150 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1151 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1152 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1153 | request); |
| 1154 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1155 | (Pair<Integer, Long>) request.argument; |
| 1156 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1157 | reasonWithNetworkTypes.first, |
| 1158 | reasonWithNetworkTypes.second, |
| 1159 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1160 | break; |
| 1161 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1162 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1163 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1164 | break; |
| 1165 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1166 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1167 | request = (MainThreadRequest) msg.obj; |
| 1168 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1169 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1170 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1171 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1172 | break; |
| 1173 | |
| 1174 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1175 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1176 | break; |
| 1177 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1178 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1179 | request = (MainThreadRequest) msg.obj; |
| 1180 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1181 | request); |
| 1182 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1183 | break; |
| 1184 | |
| 1185 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1186 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1187 | break; |
| 1188 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1189 | case CMD_PERFORM_NETWORK_SCAN: |
| 1190 | request = (MainThreadRequest) msg.obj; |
| 1191 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1192 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1193 | break; |
| 1194 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1195 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1196 | request = (MainThreadRequest) msg.obj; |
| 1197 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1198 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1199 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1200 | request.argument; |
| 1201 | int callForwardingReason = args.first; |
| 1202 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | } |
| 1205 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1206 | ar = (AsyncResult) msg.obj; |
| 1207 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1208 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1209 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1210 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1212 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1213 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1214 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1215 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1216 | // any service for voice call. |
| 1217 | if ((callForwardInfo.serviceClass |
| 1218 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1219 | callForwardingInfo = new CallForwardingInfo( |
| 1220 | callForwardInfo.status |
| 1221 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | callForwardInfo.reason, |
| 1223 | callForwardInfo.number, |
| 1224 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | break; |
| 1226 | } |
| 1227 | } |
| 1228 | // Didn't find a call forward info for voice call. |
| 1229 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1230 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1231 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1233 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1234 | } else { |
| 1235 | if (ar.result == null) { |
| 1236 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1237 | } |
| 1238 | if (ar.exception != null) { |
| 1239 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1240 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1241 | int errorCode = TelephonyManager |
| 1242 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1243 | if (ar.exception instanceof CommandException) { |
| 1244 | CommandException.Error error = |
| 1245 | ((CommandException) (ar.exception)).getCommandError(); |
| 1246 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1247 | errorCode = TelephonyManager |
| 1248 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1250 | errorCode = TelephonyManager |
| 1251 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | } |
| 1253 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1257 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1259 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | request = (MainThreadRequest) msg.obj; |
| 1261 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1262 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1265 | request.argument).first; |
| 1266 | request.phone.setCallForwardingOption( |
| 1267 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1268 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1270 | callForwardingInfoToSet.getReason(), |
| 1271 | callForwardingInfoToSet.getNumber(), |
| 1272 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1273 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | ar = (AsyncResult) msg.obj; |
| 1278 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1279 | Consumer<Integer> callback = |
| 1280 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1281 | request.argument).second; |
| 1282 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1283 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1284 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1285 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1286 | if (ar.exception instanceof CommandException) { |
| 1287 | CommandException.Error error = |
| 1288 | ((CommandException) (ar.exception)).getCommandError(); |
| 1289 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1290 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1291 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1292 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1293 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1294 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | callback.accept(errorCode); |
| 1298 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1299 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1300 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1302 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | request = (MainThreadRequest) msg.obj; |
| 1306 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1307 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1308 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1311 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | ar = (AsyncResult) msg.obj; |
| 1313 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1315 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1317 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1318 | // Service Class is a bit mask per 3gpp 27.007. |
| 1319 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1320 | if (callForwardResults.length > 1 |
| 1321 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1322 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1323 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1324 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1325 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1326 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1327 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1328 | } |
| 1329 | } else { |
| 1330 | if (ar.result == null) { |
| 1331 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1332 | } |
| 1333 | if (ar.exception != null) { |
| 1334 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1335 | } |
| 1336 | if (ar.exception instanceof CommandException) { |
| 1337 | CommandException.Error error = |
| 1338 | ((CommandException) (ar.exception)).getCommandError(); |
| 1339 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1340 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1341 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1342 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1343 | callWaitingStatus = |
| 1344 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1348 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1349 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1350 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1351 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1353 | request = (MainThreadRequest) msg.obj; |
| 1354 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1355 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1356 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1357 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1358 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1359 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1360 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1361 | ar = (AsyncResult) msg.obj; |
| 1362 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1363 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1364 | Consumer<Integer> callback = |
| 1365 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1366 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1367 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1368 | if (ar.exception instanceof CommandException) { |
| 1369 | CommandException.Error error = |
| 1370 | ((CommandException) (ar.exception)).getCommandError(); |
| 1371 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1372 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1373 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1374 | callback.accept( |
| 1375 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1376 | } else { |
| 1377 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1378 | } |
| 1379 | } else { |
| 1380 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1381 | } |
| 1382 | } else { |
| 1383 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1384 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1385 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1386 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1387 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1388 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1389 | ar = (AsyncResult) msg.obj; |
| 1390 | request = (MainThreadRequest) ar.userObj; |
| 1391 | CellNetworkScanResult cellScanResult; |
| 1392 | if (ar.exception == null && ar.result != null) { |
| 1393 | cellScanResult = new CellNetworkScanResult( |
| 1394 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1395 | (List<OperatorInfo>) ar.result); |
| 1396 | } else { |
| 1397 | if (ar.result == null) { |
| 1398 | loge("getCellNetworkScanResults: Empty response"); |
| 1399 | } |
| 1400 | if (ar.exception != null) { |
| 1401 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1402 | } |
| 1403 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1404 | if (ar.exception instanceof CommandException) { |
| 1405 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1406 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1407 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1408 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1409 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1410 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1411 | } |
| 1412 | } |
| 1413 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1414 | } |
| 1415 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1416 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1417 | break; |
| 1418 | |
| 1419 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1420 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1421 | ManualNetworkSelectionArgument selArg = |
| 1422 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1423 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1424 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1425 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1426 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1427 | break; |
| 1428 | |
| 1429 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1430 | ar = (AsyncResult) msg.obj; |
| 1431 | request = (MainThreadRequest) ar.userObj; |
| 1432 | if (ar.exception == null) { |
| 1433 | request.result = true; |
| 1434 | } else { |
| 1435 | request.result = false; |
| 1436 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1437 | } |
| 1438 | notifyRequester(request); |
| 1439 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1440 | break; |
| 1441 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1442 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1443 | request = (MainThreadRequest) msg.obj; |
| 1444 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1445 | if (defaultPhone != null) { |
| 1446 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1447 | } else { |
| 1448 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1449 | Bundle bundle = new Bundle(); |
| 1450 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1451 | new ModemActivityInfo(0, 0, 0, |
| 1452 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1453 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1454 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1455 | break; |
| 1456 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1457 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1458 | ar = (AsyncResult) msg.obj; |
| 1459 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1460 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1461 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1462 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1463 | if (mLastModemActivityInfo == null) { |
| 1464 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1465 | mLastModemActivitySpecificInfo[0] = |
| 1466 | new ActivityStatsTechSpecificInfo( |
| 1467 | 0, |
| 1468 | 0, |
| 1469 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1470 | 0); |
| 1471 | mLastModemActivityInfo = |
| 1472 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1473 | } |
| 1474 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1475 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1476 | // Update the last modem activity info and the result of the request. |
| 1477 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1478 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1479 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1480 | } else { |
| 1481 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1482 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1483 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1484 | // We don't want to return mLastModemActivityInfo which is updated |
| 1485 | // inside mergeModemActivityInfo() |
| 1486 | ret = new ModemActivityInfo( |
| 1487 | mLastModemActivityInfo.getTimestampMillis(), |
| 1488 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1489 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1490 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1491 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1492 | } else { |
| 1493 | if (ar.result == null) { |
| 1494 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1495 | error = TelephonyManager.ModemActivityInfoException |
| 1496 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1497 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1498 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1499 | error = TelephonyManager.ModemActivityInfoException |
| 1500 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1501 | } else { |
| 1502 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1503 | error = TelephonyManager.ModemActivityInfoException |
| 1504 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1505 | } |
| 1506 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1507 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1508 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1509 | bundle.putParcelable( |
| 1510 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1511 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1512 | } else { |
| 1513 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1514 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1515 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1516 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1517 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1518 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1519 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1520 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1521 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1522 | CarrierRestrictionRules argument = |
| 1523 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1524 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1525 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1526 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1527 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1528 | |
| 1529 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1530 | ar = (AsyncResult) msg.obj; |
| 1531 | request = (MainThreadRequest) ar.userObj; |
| 1532 | if (ar.exception == null && ar.result != null) { |
| 1533 | request.result = ar.result; |
| 1534 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1535 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1536 | if (ar.exception instanceof CommandException) { |
| 1537 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1538 | CommandException.Error error = |
| 1539 | ((CommandException) (ar.exception)).getCommandError(); |
| 1540 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1541 | request.result = |
| 1542 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1543 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1544 | } else { |
| 1545 | loge("setAllowedCarriers: Unknown exception"); |
| 1546 | } |
| 1547 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1548 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1549 | break; |
| 1550 | |
| 1551 | case CMD_GET_ALLOWED_CARRIERS: |
| 1552 | request = (MainThreadRequest) msg.obj; |
| 1553 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1554 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1555 | break; |
| 1556 | |
| 1557 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1558 | ar = (AsyncResult) msg.obj; |
| 1559 | request = (MainThreadRequest) ar.userObj; |
| 1560 | if (ar.exception == null && ar.result != null) { |
| 1561 | request.result = ar.result; |
| 1562 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1563 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1564 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1565 | if (ar.result == null) { |
| 1566 | loge("getAllowedCarriers: Empty response"); |
| 1567 | } else if (ar.exception instanceof CommandException) { |
| 1568 | loge("getAllowedCarriers: CommandException: " + |
| 1569 | ar.exception); |
| 1570 | } else { |
| 1571 | loge("getAllowedCarriers: Unknown exception"); |
| 1572 | } |
| 1573 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1574 | if (request.argument != null) { |
| 1575 | // This is for the implementation of carrierRestrictionStatus. |
| 1576 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1577 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1578 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1579 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1580 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1581 | CarrierRestrictionRules carrierRestrictionRules = |
| 1582 | (CarrierRestrictionRules) ar.result; |
| 1583 | int carrierId = -1; |
| 1584 | try { |
| 1585 | CarrierIdentifier carrierIdentifier = |
| 1586 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1587 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1588 | carrierIdentifier); |
| 1589 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1590 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1591 | } |
| 1592 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1593 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1594 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1595 | lockStatus = TelephonyManager |
| 1596 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1597 | } |
| 1598 | } else { |
| 1599 | Rlog.e(LOG_TAG, |
| 1600 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1601 | } |
| 1602 | callback.accept(lockStatus); |
| 1603 | } else { |
| 1604 | // This is for the implementation of getAllowedCarriers. |
| 1605 | notifyRequester(request); |
| 1606 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1607 | break; |
| 1608 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1609 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1610 | ar = (AsyncResult) msg.obj; |
| 1611 | request = (MainThreadRequest) ar.userObj; |
| 1612 | if (ar.exception == null && ar.result != null) { |
| 1613 | request.result = ar.result; |
| 1614 | } else { |
| 1615 | request.result = new IllegalArgumentException( |
| 1616 | "Failed to retrieve Forbidden Plmns"); |
| 1617 | if (ar.result == null) { |
| 1618 | loge("getForbiddenPlmns: Empty response"); |
| 1619 | } else { |
| 1620 | loge("getForbiddenPlmns: Unknown exception"); |
| 1621 | } |
| 1622 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1623 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1624 | break; |
| 1625 | |
| 1626 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1627 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1628 | uiccPort = getUiccPortFromRequest(request); |
| 1629 | if (uiccPort == null) { |
| 1630 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1631 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1632 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1633 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1634 | break; |
| 1635 | } |
| 1636 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1637 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1638 | if (uiccApp == null) { |
| 1639 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1640 | + appType); |
| 1641 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1642 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1643 | break; |
| 1644 | } else { |
| 1645 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1646 | + " specified type -- " + appType); |
| 1647 | } |
| 1648 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1649 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1650 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1651 | break; |
| 1652 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1653 | case CMD_SWITCH_SLOTS: |
| 1654 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1655 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1656 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1657 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1658 | break; |
| 1659 | |
| 1660 | case EVENT_SWITCH_SLOTS_DONE: |
| 1661 | ar = (AsyncResult) msg.obj; |
| 1662 | request = (MainThreadRequest) ar.userObj; |
| 1663 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1664 | notifyRequester(request); |
| 1665 | break; |
| 1666 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1667 | request = (MainThreadRequest) msg.obj; |
| 1668 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1669 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1670 | break; |
| 1671 | |
| 1672 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1673 | ar = (AsyncResult) msg.obj; |
| 1674 | request = (MainThreadRequest) ar.userObj; |
| 1675 | if (ar.exception != null) { |
| 1676 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1677 | } else { |
| 1678 | int mode = ((int[]) ar.result)[0]; |
| 1679 | if (mode == 0) { |
| 1680 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1681 | } else { |
| 1682 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1683 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1684 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1685 | notifyRequester(request); |
| 1686 | break; |
| 1687 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1688 | request = (MainThreadRequest) msg.obj; |
| 1689 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1690 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1691 | break; |
| 1692 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1693 | ar = (AsyncResult) msg.obj; |
| 1694 | request = (MainThreadRequest) ar.userObj; |
| 1695 | if (ar.exception != null) { |
| 1696 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1697 | } else { |
| 1698 | request.result = ((int[]) ar.result)[0]; |
| 1699 | } |
| 1700 | notifyRequester(request); |
| 1701 | break; |
| 1702 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1703 | request = (MainThreadRequest) msg.obj; |
| 1704 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1705 | int mode = (int) request.argument; |
| 1706 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1707 | break; |
| 1708 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1709 | ar = (AsyncResult) msg.obj; |
| 1710 | request = (MainThreadRequest) ar.userObj; |
| 1711 | request.result = ar.exception == null; |
| 1712 | notifyRequester(request); |
| 1713 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1714 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1715 | request = (MainThreadRequest) msg.obj; |
| 1716 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1717 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1718 | break; |
| 1719 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1720 | ar = (AsyncResult) msg.obj; |
| 1721 | request = (MainThreadRequest) ar.userObj; |
| 1722 | if (ar.exception != null) { |
| 1723 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1724 | } else { |
| 1725 | request.result = ((int[]) ar.result)[0]; |
| 1726 | } |
| 1727 | notifyRequester(request); |
| 1728 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1729 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1730 | request = (MainThreadRequest) msg.obj; |
| 1731 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1732 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1733 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1734 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1735 | break; |
| 1736 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1737 | ar = (AsyncResult) msg.obj; |
| 1738 | request = (MainThreadRequest) ar.userObj; |
| 1739 | request.result = ar.exception == null; |
| 1740 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1741 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1742 | case CMD_GET_ALL_CELL_INFO: |
| 1743 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1744 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1745 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1746 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1748 | ar = (AsyncResult) msg.obj; |
| 1749 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1750 | // If a timeout occurs, the response will be null |
| 1751 | request.result = (ar.exception == null && ar.result != null) |
| 1752 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1753 | synchronized (request) { |
| 1754 | request.notifyAll(); |
| 1755 | } |
| 1756 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1757 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1758 | request = (MainThreadRequest) msg.obj; |
| 1759 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1760 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1761 | break; |
| 1762 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1763 | ar = (AsyncResult) msg.obj; |
| 1764 | request = (MainThreadRequest) ar.userObj; |
| 1765 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1766 | try { |
| 1767 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1768 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1769 | cb.onError( |
| 1770 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1771 | ar.exception.getClass().getName(), |
| 1772 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1773 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1774 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1775 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1776 | } else { |
| 1777 | // use the result as returned |
| 1778 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1779 | } |
| 1780 | } catch (RemoteException re) { |
| 1781 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1782 | } |
| 1783 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1784 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1785 | request = (MainThreadRequest) msg.obj; |
| 1786 | WorkSource ws = (WorkSource) request.argument; |
| 1787 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1788 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1789 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1790 | } |
| 1791 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1792 | ar = (AsyncResult) msg.obj; |
| 1793 | request = (MainThreadRequest) ar.userObj; |
| 1794 | if (ar.exception == null) { |
| 1795 | request.result = ar.result; |
| 1796 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1797 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1798 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1799 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | synchronized (request) { |
| 1803 | request.notifyAll(); |
| 1804 | } |
| 1805 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1806 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1807 | case CMD_MODEM_REBOOT: |
| 1808 | request = (MainThreadRequest) msg.obj; |
| 1809 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1810 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1811 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1812 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1813 | handleNullReturnEvent(msg, "rebootModem"); |
| 1814 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1815 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1816 | request = (MainThreadRequest) msg.obj; |
| 1817 | boolean enable = (boolean) request.argument; |
| 1818 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1819 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1820 | PhoneConfigurationManager.getInstance() |
| 1821 | .enablePhone(request.phone, enable, onCompleted); |
| 1822 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1823 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1824 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1825 | ar = (AsyncResult) msg.obj; |
| 1826 | request = (MainThreadRequest) ar.userObj; |
| 1827 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1828 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1829 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1830 | if ((boolean) request.result) { |
| 1831 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1832 | updateModemStateMetrics(); |
| 1833 | } else { |
| 1834 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1835 | + ar.exception); |
| 1836 | } |
| 1837 | notifyRequester(request); |
| 1838 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1839 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1840 | case CMD_GET_MODEM_STATUS: |
| 1841 | request = (MainThreadRequest) msg.obj; |
| 1842 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1843 | PhoneConfigurationManager.getInstance() |
| 1844 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1845 | break; |
| 1846 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1847 | ar = (AsyncResult) msg.obj; |
| 1848 | request = (MainThreadRequest) ar.userObj; |
| 1849 | int id = request.phone.getPhoneId(); |
| 1850 | if (ar.exception == null && ar.result != null) { |
| 1851 | request.result = ar.result; |
| 1852 | //update the cache as modem status has changed |
| 1853 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1854 | (boolean) request.result); |
| 1855 | } else { |
| 1856 | // Return true if modem status cannot be retrieved. For most cases, |
| 1857 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1858 | // and disable modem are not supported. Modem is always on. |
| 1859 | // TODO: this should be fixed in R to support a third |
| 1860 | // status UNKNOWN b/131631629 |
| 1861 | request.result = true; |
| 1862 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1863 | + ar.exception); |
| 1864 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1865 | notifyRequester(request); |
| 1866 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1867 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1868 | request = (MainThreadRequest) msg.obj; |
| 1869 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1870 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1871 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1872 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1873 | break; |
| 1874 | } |
| 1875 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1876 | ar = (AsyncResult) msg.obj; |
| 1877 | request = (MainThreadRequest) ar.userObj; |
| 1878 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1879 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1880 | args.second.accept(ar.exception == null); |
| 1881 | notifyRequester(request); |
| 1882 | break; |
| 1883 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1884 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1885 | request = (MainThreadRequest) msg.obj; |
| 1886 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1887 | Phone phone = getPhoneFromRequest(request); |
| 1888 | if (phone != null) { |
| 1889 | phone.getSystemSelectionChannels(onCompleted); |
| 1890 | } else { |
| 1891 | loge("getSystemSelectionChannels: No phone object"); |
| 1892 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1893 | notifyRequester(request); |
| 1894 | } |
| 1895 | break; |
| 1896 | } |
| 1897 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1898 | ar = (AsyncResult) msg.obj; |
| 1899 | request = (MainThreadRequest) ar.userObj; |
| 1900 | if (ar.exception == null && ar.result != null) { |
| 1901 | request.result = ar.result; |
| 1902 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1903 | request.result = new IllegalStateException( |
| 1904 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1905 | if (ar.result == null) { |
| 1906 | loge("getSystemSelectionChannels: Empty response"); |
| 1907 | } else { |
| 1908 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1909 | } |
| 1910 | } |
| 1911 | notifyRequester(request); |
| 1912 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1913 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1914 | ar = (AsyncResult) msg.obj; |
| 1915 | request = (MainThreadRequest) ar.userObj; |
| 1916 | if (ar.exception == null && ar.result != null) { |
| 1917 | request.result = ar.result; |
| 1918 | } else { |
| 1919 | request.result = -1; |
| 1920 | loge("Failed to set Forbidden Plmns"); |
| 1921 | if (ar.result == null) { |
| 1922 | loge("setForbidenPlmns: Empty response"); |
| 1923 | } else if (ar.exception != null) { |
| 1924 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1925 | request.result = -1; |
| 1926 | } else { |
| 1927 | loge("setForbiddenPlmns: Unknown exception"); |
| 1928 | } |
| 1929 | } |
| 1930 | notifyRequester(request); |
| 1931 | break; |
| 1932 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1933 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1934 | uiccPort = getUiccPortFromRequest(request); |
| 1935 | if (uiccPort == null) { |
| 1936 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1937 | request.result = -1; |
| 1938 | notifyRequester(request); |
| 1939 | break; |
| 1940 | } |
| 1941 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1942 | (Pair<Integer, List<String>>) request.argument; |
| 1943 | appType = setFplmnsArgs.first; |
| 1944 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1945 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1946 | if (uiccApp == null) { |
| 1947 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1948 | request.result = -1; |
| 1949 | loge("Failed to get UICC App"); |
| 1950 | notifyRequester(request); |
| 1951 | } else { |
| 1952 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1953 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1954 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1955 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1956 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1957 | case CMD_ERASE_MODEM_CONFIG: |
| 1958 | request = (MainThreadRequest) msg.obj; |
| 1959 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1960 | defaultPhone.eraseModemConfig(onCompleted); |
| 1961 | break; |
| 1962 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1963 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1964 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1965 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1966 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1967 | request = (MainThreadRequest) msg.obj; |
| 1968 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1969 | notifyRequester(request); |
| 1970 | break; |
| 1971 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1972 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1973 | request = (MainThreadRequest) msg.obj; |
| 1974 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1975 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1976 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1977 | changed.first, changed.second, onCompleted); |
| 1978 | break; |
| 1979 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1980 | ar = (AsyncResult) msg.obj; |
| 1981 | request = (MainThreadRequest) ar.userObj; |
| 1982 | if (ar.exception == null) { |
| 1983 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1984 | // If the operation is successful, update the PIN storage |
| 1985 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1986 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1987 | UiccController.getInstance().getPinStorage() |
| 1988 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1989 | } else { |
| 1990 | request.result = msg.arg1; |
| 1991 | } |
| 1992 | notifyRequester(request); |
| 1993 | break; |
| 1994 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1995 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1996 | request = (MainThreadRequest) msg.obj; |
| 1997 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1998 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1999 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2000 | enabled.first, enabled.second, onCompleted); |
| 2001 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2002 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2003 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2004 | ar = (AsyncResult) msg.obj; |
| 2005 | request = (MainThreadRequest) ar.userObj; |
| 2006 | if (ar.exception == null) { |
| 2007 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2008 | // If the operation is successful, update the PIN storage |
| 2009 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2010 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2011 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2012 | UiccController.getInstance().getPinStorage() |
| 2013 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2014 | } else { |
| 2015 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2016 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2017 | } else { |
| 2018 | request.result = msg.arg1; |
| 2019 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2020 | |
| 2021 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2022 | notifyRequester(request); |
| 2023 | break; |
| 2024 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2025 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2026 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2027 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2028 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2029 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2030 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2031 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2032 | |
| 2033 | case CMD_SET_DATA_THROTTLING: { |
| 2034 | request = (MainThreadRequest) msg.obj; |
| 2035 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2036 | DataThrottlingRequest dataThrottlingRequest = |
| 2037 | (DataThrottlingRequest) request.argument; |
| 2038 | Phone phone = getPhoneFromRequest(request); |
| 2039 | if (phone != null) { |
| 2040 | phone.setDataThrottling(onCompleted, |
| 2041 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2042 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2043 | } else { |
| 2044 | loge("setDataThrottling: No phone object"); |
| 2045 | request.result = |
| 2046 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2047 | notifyRequester(request); |
| 2048 | } |
| 2049 | |
| 2050 | break; |
| 2051 | } |
| 2052 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2053 | ar = (AsyncResult) msg.obj; |
| 2054 | request = (MainThreadRequest) ar.userObj; |
| 2055 | |
| 2056 | if (ar.exception == null) { |
| 2057 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2058 | } else if (ar.exception instanceof CommandException) { |
| 2059 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2060 | CommandException.Error error = |
| 2061 | ((CommandException) (ar.exception)).getCommandError(); |
| 2062 | |
| 2063 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2064 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2065 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2066 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2067 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2068 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2069 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2070 | } else { |
| 2071 | request.result = |
| 2072 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2073 | } |
| 2074 | } else { |
| 2075 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2076 | } |
| 2077 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2078 | notifyRequester(request); |
| 2079 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2080 | |
| 2081 | case CMD_SET_SIM_POWER: { |
| 2082 | request = (MainThreadRequest) msg.obj; |
| 2083 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2084 | request = (MainThreadRequest) msg.obj; |
| 2085 | int stateToSet = |
| 2086 | ((Pair<Integer, IIntegerConsumer>) |
| 2087 | request.argument).first; |
| 2088 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2089 | break; |
| 2090 | } |
| 2091 | case EVENT_SET_SIM_POWER_DONE: { |
| 2092 | ar = (AsyncResult) msg.obj; |
| 2093 | request = (MainThreadRequest) ar.userObj; |
| 2094 | IIntegerConsumer callback = |
| 2095 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2096 | if (ar.exception != null) { |
| 2097 | loge("setSimPower exception: " + ar.exception); |
| 2098 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2099 | .RESULT_ERROR_UNKNOWN; |
| 2100 | if (ar.exception instanceof CommandException) { |
| 2101 | CommandException.Error error = |
| 2102 | ((CommandException) (ar.exception)).getCommandError(); |
| 2103 | if (error == CommandException.Error.SIM_ERR) { |
| 2104 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2105 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2106 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2107 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2108 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2109 | } else { |
| 2110 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2111 | } |
| 2112 | } |
| 2113 | try { |
| 2114 | callback.accept(errorCode); |
| 2115 | } catch (RemoteException e) { |
| 2116 | // Ignore if the remote process is no longer available to call back. |
| 2117 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2118 | } |
| 2119 | } else { |
| 2120 | try { |
| 2121 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2122 | } catch (RemoteException e) { |
| 2123 | // Ignore if the remote process is no longer available to call back. |
| 2124 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2125 | } |
| 2126 | } |
| 2127 | break; |
| 2128 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2129 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2130 | request = (MainThreadRequest) msg.obj; |
| 2131 | |
| 2132 | final Phone phone = getPhoneFromRequest(request); |
| 2133 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2134 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2135 | notifyRequester(request); |
| 2136 | break; |
| 2137 | } |
| 2138 | |
| 2139 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2140 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2141 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2142 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2143 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2144 | request.subId, pair.first /*callingUid*/, |
| 2145 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2146 | break; |
| 2147 | } |
| 2148 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2149 | ar = (AsyncResult) msg.obj; |
| 2150 | request = (MainThreadRequest) ar.userObj; |
| 2151 | // request.result will be the exception of ar if present, true otherwise. |
| 2152 | // Be cautious not to leave result null which will wait() forever |
| 2153 | request.result = ar.exception != null ? ar.exception : true; |
| 2154 | notifyRequester(request); |
| 2155 | break; |
| 2156 | } |
| 2157 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2158 | request = (MainThreadRequest) msg.obj; |
| 2159 | |
| 2160 | Phone phone = getPhoneFromRequest(request); |
| 2161 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2162 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2163 | notifyRequester(request); |
| 2164 | break; |
| 2165 | } |
| 2166 | |
| 2167 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2168 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2169 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2170 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2171 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2172 | request.subId, pair.first /*callingUid*/, |
| 2173 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2174 | break; |
| 2175 | } |
| 2176 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2177 | ar = (AsyncResult) msg.obj; |
| 2178 | request = (MainThreadRequest) ar.userObj; |
| 2179 | request.result = ar.exception != null ? ar.exception : true; |
| 2180 | notifyRequester(request); |
| 2181 | break; |
| 2182 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2183 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2184 | case CMD_GET_SLICING_CONFIG: { |
| 2185 | request = (MainThreadRequest) msg.obj; |
| 2186 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2187 | request.phone.getSlicingConfig(onCompleted); |
| 2188 | break; |
| 2189 | } |
| 2190 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2191 | ar = (AsyncResult) msg.obj; |
| 2192 | request = (MainThreadRequest) ar.userObj; |
| 2193 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2194 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2195 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2196 | Bundle bundle = new Bundle(); |
| 2197 | int resultCode = 0; |
| 2198 | if (ar.exception != null) { |
| 2199 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2200 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2201 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2202 | } else if (ar.result == null) { |
| 2203 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2204 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2205 | } else { |
| 2206 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2207 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2208 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2212 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2213 | } |
| 2214 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2215 | result.send(resultCode, bundle); |
| 2216 | notifyRequester(request); |
| 2217 | break; |
| 2218 | } |
| 2219 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2220 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2221 | request = (MainThreadRequest) msg.obj; |
| 2222 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2223 | PurchasePremiumCapabilityArgument arg = |
| 2224 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2225 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2226 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2227 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2228 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2229 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2230 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2231 | ar = (AsyncResult) msg.obj; |
| 2232 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2233 | PurchasePremiumCapabilityArgument arg = |
| 2234 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2235 | try { |
| 2236 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2237 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2238 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2239 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2240 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2241 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2242 | } catch (RemoteException e) { |
| 2243 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2244 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2245 | + " failed: " + e; |
| 2246 | if (DBG) log(logStr); |
| 2247 | AnomalyReporter.reportAnomaly( |
| 2248 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2249 | } |
| 2250 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2251 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2252 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2253 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2254 | request = (MainThreadRequest) msg.obj; |
| 2255 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2256 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2257 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2258 | notifyRequester(request); |
| 2259 | break; |
| 2260 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 | default: |
| 2262 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2263 | break; |
| 2264 | } |
| 2265 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2266 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2267 | private void notifyRequester(MainThreadRequest request) { |
| 2268 | synchronized (request) { |
| 2269 | request.notifyAll(); |
| 2270 | } |
| 2271 | } |
| 2272 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2273 | private void handleNullReturnEvent(Message msg, String command) { |
| 2274 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2275 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2276 | if (ar.exception == null) { |
| 2277 | request.result = true; |
| 2278 | } else { |
| 2279 | request.result = false; |
| 2280 | if (ar.exception instanceof CommandException) { |
| 2281 | loge(command + ": CommandException: " + ar.exception); |
| 2282 | } else { |
| 2283 | loge(command + ": Unknown exception"); |
| 2284 | } |
| 2285 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2286 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2287 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | /** |
| 2291 | * Posts the specified command to be executed on the main thread, |
| 2292 | * waits for the request to complete, and returns the result. |
| 2293 | * @see #sendRequestAsync |
| 2294 | */ |
| 2295 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2296 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2297 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | /** |
| 2301 | * Posts the specified command to be executed on the main thread, |
| 2302 | * waits for the request to complete, and returns the result. |
| 2303 | * @see #sendRequestAsync |
| 2304 | */ |
| 2305 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2306 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2307 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | /** |
| 2311 | * Posts the specified command to be executed on the main thread, |
| 2312 | * waits for the request to complete, and returns the result. |
| 2313 | * @see #sendRequestAsync |
| 2314 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2315 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2316 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2317 | } |
| 2318 | |
| 2319 | /** |
| 2320 | * Posts the specified command to be executed on the main thread, |
| 2321 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2322 | * if not timeout or null otherwise. |
| 2323 | * @see #sendRequestAsync |
| 2324 | */ |
| 2325 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2326 | long timeoutInMs) { |
| 2327 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | /** |
| 2331 | * Posts the specified command to be executed on the main thread, |
| 2332 | * waits for the request to complete, and returns the result. |
| 2333 | * @see #sendRequestAsync |
| 2334 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2335 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2336 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | /** |
| 2340 | * Posts the specified command to be executed on the main thread, |
| 2341 | * waits for the request to complete, and returns the result. |
| 2342 | * @see #sendRequestAsync |
| 2343 | */ |
| 2344 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2345 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2346 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2350 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2351 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2352 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2353 | * @see #sendRequestAsync |
| 2354 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2355 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2356 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2358 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2359 | } |
| 2360 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2361 | MainThreadRequest request = null; |
| 2362 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2363 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2364 | } else if (phone != null) { |
| 2365 | request = new MainThreadRequest(argument, phone, workSource); |
| 2366 | } else { |
| 2367 | request = new MainThreadRequest(argument, subId, workSource); |
| 2368 | } |
| 2369 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2370 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2371 | msg.sendToTarget(); |
| 2372 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2373 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2374 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2375 | if (timeoutInMs >= 0) { |
| 2376 | // Wait for at least timeoutInMs before returning null request result |
| 2377 | long now = SystemClock.elapsedRealtime(); |
| 2378 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2379 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2380 | try { |
| 2381 | request.wait(deadline - now); |
| 2382 | } catch (InterruptedException e) { |
| 2383 | // Do nothing, go back and check if request is completed or timeout |
| 2384 | } finally { |
| 2385 | now = SystemClock.elapsedRealtime(); |
| 2386 | } |
| 2387 | } |
| 2388 | } else { |
| 2389 | // Wait for the request to complete |
| 2390 | while (request.result == null) { |
| 2391 | try { |
| 2392 | request.wait(); |
| 2393 | } catch (InterruptedException e) { |
| 2394 | // Do nothing, go back and wait until the request is complete |
| 2395 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | } |
| 2397 | } |
| 2398 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2399 | if (request.result == null) { |
| 2400 | Log.wtf(LOG_TAG, |
| 2401 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | return request.result; |
| 2404 | } |
| 2405 | |
| 2406 | /** |
| 2407 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2408 | * Posts the specified command to be executed on the main thread, and |
| 2409 | * returns immediately. |
| 2410 | * @see #sendRequest |
| 2411 | */ |
| 2412 | private void sendRequestAsync(int command) { |
| 2413 | mMainThreadHandler.sendEmptyMessage(command); |
| 2414 | } |
| 2415 | |
| 2416 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2417 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2418 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2419 | */ |
| 2420 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2421 | sendRequestAsync(command, argument, null, null); |
| 2422 | } |
| 2423 | |
| 2424 | /** |
| 2425 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2426 | * @see {@link #sendRequest(int,Object)} |
| 2427 | */ |
| 2428 | private void sendRequestAsync( |
| 2429 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2430 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2431 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2432 | msg.sendToTarget(); |
| 2433 | } |
| 2434 | |
| 2435 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2437 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2438 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2439 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2440 | synchronized (PhoneInterfaceManager.class) { |
| 2441 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2442 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | } else { |
| 2444 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2445 | } |
| 2446 | return sInstance; |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2451 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2452 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2453 | mFeatureFlags = featureFlags; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2455 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2456 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2457 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2459 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2460 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2461 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2462 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2463 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2464 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2465 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2467 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2470 | @VisibleForTesting |
| 2471 | public SharedPreferences getSharedPreferences() { |
| 2472 | return mTelephonySharedPreferences; |
| 2473 | } |
| 2474 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2475 | /** |
| 2476 | * Get the default phone for this device. |
| 2477 | */ |
| 2478 | @VisibleForTesting |
| 2479 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2480 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2481 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2482 | } |
| 2483 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | private void publish() { |
| 2485 | if (DBG) log("publish: " + this); |
| 2486 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2487 | TelephonyFrameworkInitializer |
| 2488 | .getTelephonyServiceManager() |
| 2489 | .getTelephonyServiceRegisterer() |
| 2490 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2491 | } |
| 2492 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2493 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2494 | if (request.phone != null) { |
| 2495 | return request.phone; |
| 2496 | } else { |
| 2497 | return getPhoneFromSubId(request.subId); |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | private Phone getPhoneFromSubId(int subId) { |
| 2502 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2503 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2504 | } |
| 2505 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2506 | /** |
| 2507 | * Get phone object associated with a subscription. |
| 2508 | * Return default phone if phone object associated with subscription is null |
| 2509 | * @param subId - subscriptionId |
| 2510 | * @return phone object associated with a subscription or default phone if null. |
| 2511 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2512 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2513 | Phone phone = getPhoneFromSubId(subId); |
| 2514 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2515 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2516 | phone = getDefaultPhone(); |
| 2517 | } |
| 2518 | return phone; |
| 2519 | } |
| 2520 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2521 | @Nullable |
| 2522 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2523 | Phone phone = getPhoneFromRequest(request); |
| 2524 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2525 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2526 | } |
| 2527 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2528 | /** |
| 2529 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2530 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2531 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2532 | * @return The Phone associated the sub Id |
| 2533 | */ |
| 2534 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2535 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2536 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2537 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2538 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2539 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2540 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2541 | } |
| 2542 | |
| 2543 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2544 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2545 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2548 | private boolean isImsAvailableOnDevice() { |
| 2549 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2550 | if (pm == null) { |
| 2551 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2552 | // so do not throw error and allow. |
| 2553 | return true; |
| 2554 | } |
| 2555 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2556 | } |
| 2557 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2558 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2559 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2562 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2563 | if (DBG) log("dial: " + number); |
| 2564 | // No permission check needed here: This is just a wrapper around the |
| 2565 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2566 | // the UI before it does anything. |
| 2567 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2568 | final long identity = Binder.clearCallingIdentity(); |
| 2569 | try { |
| 2570 | String url = createTelUrl(number); |
| 2571 | if (url == null) { |
| 2572 | return; |
| 2573 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2574 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2575 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2576 | PhoneConstants.State state = mCM.getState(subId); |
| 2577 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2578 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2579 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2580 | mApp.startActivity(intent); |
| 2581 | } |
| 2582 | } finally { |
| 2583 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2588 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2591 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2592 | if (DBG) log("call: " + number); |
| 2593 | |
| 2594 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2595 | // need to do a permission check since we're calling startActivity() |
| 2596 | // from the context of the phone app. |
| 2597 | enforceCallPermission(); |
| 2598 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2599 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2600 | != AppOpsManager.MODE_ALLOWED) { |
| 2601 | return; |
| 2602 | } |
| 2603 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | final long identity = Binder.clearCallingIdentity(); |
| 2605 | try { |
| 2606 | String url = createTelUrl(number); |
| 2607 | if (url == null) { |
| 2608 | return; |
| 2609 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2611 | boolean isValid = false; |
| 2612 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2613 | if (slist != null) { |
| 2614 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2615 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2616 | isValid = true; |
| 2617 | break; |
| 2618 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2619 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2620 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | if (!isValid) { |
| 2622 | return; |
| 2623 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2624 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2625 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2626 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2627 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2628 | mApp.startActivity(intent); |
| 2629 | } finally { |
| 2630 | Binder.restoreCallingIdentity(identity); |
| 2631 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2634 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2635 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2636 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2637 | } |
| 2638 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2639 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2640 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2641 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2642 | } |
| 2643 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2644 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2645 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | |
| 2647 | final long identity = Binder.clearCallingIdentity(); |
| 2648 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2649 | Phone phone = getPhone(subId); |
| 2650 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | checkSimPin.start(); |
| 2652 | return checkSimPin.unlockSim(null, pin); |
| 2653 | } finally { |
| 2654 | Binder.restoreCallingIdentity(identity); |
| 2655 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2658 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2659 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | |
| 2661 | final long identity = Binder.clearCallingIdentity(); |
| 2662 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2663 | Phone phone = getPhone(subId); |
| 2664 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | checkSimPuk.start(); |
| 2666 | return checkSimPuk.unlockSim(puk, pin); |
| 2667 | } finally { |
| 2668 | Binder.restoreCallingIdentity(identity); |
| 2669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2673 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2674 | * a synchronous one. |
| 2675 | */ |
| 2676 | private static class UnlockSim extends Thread { |
| 2677 | |
| 2678 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2679 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2680 | |
| 2681 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2682 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2683 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | |
| 2685 | // For replies from SimCard interface |
| 2686 | private Handler mHandler; |
| 2687 | |
| 2688 | // For async handler to identify request type |
| 2689 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2690 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2691 | UnlockSim(int phoneId, IccCard simCard) { |
| 2692 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 | mSimCard = simCard; |
| 2694 | } |
| 2695 | |
| 2696 | @Override |
| 2697 | public void run() { |
| 2698 | Looper.prepare(); |
| 2699 | synchronized (UnlockSim.this) { |
| 2700 | mHandler = new Handler() { |
| 2701 | @Override |
| 2702 | public void handleMessage(Message msg) { |
| 2703 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2704 | switch (msg.what) { |
| 2705 | case SUPPLY_PIN_COMPLETE: |
| 2706 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2707 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2708 | mRetryCount = msg.arg1; |
| 2709 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2710 | CommandException.Error error = null; |
| 2711 | if (ar.exception instanceof CommandException) { |
| 2712 | error = ((CommandException) (ar.exception)) |
| 2713 | .getCommandError(); |
| 2714 | } |
| 2715 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2716 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2717 | } else if (error == CommandException.Error.ABORTED) { |
| 2718 | /* When UiccCardApp dispose, handle message and return |
| 2719 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2720 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2721 | } else { |
| 2722 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2723 | } |
| 2724 | } else { |
| 2725 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2726 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | mDone = true; |
| 2728 | UnlockSim.this.notifyAll(); |
| 2729 | } |
| 2730 | break; |
| 2731 | } |
| 2732 | } |
| 2733 | }; |
| 2734 | UnlockSim.this.notifyAll(); |
| 2735 | } |
| 2736 | Looper.loop(); |
| 2737 | } |
| 2738 | |
| 2739 | /* |
| 2740 | * Use PIN or PUK to unlock SIM card |
| 2741 | * |
| 2742 | * If PUK is null, unlock SIM card with PIN |
| 2743 | * |
| 2744 | * 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] | 2745 | * |
| 2746 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2747 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2748 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2749 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2750 | |
| 2751 | while (mHandler == null) { |
| 2752 | try { |
| 2753 | wait(); |
| 2754 | } catch (InterruptedException e) { |
| 2755 | Thread.currentThread().interrupt(); |
| 2756 | } |
| 2757 | } |
| 2758 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2759 | |
| 2760 | if (puk == null) { |
| 2761 | mSimCard.supplyPin(pin, callback); |
| 2762 | } else { |
| 2763 | mSimCard.supplyPuk(puk, pin, callback); |
| 2764 | } |
| 2765 | |
| 2766 | while (!mDone) { |
| 2767 | try { |
| 2768 | Log.d(LOG_TAG, "wait for done"); |
| 2769 | wait(); |
| 2770 | } catch (InterruptedException e) { |
| 2771 | // Restore the interrupted status |
| 2772 | Thread.currentThread().interrupt(); |
| 2773 | } |
| 2774 | } |
| 2775 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2776 | int[] resultArray = new int[2]; |
| 2777 | resultArray[0] = mResult; |
| 2778 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2779 | |
| 2780 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2781 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2782 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2783 | // This instance is no longer reused, so quit its thread's looper. |
| 2784 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2785 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2786 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2787 | } |
| 2788 | } |
| 2789 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2790 | /** |
| 2791 | * This method has been removed due to privacy and stability concerns. |
| 2792 | */ |
| 2793 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2794 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2795 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2796 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2799 | @Override |
| 2800 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2801 | mApp.getSystemService(AppOpsManager.class) |
| 2802 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2803 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2804 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2805 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2806 | // Callers targeting S have no business invoking this method. |
| 2807 | return; |
| 2808 | } |
| 2809 | |
| 2810 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2811 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2812 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2813 | .setCallingPackage(callingPackage) |
| 2814 | .setCallingFeatureId(null) |
| 2815 | .setCallingPid(Binder.getCallingPid()) |
| 2816 | .setCallingUid(Binder.getCallingUid()) |
| 2817 | .setMethod("updateServiceLocation") |
| 2818 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2819 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2820 | .build()); |
| 2821 | // Apps that lack location permission have no business calling this method; |
| 2822 | // however, because no permission was declared in the public API, denials must |
| 2823 | // all be "soft". |
| 2824 | switch (locationResult) { |
| 2825 | case DENIED_HARD: /* fall through */ |
| 2826 | case DENIED_SOFT: |
| 2827 | return; |
| 2828 | } |
| 2829 | |
| 2830 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2831 | final long identity = Binder.clearCallingIdentity(); |
| 2832 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2833 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2834 | } finally { |
| 2835 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2836 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2839 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2840 | @Override |
| 2841 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2842 | return isRadioOnWithFeature(callingPackage, null); |
| 2843 | } |
| 2844 | |
| 2845 | |
| 2846 | @Override |
| 2847 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2848 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2849 | callingFeatureId); |
| 2850 | } |
| 2851 | |
| 2852 | @Deprecated |
| 2853 | @Override |
| 2854 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2855 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2858 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2859 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2860 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2861 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2862 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2863 | return false; |
| 2864 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2865 | |
| 2866 | final long identity = Binder.clearCallingIdentity(); |
| 2867 | try { |
| 2868 | return isRadioOnForSubscriber(subId); |
| 2869 | } finally { |
| 2870 | Binder.restoreCallingIdentity(identity); |
| 2871 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2875 | final long identity = Binder.clearCallingIdentity(); |
| 2876 | try { |
| 2877 | final Phone phone = getPhone(subId); |
| 2878 | if (phone != null) { |
| 2879 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2880 | } else { |
| 2881 | return false; |
| 2882 | } |
| 2883 | } finally { |
| 2884 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2885 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2889 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2891 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2892 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2893 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2894 | |
| 2895 | final long identity = Binder.clearCallingIdentity(); |
| 2896 | try { |
| 2897 | final Phone phone = getPhone(subId); |
| 2898 | if (phone != null) { |
| 2899 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2900 | } |
| 2901 | } finally { |
| 2902 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2903 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2907 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2908 | } |
| 2909 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2910 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2911 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2912 | |
| 2913 | final long identity = Binder.clearCallingIdentity(); |
| 2914 | try { |
| 2915 | final Phone phone = getPhone(subId); |
| 2916 | if (phone == null) { |
| 2917 | return false; |
| 2918 | } |
| 2919 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2920 | toggleRadioOnOffForSubscriber(subId); |
| 2921 | } |
| 2922 | return true; |
| 2923 | } finally { |
| 2924 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2925 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2926 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2927 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2928 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2929 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2930 | /* |
| 2931 | * If any of the Radios are available, it will need to be |
| 2932 | * shutdown. So return true if any Radio is available. |
| 2933 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2937 | Phone phone = PhoneFactory.getPhone(i); |
| 2938 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2939 | } |
| 2940 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2941 | return false; |
| 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2944 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2947 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2948 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2949 | enforceModifyPermission(); |
| 2950 | |
| 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2954 | logv("Shutting down Phone " + i); |
| 2955 | shutdownRadioUsingPhoneId(i); |
| 2956 | } |
| 2957 | } finally { |
| 2958 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2963 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2964 | if (phone != null && phone.isRadioAvailable()) { |
| 2965 | phone.shutdownRadio(); |
| 2966 | } |
| 2967 | } |
| 2968 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2969 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2970 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2971 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2972 | if (!turnOn) { |
| 2973 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 2974 | } |
| 2975 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | final long identity = Binder.clearCallingIdentity(); |
| 2977 | try { |
| 2978 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2979 | if (defaultPhone != null) { |
| 2980 | defaultPhone.setRadioPower(turnOn); |
| 2981 | return true; |
| 2982 | } else { |
| 2983 | loge("There's no default phone."); |
| 2984 | return false; |
| 2985 | } |
| 2986 | } finally { |
| 2987 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2988 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2991 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2992 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2993 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2994 | if (!turnOn) { |
| 2995 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 2996 | + ",callingPackage=" + getCurrentPackageName()); |
| 2997 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | final long identity = Binder.clearCallingIdentity(); |
| 2999 | try { |
| 3000 | final Phone phone = getPhone(subId); |
| 3001 | if (phone != null) { |
| 3002 | phone.setRadioPower(turnOn); |
| 3003 | return true; |
| 3004 | } else { |
| 3005 | return false; |
| 3006 | } |
| 3007 | } finally { |
| 3008 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3009 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3010 | } |
| 3011 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3012 | /** |
| 3013 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3014 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3015 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3016 | * powering it off, and these radio off votes will be cleared. |
| 3017 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3018 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3019 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3020 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3021 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3022 | * check its vote. |
| 3023 | * |
| 3024 | * @param subId The subscription ID. |
| 3025 | * @param reason The reason for powering off radio. |
| 3026 | * @return true on success and false on failure. |
| 3027 | */ |
| 3028 | public boolean requestRadioPowerOffForReason(int subId, |
| 3029 | @TelephonyManager.RadioPowerReason int reason) { |
| 3030 | enforceModifyPermission(); |
| 3031 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3032 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3033 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3034 | final long identity = Binder.clearCallingIdentity(); |
| 3035 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3036 | boolean result = false; |
| 3037 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3038 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3039 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3040 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3041 | if (!result) { |
| 3042 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3043 | } |
| 3044 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3045 | } finally { |
| 3046 | Binder.restoreCallingIdentity(identity); |
| 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | /** |
| 3051 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3052 | * {@link requestRadioPowerOffForReason}. |
| 3053 | * |
| 3054 | * @param subId The subscription ID. |
| 3055 | * @param reason The reason for powering off radio. |
| 3056 | * @return true on success and false on failure. |
| 3057 | */ |
| 3058 | public boolean clearRadioPowerOffForReason(int subId, |
| 3059 | @TelephonyManager.RadioPowerReason int reason) { |
| 3060 | enforceModifyPermission(); |
| 3061 | |
| 3062 | final long identity = Binder.clearCallingIdentity(); |
| 3063 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3064 | boolean result = false; |
| 3065 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3066 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3067 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3068 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3069 | if (!result) { |
| 3070 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3071 | } |
| 3072 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3073 | } finally { |
| 3074 | Binder.restoreCallingIdentity(identity); |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | /** |
| 3079 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3080 | * |
| 3081 | * @param subId The subscription ID. |
| 3082 | * @param callingPackage The package making the call. |
| 3083 | * @param callingFeatureId The feature in the package. |
| 3084 | * @return List of reasons for powering off radio. |
| 3085 | */ |
| 3086 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3087 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3088 | |
| 3089 | final long identity = Binder.clearCallingIdentity(); |
| 3090 | List result = new ArrayList(); |
| 3091 | try { |
| 3092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3093 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3094 | return result; |
| 3095 | } |
| 3096 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3097 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3098 | if (phone != null) { |
| 3099 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3100 | } else { |
| 3101 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3102 | } |
| 3103 | } finally { |
| 3104 | Binder.restoreCallingIdentity(identity); |
| 3105 | } |
| 3106 | return result; |
| 3107 | } |
| 3108 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3109 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3110 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3111 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3112 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | |
| 3114 | final long identity = Binder.clearCallingIdentity(); |
| 3115 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3116 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3117 | final Phone phone = getPhone(subId); |
| 3118 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3119 | phone.getDataSettingsManager().setDataEnabled( |
| 3120 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3121 | return true; |
| 3122 | } else { |
| 3123 | return false; |
| 3124 | } |
| 3125 | } finally { |
| 3126 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3128 | } |
| 3129 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3130 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3131 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3132 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3133 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3134 | |
| 3135 | final long identity = Binder.clearCallingIdentity(); |
| 3136 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3137 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3138 | final Phone phone = getPhone(subId); |
| 3139 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3140 | phone.getDataSettingsManager().setDataEnabled( |
| 3141 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3142 | return true; |
| 3143 | } else { |
| 3144 | return false; |
| 3145 | } |
| 3146 | } finally { |
| 3147 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3148 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3149 | } |
| 3150 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3151 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3152 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3153 | final long identity = Binder.clearCallingIdentity(); |
| 3154 | try { |
| 3155 | final Phone phone = getPhone(subId); |
| 3156 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3157 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | } else { |
| 3159 | return false; |
| 3160 | } |
| 3161 | } finally { |
| 3162 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3163 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3167 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3170 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3171 | enforceCallPermission(); |
| 3172 | |
| 3173 | final long identity = Binder.clearCallingIdentity(); |
| 3174 | try { |
| 3175 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3176 | return; |
| 3177 | } |
| 3178 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3179 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3180 | } finally { |
| 3181 | Binder.restoreCallingIdentity(identity); |
| 3182 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3183 | }; |
| 3184 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3185 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3186 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3187 | |
| 3188 | final long identity = Binder.clearCallingIdentity(); |
| 3189 | try { |
| 3190 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3191 | return false; |
| 3192 | } |
| 3193 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3194 | } finally { |
| 3195 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3197 | } |
| 3198 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3199 | /** |
| 3200 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3201 | * tag on getCallState Binder call. |
| 3202 | */ |
| 3203 | @Deprecated |
| 3204 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3206 | if (CompatChanges.isChangeEnabled( |
| 3207 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3208 | Binder.getCallingUid())) { |
| 3209 | // Do not allow this API to be called on API version 31+, it should only be |
| 3210 | // called on old apps using this Binder call directly. |
| 3211 | throw new SecurityException("This method can only be used for applications " |
| 3212 | + "targeting API version 30 or less."); |
| 3213 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3214 | final long identity = Binder.clearCallingIdentity(); |
| 3215 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3216 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3217 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3218 | } finally { |
| 3219 | Binder.restoreCallingIdentity(identity); |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | @Override |
| 3224 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3225 | if (CompatChanges.isChangeEnabled( |
| 3226 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3227 | Binder.getCallingUid())) { |
| 3228 | // Check READ_PHONE_STATE for API version 31+ |
| 3229 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3230 | featureId, "getCallStateForSubscription")) { |
| 3231 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3232 | + "targeting API level 31+."); |
| 3233 | } |
| 3234 | } |
| 3235 | final long identity = Binder.clearCallingIdentity(); |
| 3236 | try { |
| 3237 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3238 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3239 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3240 | } finally { |
| 3241 | Binder.restoreCallingIdentity(identity); |
| 3242 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3245 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3246 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3247 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | @Override |
| 3251 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | final long identity = Binder.clearCallingIdentity(); |
| 3253 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3254 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3255 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3256 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3257 | } else { |
| 3258 | return PhoneConstantConversions.convertDataState( |
| 3259 | PhoneConstants.DataState.DISCONNECTED); |
| 3260 | } |
| 3261 | } finally { |
| 3262 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3263 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3266 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3267 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3268 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3272 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3273 | final long identity = Binder.clearCallingIdentity(); |
| 3274 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3275 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3276 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3277 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3278 | } else { |
| 3279 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3280 | } |
| 3281 | } finally { |
| 3282 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3287 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3288 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3289 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3290 | |
| 3291 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3292 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3293 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3294 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3295 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3296 | .setCallingPid(Binder.getCallingPid()) |
| 3297 | .setCallingUid(Binder.getCallingUid()) |
| 3298 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3299 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3300 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3301 | .build()); |
| 3302 | switch (locationResult) { |
| 3303 | case DENIED_HARD: |
| 3304 | throw new SecurityException("Not allowed to access cell location"); |
| 3305 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3306 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3307 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3310 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
| 3313 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3314 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3315 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3316 | } finally { |
| 3317 | Binder.restoreCallingIdentity(identity); |
| 3318 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3319 | } |
| 3320 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3321 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3322 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3323 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3324 | // registered cell info, so return a NULL country instead. |
| 3325 | final long identity = Binder.clearCallingIdentity(); |
| 3326 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3327 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3328 | // Get default phone in this case. |
| 3329 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3330 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3331 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3332 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3333 | if (phone == null) return ""; |
| 3334 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3335 | if (sst == null) return ""; |
| 3336 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3337 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3338 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3339 | } finally { |
| 3340 | Binder.restoreCallingIdentity(identity); |
| 3341 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3342 | } |
| 3343 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3344 | /** |
| 3345 | * This method was removed due to potential issues caused by performing partial |
| 3346 | * updates of service state, and lack of a credible use case. |
| 3347 | * |
| 3348 | * This has the ability to break the telephony implementation by disabling notification of |
| 3349 | * changes in device connectivity. DO NOT USE THIS! |
| 3350 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3351 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3352 | public void enableLocationUpdates() { |
| 3353 | mApp.enforceCallingOrSelfPermission( |
| 3354 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3357 | /** |
| 3358 | * This method was removed due to potential issues caused by performing partial |
| 3359 | * updates of service state, and lack of a credible use case. |
| 3360 | * |
| 3361 | * This has the ability to break the telephony implementation by disabling notification of |
| 3362 | * changes in device connectivity. DO NOT USE THIS! |
| 3363 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3364 | @Override |
| 3365 | public void disableLocationUpdates() { |
| 3366 | mApp.enforceCallingOrSelfPermission( |
| 3367 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | @Override |
| 3371 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3372 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3373 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3374 | try { |
| 3375 | mApp.getSystemService(AppOpsManager.class) |
| 3376 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3377 | } catch (SecurityException e) { |
| 3378 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3379 | throw e; |
| 3380 | } |
| 3381 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3382 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3383 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3384 | throw new SecurityException( |
| 3385 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3386 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3387 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3388 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3389 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3390 | return null; |
| 3391 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3392 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3393 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3394 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3395 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3396 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3397 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3398 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3399 | for (CellInfo ci : info) { |
| 3400 | if (ci instanceof CellInfoGsm) { |
| 3401 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3402 | } else if (ci instanceof CellInfoWcdma) { |
| 3403 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3404 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3405 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3406 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3409 | private List<CellInfo> getCachedCellInfo() { |
| 3410 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3411 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3412 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3413 | if (info != null) cellInfos.addAll(info); |
| 3414 | } |
| 3415 | return cellInfos; |
| 3416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3417 | |
| 3418 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3419 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3420 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3421 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3422 | |
| 3423 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3424 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3425 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3426 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3427 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3428 | .setCallingPid(Binder.getCallingPid()) |
| 3429 | .setCallingUid(Binder.getCallingUid()) |
| 3430 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3431 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3432 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3433 | .build()); |
| 3434 | switch (locationResult) { |
| 3435 | case DENIED_HARD: |
| 3436 | throw new SecurityException("Not allowed to access cell info"); |
| 3437 | case DENIED_SOFT: |
| 3438 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3441 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3442 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3443 | return getCachedCellInfo(); |
| 3444 | } |
| 3445 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3446 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3447 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | final long identity = Binder.clearCallingIdentity(); |
| 3449 | try { |
| 3450 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3451 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3452 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3453 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3454 | if (info != null) cellInfos.addAll(info); |
| 3455 | } |
| 3456 | return cellInfos; |
| 3457 | } finally { |
| 3458 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3459 | } |
| 3460 | } |
| 3461 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3462 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3463 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3464 | String callingFeatureId) { |
| 3465 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3466 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3470 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3471 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3472 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3473 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3476 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3477 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3478 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3479 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3480 | |
| 3481 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3482 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3483 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3484 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3485 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3486 | .setCallingPid(Binder.getCallingPid()) |
| 3487 | .setCallingUid(Binder.getCallingUid()) |
| 3488 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3489 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3490 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3491 | .build()); |
| 3492 | switch (locationResult) { |
| 3493 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3494 | if (TelephonyPermissions |
| 3495 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3496 | // Safetynet logging for b/154934934 |
| 3497 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3498 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3499 | throw new SecurityException("Not allowed to access cell info"); |
| 3500 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3501 | if (TelephonyPermissions |
| 3502 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3503 | // Safetynet logging for b/154934934 |
| 3504 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3505 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3506 | try { |
| 3507 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3508 | } catch (RemoteException re) { |
| 3509 | // Drop without consequences |
| 3510 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3511 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3514 | |
| 3515 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3516 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3517 | |
| 3518 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3519 | } |
| 3520 | |
| 3521 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3522 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3523 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3524 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3525 | |
| 3526 | final long identity = Binder.clearCallingIdentity(); |
| 3527 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3528 | Phone phone = getPhone(subId); |
| 3529 | if (phone == null) { |
| 3530 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3531 | } else { |
| 3532 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3533 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3534 | } finally { |
| 3535 | Binder.restoreCallingIdentity(identity); |
| 3536 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3539 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3540 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3541 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3542 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3543 | return null; |
| 3544 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3545 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3546 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3547 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3548 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3549 | return null; |
| 3550 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3551 | |
| 3552 | final long identity = Binder.clearCallingIdentity(); |
| 3553 | try { |
| 3554 | return phone.getImei(); |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
| 3557 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3561 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3562 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3563 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3564 | callingFeatureId, "getPrimaryImei")) { |
| 3565 | throw new SecurityException("Caller does not have permission"); |
| 3566 | } |
| 3567 | final long identity = Binder.clearCallingIdentity(); |
| 3568 | try { |
| 3569 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3570 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3571 | return phone.getImei(); |
| 3572 | } |
| 3573 | } |
| 3574 | throw new UnsupportedOperationException("Operation not supported"); |
| 3575 | } finally { |
| 3576 | Binder.restoreCallingIdentity(identity); |
| 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3581 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3582 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3583 | String tac = null; |
| 3584 | if (phone != null) { |
| 3585 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3586 | try { |
| 3587 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3588 | } catch (IndexOutOfBoundsException e) { |
| 3589 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3590 | return null; |
| 3591 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3592 | } |
| 3593 | return tac; |
| 3594 | } |
| 3595 | |
| 3596 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3597 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3598 | try { |
| 3599 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3600 | } catch (SecurityException se) { |
| 3601 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3602 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3603 | + Binder.getCallingUid()); |
| 3604 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3605 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3606 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3607 | return null; |
| 3608 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3609 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3610 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3611 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3612 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3613 | return null; |
| 3614 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3615 | |
| 3616 | final long identity = Binder.clearCallingIdentity(); |
| 3617 | try { |
| 3618 | return phone.getMeid(); |
| 3619 | } finally { |
| 3620 | Binder.restoreCallingIdentity(identity); |
| 3621 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3625 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3626 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3627 | String manufacturerCode = null; |
| 3628 | if (phone != null) { |
| 3629 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3630 | try { |
| 3631 | manufacturerCode = |
| 3632 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3633 | } catch (IndexOutOfBoundsException e) { |
| 3634 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3635 | return null; |
| 3636 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3637 | } |
| 3638 | return manufacturerCode; |
| 3639 | } |
| 3640 | |
| 3641 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3642 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3643 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3644 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3645 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3646 | return null; |
| 3647 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3648 | int subId = phone.getSubId(); |
| 3649 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3650 | mApp, subId, callingPackage, callingFeatureId, |
| 3651 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3652 | return null; |
| 3653 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | |
| 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
| 3657 | return phone.getDeviceSvn(); |
| 3658 | } finally { |
| 3659 | Binder.restoreCallingIdentity(identity); |
| 3660 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3661 | } |
| 3662 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3663 | @Override |
| 3664 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3665 | final long identity = Binder.clearCallingIdentity(); |
| 3666 | try { |
| 3667 | final Phone phone = getPhone(subId); |
| 3668 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(identity); |
| 3671 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3672 | } |
| 3673 | |
| 3674 | @Override |
| 3675 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3676 | final long identity = Binder.clearCallingIdentity(); |
| 3677 | try { |
| 3678 | final Phone phone = getPhone(subId); |
| 3679 | return phone == null ? null : phone.getCarrierName(); |
| 3680 | } finally { |
| 3681 | Binder.restoreCallingIdentity(identity); |
| 3682 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3683 | } |
| 3684 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3685 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3686 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
| 3689 | final Phone phone = getPhone(subId); |
| 3690 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3691 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3692 | } finally { |
| 3693 | Binder.restoreCallingIdentity(identity); |
| 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3698 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3699 | final long identity = Binder.clearCallingIdentity(); |
| 3700 | try { |
| 3701 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3702 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3703 | } finally { |
| 3704 | Binder.restoreCallingIdentity(identity); |
| 3705 | } |
| 3706 | } |
| 3707 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3708 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3709 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3710 | if (!isSubscriptionMccMnc) { |
| 3711 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3712 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3713 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3714 | if (phone == null) { |
| 3715 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3716 | } |
| 3717 | final long identity = Binder.clearCallingIdentity(); |
| 3718 | try { |
| 3719 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3720 | } finally { |
| 3721 | Binder.restoreCallingIdentity(identity); |
| 3722 | } |
| 3723 | } |
| 3724 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3725 | // |
| 3726 | // Internal helper methods. |
| 3727 | // |
| 3728 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3729 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3730 | * Make sure the caller is the calling package itself |
| 3731 | * |
| 3732 | * @throws SecurityException if the caller is not the calling package |
| 3733 | */ |
| 3734 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3735 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3736 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3737 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3738 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3739 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3740 | } catch (PackageManager.NameNotFoundException e) { |
| 3741 | // packageUid is -1 |
| 3742 | } |
| 3743 | if (packageUid != callingUid) { |
| 3744 | throw new SecurityException(message + ": Package " + callingPackage |
| 3745 | + " does not belong to " + callingUid); |
| 3746 | } |
| 3747 | } |
| 3748 | |
| 3749 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3750 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3751 | * |
| 3752 | * @throws SecurityException if the caller does not have the required permission |
| 3753 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3754 | @VisibleForTesting |
| 3755 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3756 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3757 | } |
| 3758 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3759 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3760 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3761 | * |
| 3762 | * @throws SecurityException if the caller does not have the required permission |
| 3763 | */ |
| 3764 | @VisibleForTesting |
| 3765 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3766 | enforceReadPermission(null); |
| 3767 | } |
| 3768 | |
| 3769 | /** |
| 3770 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3771 | * |
| 3772 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3773 | */ |
| 3774 | @VisibleForTesting |
| 3775 | public void enforceReadPermission(String msg) { |
| 3776 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3777 | } |
| 3778 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3779 | private void enforceActiveEmergencySessionPermission() { |
| 3780 | mApp.enforceCallingOrSelfPermission( |
| 3781 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3782 | } |
| 3783 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3784 | /** |
| 3785 | * Make sure the caller has the CALL_PHONE permission. |
| 3786 | * |
| 3787 | * @throws SecurityException if the caller does not have the required permission |
| 3788 | */ |
| 3789 | private void enforceCallPermission() { |
| 3790 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3791 | } |
| 3792 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3793 | private void enforceSettingsPermission() { |
| 3794 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3797 | private void enforceRebootPermission() { |
| 3798 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3799 | } |
| 3800 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3801 | /** |
| 3802 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3803 | * @param message - log message to print. |
| 3804 | * @throws SecurityException if the caller does not have the required permission |
| 3805 | */ |
| 3806 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3807 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3808 | } |
| 3809 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3810 | private String createTelUrl(String number) { |
| 3811 | if (TextUtils.isEmpty(number)) { |
| 3812 | return null; |
| 3813 | } |
| 3814 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3815 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3818 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3819 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3822 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3823 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3826 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3827 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3830 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3831 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3832 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3833 | } |
| 3834 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3835 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3836 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3837 | final long identity = Binder.clearCallingIdentity(); |
| 3838 | try { |
| 3839 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3840 | if (phone == null) { |
| 3841 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3842 | } else { |
| 3843 | return phone.getPhoneType(); |
| 3844 | } |
| 3845 | } finally { |
| 3846 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3847 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | /** |
| 3851 | * Returns the CDMA ERI icon index to display |
| 3852 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3853 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3854 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3855 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3856 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3857 | } |
| 3858 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3859 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3860 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3861 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3862 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3863 | mApp, subId, callingPackage, callingFeatureId, |
| 3864 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3865 | return -1; |
| 3866 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3867 | |
| 3868 | final long identity = Binder.clearCallingIdentity(); |
| 3869 | try { |
| 3870 | final Phone phone = getPhone(subId); |
| 3871 | if (phone != null) { |
| 3872 | return phone.getCdmaEriIconIndex(); |
| 3873 | } else { |
| 3874 | return -1; |
| 3875 | } |
| 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3878 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | /** |
| 3882 | * Returns the CDMA ERI icon mode, |
| 3883 | * 0 - ON |
| 3884 | * 1 - FLASHING |
| 3885 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3886 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3887 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3888 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3889 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3892 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3893 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3894 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3895 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3896 | mApp, subId, callingPackage, callingFeatureId, |
| 3897 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3898 | return -1; |
| 3899 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3900 | |
| 3901 | final long identity = Binder.clearCallingIdentity(); |
| 3902 | try { |
| 3903 | final Phone phone = getPhone(subId); |
| 3904 | if (phone != null) { |
| 3905 | return phone.getCdmaEriIconMode(); |
| 3906 | } else { |
| 3907 | return -1; |
| 3908 | } |
| 3909 | } finally { |
| 3910 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3911 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | /** |
| 3915 | * Returns the CDMA ERI text, |
| 3916 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3917 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3918 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3919 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3920 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3921 | } |
| 3922 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3923 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3924 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3925 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3927 | mApp, subId, callingPackage, callingFeatureId, |
| 3928 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3929 | return null; |
| 3930 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3931 | |
| 3932 | final long identity = Binder.clearCallingIdentity(); |
| 3933 | try { |
| 3934 | final Phone phone = getPhone(subId); |
| 3935 | if (phone != null) { |
| 3936 | return phone.getCdmaEriText(); |
| 3937 | } else { |
| 3938 | return null; |
| 3939 | } |
| 3940 | } finally { |
| 3941 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3942 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3946 | * Returns the CDMA MDN. |
| 3947 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3948 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3949 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3951 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3952 | |
| 3953 | final long identity = Binder.clearCallingIdentity(); |
| 3954 | try { |
| 3955 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3956 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3957 | return phone.getLine1Number(); |
| 3958 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3959 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3960 | return null; |
| 3961 | } |
| 3962 | } finally { |
| 3963 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3964 | } |
| 3965 | } |
| 3966 | |
| 3967 | /** |
| 3968 | * Returns the CDMA MIN. |
| 3969 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3970 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3971 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3972 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3973 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3974 | |
| 3975 | final long identity = Binder.clearCallingIdentity(); |
| 3976 | try { |
| 3977 | final Phone phone = getPhone(subId); |
| 3978 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3979 | return phone.getCdmaMin(); |
| 3980 | } else { |
| 3981 | return null; |
| 3982 | } |
| 3983 | } finally { |
| 3984 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3985 | } |
| 3986 | } |
| 3987 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3988 | @Override |
| 3989 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3990 | INumberVerificationCallback callback, String callingPackage) { |
| 3991 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3992 | != PERMISSION_GRANTED) { |
| 3993 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3994 | } |
| 3995 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3996 | |
| 3997 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3998 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3999 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4000 | + "calling package: " + callingPackage |
| 4001 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | if (range == null) { |
| 4005 | throw new NullPointerException("Range must be non-null"); |
| 4006 | } |
| 4007 | |
| 4008 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4009 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4010 | |
| 4011 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4012 | } |
| 4013 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4014 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4015 | * Returns true if CDMA provisioning needs to run. |
| 4016 | */ |
| 4017 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4018 | final long identity = Binder.clearCallingIdentity(); |
| 4019 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4020 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 | } finally { |
| 4022 | Binder.restoreCallingIdentity(identity); |
| 4023 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4027 | * Sets the voice mail number of a given subId. |
| 4028 | */ |
| 4029 | @Override |
| 4030 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4031 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4032 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4033 | |
| 4034 | final long identity = Binder.clearCallingIdentity(); |
| 4035 | try { |
| 4036 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4037 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4038 | return success; |
| 4039 | } finally { |
| 4040 | Binder.restoreCallingIdentity(identity); |
| 4041 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4042 | } |
| 4043 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4044 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4045 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4046 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4047 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4048 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4049 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4050 | throw new SecurityException("caller must be system dialer"); |
| 4051 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4052 | |
| 4053 | final long identity = Binder.clearCallingIdentity(); |
| 4054 | try { |
| 4055 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4056 | if (phoneAccountHandle == null) { |
| 4057 | return null; |
| 4058 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4059 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4062 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4066 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4067 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4068 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4069 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4070 | mApp, subId, callingPackage, callingFeatureId, |
| 4071 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4072 | return null; |
| 4073 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4074 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4075 | final long identity = Binder.clearCallingIdentity(); |
| 4076 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4077 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4078 | } finally { |
| 4079 | Binder.restoreCallingIdentity(identity); |
| 4080 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4084 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4085 | VisualVoicemailSmsFilterSettings settings) { |
| 4086 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4087 | |
| 4088 | final long identity = Binder.clearCallingIdentity(); |
| 4089 | try { |
| 4090 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4091 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | } finally { |
| 4093 | Binder.restoreCallingIdentity(identity); |
| 4094 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4098 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4099 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | |
| 4101 | final long identity = Binder.clearCallingIdentity(); |
| 4102 | try { |
| 4103 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4104 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4105 | } finally { |
| 4106 | Binder.restoreCallingIdentity(identity); |
| 4107 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4111 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4112 | String callingPackage, int subId) { |
| 4113 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4114 | |
| 4115 | final long identity = Binder.clearCallingIdentity(); |
| 4116 | try { |
| 4117 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4118 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4119 | } finally { |
| 4120 | Binder.restoreCallingIdentity(identity); |
| 4121 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4125 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4126 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4127 | |
| 4128 | final long identity = Binder.clearCallingIdentity(); |
| 4129 | try { |
| 4130 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4131 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | } finally { |
| 4133 | Binder.restoreCallingIdentity(identity); |
| 4134 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4138 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4139 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4140 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4141 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4142 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4143 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4144 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4145 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4146 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4147 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4148 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4149 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4150 | * Sets the voice activation state of a given subId. |
| 4151 | */ |
| 4152 | @Override |
| 4153 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4154 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4155 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4156 | |
| 4157 | final long identity = Binder.clearCallingIdentity(); |
| 4158 | try { |
| 4159 | final Phone phone = getPhone(subId); |
| 4160 | if (phone != null) { |
| 4161 | phone.setVoiceActivationState(activationState); |
| 4162 | } else { |
| 4163 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4164 | } |
| 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | /** |
| 4171 | * Sets the data activation state of a given subId. |
| 4172 | */ |
| 4173 | @Override |
| 4174 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4175 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4176 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | |
| 4178 | final long identity = Binder.clearCallingIdentity(); |
| 4179 | try { |
| 4180 | final Phone phone = getPhone(subId); |
| 4181 | if (phone != null) { |
| 4182 | phone.setDataActivationState(activationState); |
| 4183 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4184 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4185 | } |
| 4186 | } finally { |
| 4187 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | /** |
| 4192 | * Returns the voice activation state of a given subId. |
| 4193 | */ |
| 4194 | @Override |
| 4195 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4196 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4197 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4198 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4199 | final long identity = Binder.clearCallingIdentity(); |
| 4200 | try { |
| 4201 | if (phone != null) { |
| 4202 | return phone.getVoiceActivationState(); |
| 4203 | } else { |
| 4204 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4205 | } |
| 4206 | } finally { |
| 4207 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | /** |
| 4212 | * Returns the data activation state of a given subId. |
| 4213 | */ |
| 4214 | @Override |
| 4215 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4216 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4217 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4218 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4219 | final long identity = Binder.clearCallingIdentity(); |
| 4220 | try { |
| 4221 | if (phone != null) { |
| 4222 | return phone.getDataActivationState(); |
| 4223 | } else { |
| 4224 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4225 | } |
| 4226 | } finally { |
| 4227 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4228 | } |
| 4229 | } |
| 4230 | |
| 4231 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4232 | * Returns the unread count of voicemails for a subId |
| 4233 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4234 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4235 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4236 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4237 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4238 | mApp, subId, callingPackage, callingFeatureId, |
| 4239 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4240 | return 0; |
| 4241 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4242 | final long identity = Binder.clearCallingIdentity(); |
| 4243 | try { |
| 4244 | final Phone phone = getPhone(subId); |
| 4245 | if (phone != null) { |
| 4246 | return phone.getVoiceMessageCount(); |
| 4247 | } else { |
| 4248 | return 0; |
| 4249 | } |
| 4250 | } finally { |
| 4251 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4256 | * returns true, if the device is in a state where both voice and data |
| 4257 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4258 | */ |
| 4259 | @Override |
| 4260 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4261 | final long identity = Binder.clearCallingIdentity(); |
| 4262 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4263 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4264 | } finally { |
| 4265 | Binder.restoreCallingIdentity(identity); |
| 4266 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4270 | * Send the dialer code if called from the current default dialer or the caller has |
| 4271 | * carrier privilege. |
| 4272 | * @param inputCode The dialer code to send |
| 4273 | */ |
| 4274 | @Override |
| 4275 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4276 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4277 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4278 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4279 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4280 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4281 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4282 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4283 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4284 | |
| 4285 | final long identity = Binder.clearCallingIdentity(); |
| 4286 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4287 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4288 | } finally { |
| 4289 | Binder.restoreCallingIdentity(identity); |
| 4290 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4291 | } |
| 4292 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4293 | @Override |
| 4294 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4295 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4296 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4297 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4298 | final long identity = Binder.clearCallingIdentity(); |
| 4299 | try { |
| 4300 | if (!isActiveSubscription(subId)) { |
| 4301 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4302 | } |
| 4303 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4304 | } finally { |
| 4305 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4306 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4307 | } |
| 4308 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4309 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4310 | public boolean isInEmergencySmsMode() { |
| 4311 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4312 | final long identity = Binder.clearCallingIdentity(); |
| 4313 | try { |
| 4314 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4315 | if (phone.isInEmergencySmsMode()) { |
| 4316 | return true; |
| 4317 | } |
| 4318 | } |
| 4319 | } finally { |
| 4320 | Binder.restoreCallingIdentity(identity); |
| 4321 | } |
| 4322 | return false; |
| 4323 | } |
| 4324 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4325 | /** |
| 4326 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4327 | * @param subId The subscription to use to check the configuration. |
| 4328 | * @param c The callback that will be used to send the result. |
| 4329 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4330 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4331 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4332 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4333 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4334 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4335 | |
| 4336 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4337 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4338 | "IMS not available on device."); |
| 4339 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4340 | final long token = Binder.clearCallingIdentity(); |
| 4341 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4342 | int slotId = getSlotIndexOrException(subId); |
| 4343 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4344 | |
| 4345 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4346 | if (controller != null) { |
| 4347 | ImsManager imsManager = controller.getImsManager(subId); |
| 4348 | if (imsManager != null) { |
| 4349 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4350 | } else { |
| 4351 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4352 | } |
| 4353 | } else { |
| 4354 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4355 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4356 | } catch (ImsException e) { |
| 4357 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(token); |
| 4360 | } |
| 4361 | } |
| 4362 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4363 | /** |
| 4364 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4365 | * @param subId The subscription to use to check the configuration. |
| 4366 | * @param c The callback that will be used to send the result. |
| 4367 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4368 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4369 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4370 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4371 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4372 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4373 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4374 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4375 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4376 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4377 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4378 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4379 | if (controller != null) { |
| 4380 | ImsManager imsManager = controller.getImsManager(subId); |
| 4381 | if (imsManager != null) { |
| 4382 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4383 | } else { |
| 4384 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4385 | + "is inactive, ignoring unregister."); |
| 4386 | // If the ImsManager is not valid, just return, since the callback |
| 4387 | // will already have been removed internally. |
| 4388 | } |
| 4389 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4390 | } finally { |
| 4391 | Binder.restoreCallingIdentity(token); |
| 4392 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4393 | } |
| 4394 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4395 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4396 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4397 | * @param subId The subscription to use to check the configuration. |
| 4398 | * @param c The callback that will be used to send the result. |
| 4399 | */ |
| 4400 | @Override |
| 4401 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4402 | throws RemoteException { |
| 4403 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4404 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4405 | |
| 4406 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4407 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4408 | "IMS not available on device."); |
| 4409 | } |
| 4410 | final long token = Binder.clearCallingIdentity(); |
| 4411 | try { |
| 4412 | int slotId = getSlotIndexOrException(subId); |
| 4413 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4414 | |
| 4415 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4416 | if (controller != null) { |
| 4417 | ImsManager imsManager = controller.getImsManager(subId); |
| 4418 | if (imsManager != null) { |
| 4419 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4420 | } else { |
| 4421 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4422 | } |
| 4423 | } else { |
| 4424 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4425 | } |
| 4426 | } catch (ImsException e) { |
| 4427 | throw new ServiceSpecificException(e.getCode()); |
| 4428 | } finally { |
| 4429 | Binder.restoreCallingIdentity(token); |
| 4430 | } |
| 4431 | } |
| 4432 | |
| 4433 | /** |
| 4434 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4435 | * @param subId The subscription to use to check the configuration. |
| 4436 | * @param c The callback that will be used to send the result. |
| 4437 | */ |
| 4438 | @Override |
| 4439 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4440 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4441 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4442 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4443 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4444 | } |
| 4445 | final long token = Binder.clearCallingIdentity(); |
| 4446 | |
| 4447 | try { |
| 4448 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4449 | if (controller != null) { |
| 4450 | ImsManager imsManager = controller.getImsManager(subId); |
| 4451 | if (imsManager != null) { |
| 4452 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4453 | } else { |
| 4454 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4455 | + "is inactive, ignoring unregister."); |
| 4456 | // If the ImsManager is not valid, just return, since the callback |
| 4457 | // will already have been removed internally. |
| 4458 | } |
| 4459 | } |
| 4460 | } finally { |
| 4461 | Binder.restoreCallingIdentity(token); |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4466 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4467 | */ |
| 4468 | @Override |
| 4469 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4470 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4471 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4472 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4473 | "IMS not available on device."); |
| 4474 | } |
| 4475 | final long token = Binder.clearCallingIdentity(); |
| 4476 | try { |
| 4477 | Phone phone = getPhone(subId); |
| 4478 | if (phone == null) { |
| 4479 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4480 | + subId + "'"); |
| 4481 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4482 | } |
| 4483 | phone.getImsRegistrationState(regState -> { |
| 4484 | try { |
| 4485 | consumer.accept((regState == null) |
| 4486 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4487 | } catch (RemoteException e) { |
| 4488 | // Ignore if the remote process is no longer available to call back. |
| 4489 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4490 | } |
| 4491 | }); |
| 4492 | } finally { |
| 4493 | Binder.restoreCallingIdentity(token); |
| 4494 | } |
| 4495 | } |
| 4496 | |
| 4497 | /** |
| 4498 | * Get the transport type for the IMS service registration state. |
| 4499 | */ |
| 4500 | @Override |
| 4501 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4502 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4503 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4504 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4505 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4506 | "IMS not available on device."); |
| 4507 | } |
| 4508 | final long token = Binder.clearCallingIdentity(); |
| 4509 | try { |
| 4510 | Phone phone = getPhone(subId); |
| 4511 | if (phone == null) { |
| 4512 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4513 | + subId + "'"); |
| 4514 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4515 | } |
| 4516 | phone.getImsRegistrationTech(regTech -> { |
| 4517 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4518 | int regTechConverted = (regTech == null) |
| 4519 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4520 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4521 | regTechConverted); |
| 4522 | try { |
| 4523 | consumer.accept(regTechConverted); |
| 4524 | } catch (RemoteException e) { |
| 4525 | // Ignore if the remote process is no longer available to call back. |
| 4526 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4527 | } |
| 4528 | }); |
| 4529 | } finally { |
| 4530 | Binder.restoreCallingIdentity(token); |
| 4531 | } |
| 4532 | } |
| 4533 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4534 | /** |
| 4535 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4536 | * @param subId The subscription to use to check the configuration. |
| 4537 | * @param c The callback that will be used to send the result. |
| 4538 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4539 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4540 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4541 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4542 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4543 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4544 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4545 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4546 | "IMS not available on device."); |
| 4547 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4548 | final long token = Binder.clearCallingIdentity(); |
| 4549 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4550 | int slotId = getSlotIndexOrException(subId); |
| 4551 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4552 | |
| 4553 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4554 | if (controller != null) { |
| 4555 | ImsManager imsManager = controller.getImsManager(subId); |
| 4556 | if (imsManager != null) { |
| 4557 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4558 | } else { |
| 4559 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4560 | } |
| 4561 | } else { |
| 4562 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4563 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4564 | } catch (ImsException e) { |
| 4565 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4566 | } finally { |
| 4567 | Binder.restoreCallingIdentity(token); |
| 4568 | } |
| 4569 | } |
| 4570 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4571 | /** |
| 4572 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4573 | * @param subId The subscription to use to check the configuration. |
| 4574 | * @param c The callback that will be used to send the result. |
| 4575 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4576 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4577 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4578 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4579 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4580 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4581 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4582 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4583 | |
| 4584 | final long token = Binder.clearCallingIdentity(); |
| 4585 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4586 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4587 | if (controller != null) { |
| 4588 | ImsManager imsManager = controller.getImsManager(subId); |
| 4589 | if (imsManager != null) { |
| 4590 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4591 | } else { |
| 4592 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4593 | + " is inactive, ignoring unregister."); |
| 4594 | // If the ImsManager is not valid, just return, since the callback |
| 4595 | // will already have been removed internally. |
| 4596 | } |
| 4597 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4598 | } finally { |
| 4599 | Binder.restoreCallingIdentity(token); |
| 4600 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4604 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4605 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4606 | final long token = Binder.clearCallingIdentity(); |
| 4607 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4608 | int slotId = getSlotIndexOrException(subId); |
| 4609 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4610 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4611 | } catch (com.android.ims.ImsException e) { |
| 4612 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4613 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4614 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4615 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4616 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4617 | } finally { |
| 4618 | Binder.restoreCallingIdentity(token); |
| 4619 | } |
| 4620 | } |
| 4621 | |
| 4622 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4623 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4624 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4625 | final long token = Binder.clearCallingIdentity(); |
| 4626 | try { |
| 4627 | Phone phone = getPhone(subId); |
| 4628 | if (phone == null) return false; |
| 4629 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4630 | } catch (com.android.ims.ImsException e) { |
| 4631 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4632 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4633 | } finally { |
| 4634 | Binder.restoreCallingIdentity(token); |
| 4635 | } |
| 4636 | } |
| 4637 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4638 | /** |
| 4639 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4640 | * subscription. |
| 4641 | * @param subId The subscription to use to check the configuration. |
| 4642 | * @param callback The callback that will be used to send the result. |
| 4643 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4644 | * @param transportType The transport type of the MmTelFeature capability. |
| 4645 | */ |
| 4646 | @Override |
| 4647 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4648 | int transportType) { |
| 4649 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4650 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4651 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4652 | "IMS not available on device."); |
| 4653 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4654 | final long token = Binder.clearCallingIdentity(); |
| 4655 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4656 | int slotId = getSlotIndex(subId); |
| 4657 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4658 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4659 | + subId + "'"); |
| 4660 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4661 | } |
| 4662 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4663 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4664 | transportType, aBoolean -> { |
| 4665 | try { |
| 4666 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4667 | } catch (RemoteException e) { |
| 4668 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4669 | + "running. Ignore"); |
| 4670 | } |
| 4671 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4672 | } catch (ImsException e) { |
| 4673 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4674 | } finally { |
| 4675 | Binder.restoreCallingIdentity(token); |
| 4676 | } |
| 4677 | } |
| 4678 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4679 | /** |
| 4680 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4681 | * @param subId The subscription to use to check the configuration. |
| 4682 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4683 | @Override |
| 4684 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4685 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4686 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4687 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4688 | final long token = Binder.clearCallingIdentity(); |
| 4689 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4690 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4691 | // 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] | 4692 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4693 | } catch (ImsException e) { |
| 4694 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4695 | } finally { |
| 4696 | Binder.restoreCallingIdentity(token); |
| 4697 | } |
| 4698 | } |
| 4699 | |
| 4700 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4701 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4702 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4703 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4704 | final long identity = Binder.clearCallingIdentity(); |
| 4705 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4706 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4707 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4708 | // 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] | 4709 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4710 | } catch (ImsException e) { |
| 4711 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4712 | } finally { |
| 4713 | Binder.restoreCallingIdentity(identity); |
| 4714 | } |
| 4715 | } |
| 4716 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4717 | /** |
| 4718 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4719 | * @param subId The subscription to use to check the configuration. |
| 4720 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4721 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4722 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4723 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4724 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4725 | final long identity = Binder.clearCallingIdentity(); |
| 4726 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4727 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4728 | // 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] | 4729 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4730 | } catch (ImsException e) { |
| 4731 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4732 | } finally { |
| 4733 | Binder.restoreCallingIdentity(identity); |
| 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4738 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4739 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4740 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4741 | final long identity = Binder.clearCallingIdentity(); |
| 4742 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4743 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4744 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4745 | // 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] | 4746 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4747 | } catch (ImsException e) { |
| 4748 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4749 | } finally { |
| 4750 | Binder.restoreCallingIdentity(identity); |
| 4751 | } |
| 4752 | } |
| 4753 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4754 | /** |
| 4755 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4756 | * @param subId The subscription to use to check the configuration. |
| 4757 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4758 | @Override |
| 4759 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4760 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4761 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4762 | final long identity = Binder.clearCallingIdentity(); |
| 4763 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4764 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4765 | // 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] | 4766 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4767 | } catch (ImsException e) { |
| 4768 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4769 | } finally { |
| 4770 | Binder.restoreCallingIdentity(identity); |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4775 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4776 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4777 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4778 | final long identity = Binder.clearCallingIdentity(); |
| 4779 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4780 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4781 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4782 | // 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] | 4783 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4784 | } catch (ImsException e) { |
| 4785 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4786 | } finally { |
| 4787 | Binder.restoreCallingIdentity(identity); |
| 4788 | } |
| 4789 | } |
| 4790 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4791 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4792 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4793 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4794 | * @param subId The subscription to use to check the configuration. |
| 4795 | */ |
| 4796 | @Override |
| 4797 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4798 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4799 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4800 | final long identity = Binder.clearCallingIdentity(); |
| 4801 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4802 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4803 | // 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] | 4804 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4805 | } catch (ImsException e) { |
| 4806 | throw new ServiceSpecificException(e.getCode()); |
| 4807 | } finally { |
| 4808 | Binder.restoreCallingIdentity(identity); |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | /** |
| 4813 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4814 | * Requires MODIFY_PHONE_STATE permission. |
| 4815 | * @param subId The subscription to use to check the configuration. |
| 4816 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4817 | * false otherwise |
| 4818 | */ |
| 4819 | @Override |
| 4820 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4822 | "setCrossSimCallingEnabled"); |
| 4823 | final long identity = Binder.clearCallingIdentity(); |
| 4824 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4825 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4826 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4827 | // 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] | 4828 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4829 | } catch (ImsException e) { |
| 4830 | throw new ServiceSpecificException(e.getCode()); |
| 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(identity); |
| 4833 | } |
| 4834 | } |
| 4835 | |
| 4836 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4837 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4838 | * @param subId The subscription to use to check the configuration. |
| 4839 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4840 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4841 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4842 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4843 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4844 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4845 | final long identity = Binder.clearCallingIdentity(); |
| 4846 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4847 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4848 | // 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] | 4849 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4850 | } catch (ImsException e) { |
| 4851 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4852 | } finally { |
| 4853 | Binder.restoreCallingIdentity(identity); |
| 4854 | } |
| 4855 | } |
| 4856 | |
| 4857 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4858 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4859 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4860 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4861 | final long identity = Binder.clearCallingIdentity(); |
| 4862 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4863 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4864 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4865 | // 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] | 4866 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4867 | } catch (ImsException e) { |
| 4868 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4869 | } finally { |
| 4870 | Binder.restoreCallingIdentity(identity); |
| 4871 | } |
| 4872 | } |
| 4873 | |
| 4874 | @Override |
| 4875 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4876 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4877 | "setVoWiFiNonPersistent"); |
| 4878 | final long identity = Binder.clearCallingIdentity(); |
| 4879 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4880 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4881 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4882 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4883 | } catch (ImsException e) { |
| 4884 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4885 | } finally { |
| 4886 | Binder.restoreCallingIdentity(identity); |
| 4887 | } |
| 4888 | } |
| 4889 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4890 | /** |
| 4891 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4892 | * @param subId The subscription to use to check the configuration. |
| 4893 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4894 | @Override |
| 4895 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4896 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4897 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4898 | final long identity = Binder.clearCallingIdentity(); |
| 4899 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4900 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4901 | // 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] | 4902 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4903 | } catch (ImsException e) { |
| 4904 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4905 | } finally { |
| 4906 | Binder.restoreCallingIdentity(identity); |
| 4907 | } |
| 4908 | } |
| 4909 | |
| 4910 | @Override |
| 4911 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4913 | "setVoWiFiModeSetting"); |
| 4914 | final long identity = Binder.clearCallingIdentity(); |
| 4915 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4916 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4917 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4918 | // 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] | 4919 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4920 | } catch (ImsException e) { |
| 4921 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4922 | } finally { |
| 4923 | Binder.restoreCallingIdentity(identity); |
| 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | @Override |
| 4928 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4929 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4930 | final long identity = Binder.clearCallingIdentity(); |
| 4931 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4932 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4933 | // 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] | 4934 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4935 | } catch (ImsException e) { |
| 4936 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
| 4939 | } |
| 4940 | } |
| 4941 | |
| 4942 | @Override |
| 4943 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4945 | "setVoWiFiRoamingModeSetting"); |
| 4946 | final long identity = Binder.clearCallingIdentity(); |
| 4947 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4948 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4949 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4950 | // 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] | 4951 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4952 | } catch (ImsException e) { |
| 4953 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4954 | } finally { |
| 4955 | Binder.restoreCallingIdentity(identity); |
| 4956 | } |
| 4957 | } |
| 4958 | |
| 4959 | @Override |
| 4960 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4961 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4962 | "setRttCapabilityEnabled"); |
| 4963 | final long identity = Binder.clearCallingIdentity(); |
| 4964 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4965 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4966 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4967 | // 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] | 4968 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4969 | } catch (ImsException e) { |
| 4970 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4971 | } finally { |
| 4972 | Binder.restoreCallingIdentity(identity); |
| 4973 | } |
| 4974 | } |
| 4975 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4976 | /** |
| 4977 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4978 | * @param subId The subscription to use to check the configuration. |
| 4979 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4980 | @Override |
| 4981 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4982 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4983 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4984 | final long identity = Binder.clearCallingIdentity(); |
| 4985 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4986 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4987 | // 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] | 4988 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4989 | } catch (ImsException e) { |
| 4990 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4991 | } finally { |
| 4992 | Binder.restoreCallingIdentity(identity); |
| 4993 | } |
| 4994 | } |
| 4995 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4996 | @Override |
| 4997 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4998 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4999 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5000 | final long identity = Binder.clearCallingIdentity(); |
| 5001 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5002 | if (!isImsAvailableOnDevice()) { |
| 5003 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5004 | "IMS not available on device."); |
| 5005 | } |
| 5006 | int slotId = getSlotIndexOrException(subId); |
| 5007 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5008 | |
| 5009 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5010 | if (controller != null) { |
| 5011 | ImsManager imsManager = controller.getImsManager(subId); |
| 5012 | if (imsManager != null) { |
| 5013 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5014 | } else { |
| 5015 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5016 | } |
| 5017 | } else { |
| 5018 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5019 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5020 | } catch (ImsException e) { |
| 5021 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5022 | } finally { |
| 5023 | Binder.restoreCallingIdentity(identity); |
| 5024 | } |
| 5025 | } |
| 5026 | |
| 5027 | @Override |
| 5028 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5029 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5030 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5031 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5032 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5033 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5034 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5035 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5036 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5037 | if (controller != null) { |
| 5038 | ImsManager imsManager = controller.getImsManager(subId); |
| 5039 | if (imsManager != null) { |
| 5040 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5041 | } else { |
| 5042 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5043 | + " is inactive, ignoring unregister."); |
| 5044 | // If the ImsManager is not valid, just return, since the callback will already |
| 5045 | // have been removed internally. |
| 5046 | } |
| 5047 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5048 | } finally { |
| 5049 | Binder.restoreCallingIdentity(identity); |
| 5050 | } |
| 5051 | } |
| 5052 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5053 | @Override |
| 5054 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5055 | IFeatureProvisioningCallback callback) { |
| 5056 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5057 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5058 | |
| 5059 | final long identity = Binder.clearCallingIdentity(); |
| 5060 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5061 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5062 | } |
| 5063 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5064 | try { |
| 5065 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5066 | if (controller == null) { |
| 5067 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5068 | "Device does not support IMS"); |
| 5069 | } |
| 5070 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5071 | } finally { |
| 5072 | Binder.restoreCallingIdentity(identity); |
| 5073 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5074 | } |
| 5075 | |
| 5076 | @Override |
| 5077 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5078 | IFeatureProvisioningCallback callback) { |
| 5079 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5080 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5081 | |
| 5082 | final long identity = Binder.clearCallingIdentity(); |
| 5083 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5084 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5085 | } |
| 5086 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5087 | try { |
| 5088 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5089 | if (controller == null) { |
| 5090 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5091 | return; |
| 5092 | } |
| 5093 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5094 | } finally { |
| 5095 | Binder.restoreCallingIdentity(identity); |
| 5096 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5097 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5098 | |
| 5099 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5100 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5101 | message); |
| 5102 | } |
| 5103 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5104 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5105 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5106 | boolean isProvisioned) { |
| 5107 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5108 | |
| 5109 | final long identity = Binder.clearCallingIdentity(); |
| 5110 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5111 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5112 | if (controller == null) { |
| 5113 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5114 | return; |
| 5115 | } |
| 5116 | controller.setRcsProvisioningStatusForCapability( |
| 5117 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5118 | } finally { |
| 5119 | Binder.restoreCallingIdentity(identity); |
| 5120 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | |
| 5124 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5125 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5126 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5127 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5128 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5129 | final long identity = Binder.clearCallingIdentity(); |
| 5130 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5131 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5132 | if (controller == null) { |
| 5133 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5134 | |
| 5135 | // device does not support IMS, this method will return true always. |
| 5136 | return true; |
| 5137 | } |
| 5138 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5139 | } finally { |
| 5140 | Binder.restoreCallingIdentity(identity); |
| 5141 | } |
| 5142 | } |
| 5143 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5144 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5145 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5146 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5147 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5148 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5149 | final long identity = Binder.clearCallingIdentity(); |
| 5150 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5151 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5152 | if (controller == null) { |
| 5153 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5154 | return; |
| 5155 | } |
| 5156 | controller.setImsProvisioningStatusForCapability( |
| 5157 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5158 | } finally { |
| 5159 | Binder.restoreCallingIdentity(identity); |
| 5160 | } |
| 5161 | } |
| 5162 | |
| 5163 | @Override |
| 5164 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5165 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5166 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5167 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5168 | final long identity = Binder.clearCallingIdentity(); |
| 5169 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5170 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5171 | if (controller == null) { |
| 5172 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5173 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5174 | // device does not support IMS, this method will return true always. |
| 5175 | return true; |
| 5176 | } |
| 5177 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5178 | } finally { |
| 5179 | Binder.restoreCallingIdentity(identity); |
| 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5184 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5185 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5186 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5187 | |
| 5188 | final long identity = Binder.clearCallingIdentity(); |
| 5189 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5190 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5191 | if (controller == null) { |
| 5192 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5193 | |
| 5194 | // device does not support IMS, this method will return false |
| 5195 | return false; |
| 5196 | } |
| 5197 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5198 | } finally { |
| 5199 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5200 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5204 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5205 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5206 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5207 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5208 | final long identity = Binder.clearCallingIdentity(); |
| 5209 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5210 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5211 | if (controller == null) { |
| 5212 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5213 | |
| 5214 | // device does not support IMS, this method will return false |
| 5215 | return false; |
| 5216 | } |
| 5217 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5218 | } finally { |
| 5219 | Binder.restoreCallingIdentity(identity); |
| 5220 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5221 | } |
| 5222 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5223 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5224 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5225 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5226 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5227 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5228 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5229 | mApp, subId, "getImsProvisioningInt"); |
| 5230 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5231 | final long identity = Binder.clearCallingIdentity(); |
| 5232 | try { |
| 5233 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5234 | int slotId = getSlotIndex(subId); |
| 5235 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5236 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5237 | + subId + "' for key:" + key); |
| 5238 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5239 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5240 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5241 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5242 | if (controller == null) { |
| 5243 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5244 | |
| 5245 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5246 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5247 | } |
| 5248 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5249 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5250 | return retVal; |
| 5251 | } |
| 5252 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5253 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5254 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5255 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5256 | + subId + "' for key:" + key); |
| 5257 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
| 5260 | } |
| 5261 | } |
| 5262 | |
| 5263 | @Override |
| 5264 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5265 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5266 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5267 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5268 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5269 | mApp, subId, "getImsProvisioningString"); |
| 5270 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5271 | final long identity = Binder.clearCallingIdentity(); |
| 5272 | try { |
| 5273 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5274 | int slotId = getSlotIndex(subId); |
| 5275 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5276 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5277 | + subId + "' for key:" + key); |
| 5278 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5279 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5280 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5281 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5282 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5283 | + subId + "' for key:" + key); |
| 5284 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5285 | } finally { |
| 5286 | Binder.restoreCallingIdentity(identity); |
| 5287 | } |
| 5288 | } |
| 5289 | |
| 5290 | @Override |
| 5291 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5292 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5293 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5294 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5295 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5296 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5297 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5298 | final long identity = Binder.clearCallingIdentity(); |
| 5299 | try { |
| 5300 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5301 | int slotId = getSlotIndex(subId); |
| 5302 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5303 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5304 | + subId + "' for key:" + key); |
| 5305 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5306 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5307 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5308 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5309 | if (controller == null) { |
| 5310 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5311 | |
| 5312 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5313 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5314 | } |
| 5315 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5316 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5317 | return retVal; |
| 5318 | } |
| 5319 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5320 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5321 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5322 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5323 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5324 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5325 | } finally { |
| 5326 | Binder.restoreCallingIdentity(identity); |
| 5327 | } |
| 5328 | } |
| 5329 | |
| 5330 | @Override |
| 5331 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5332 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5333 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5334 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5336 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5337 | final long identity = Binder.clearCallingIdentity(); |
| 5338 | try { |
| 5339 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5340 | int slotId = getSlotIndex(subId); |
| 5341 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5342 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5343 | + subId + "' for key:" + key); |
| 5344 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5345 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5346 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5347 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5348 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5349 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5350 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5351 | } finally { |
| 5352 | Binder.restoreCallingIdentity(identity); |
| 5353 | } |
| 5354 | } |
| 5355 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5356 | /** |
| 5357 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5358 | * for the given slot ID or no ImsResolver instance has been created. |
| 5359 | * @param slotId The slot ID that the IMS service is created for. |
| 5360 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5361 | */ |
| 5362 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5363 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5364 | ImsFeature.FEATURE_MMTEL)) { |
| 5365 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5366 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5367 | } |
| 5368 | } |
| 5369 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5370 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5371 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5372 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5373 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5374 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5375 | } |
| 5376 | return slotId; |
| 5377 | } |
| 5378 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5379 | private int getSlotIndex(int subId) { |
| 5380 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5381 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5382 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5383 | } |
| 5384 | return slotId; |
| 5385 | } |
| 5386 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5387 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5388 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5389 | */ |
| 5390 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5391 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5392 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5393 | try { |
| 5394 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5395 | } catch (SecurityException se) { |
| 5396 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5397 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5398 | + Binder.getCallingUid()); |
| 5399 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5400 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5401 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5402 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5403 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5404 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5405 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5406 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5407 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5408 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5409 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | final long identity = Binder.clearCallingIdentity(); |
| 5411 | try { |
| 5412 | final Phone phone = getPhone(subId); |
| 5413 | if (phone != null) { |
| 5414 | return phone.getServiceState().getDataNetworkType(); |
| 5415 | } else { |
| 5416 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5417 | } |
| 5418 | } finally { |
| 5419 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | /** |
| 5424 | * Returns the data network type |
| 5425 | */ |
| 5426 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5427 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5428 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5429 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | /** |
| 5433 | * Returns the data network type for a subId |
| 5434 | */ |
| 5435 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5436 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5437 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5438 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5439 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5440 | mApp, functionName)) { |
| 5441 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5442 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5443 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5444 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | final long identity = Binder.clearCallingIdentity(); |
| 5448 | try { |
| 5449 | final Phone phone = getPhone(subId); |
| 5450 | if (phone != null) { |
| 5451 | return phone.getServiceState().getDataNetworkType(); |
| 5452 | } else { |
| 5453 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5454 | } |
| 5455 | } finally { |
| 5456 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5457 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5461 | * Returns the Voice network type for a subId |
| 5462 | */ |
| 5463 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5464 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5465 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5466 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5467 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5468 | mApp, functionName)) { |
| 5469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5470 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5471 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5472 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5473 | } |
| 5474 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | final long identity = Binder.clearCallingIdentity(); |
| 5476 | try { |
| 5477 | final Phone phone = getPhone(subId); |
| 5478 | if (phone != null) { |
| 5479 | return phone.getServiceState().getVoiceNetworkType(); |
| 5480 | } else { |
| 5481 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5482 | } |
| 5483 | } finally { |
| 5484 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | /** |
| 5489 | * @return true if a ICC card is present |
| 5490 | */ |
| 5491 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5492 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5493 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5494 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5495 | } |
| 5496 | |
| 5497 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5498 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5499 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5500 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5501 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5502 | final long identity = Binder.clearCallingIdentity(); |
| 5503 | try { |
| 5504 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5505 | if (phone != null) { |
| 5506 | return phone.getIccCard().hasIccCard(); |
| 5507 | } else { |
| 5508 | return false; |
| 5509 | } |
| 5510 | } finally { |
| 5511 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5512 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | /** |
| 5516 | * Return if the current radio is LTE on CDMA. This |
| 5517 | * is a tri-state return value as for a period of time |
| 5518 | * the mode may be unknown. |
| 5519 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5520 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5521 | * @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] | 5522 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5523 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5524 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5525 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5526 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5527 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5528 | } |
| 5529 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5530 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5531 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5532 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5533 | try { |
| 5534 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5535 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5536 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5537 | } |
| 5538 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5539 | final long identity = Binder.clearCallingIdentity(); |
| 5540 | try { |
| 5541 | final Phone phone = getPhone(subId); |
| 5542 | if (phone == null) { |
| 5543 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5544 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5545 | return TelephonyProperties.lte_on_cdma_device() |
| 5546 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | } |
| 5548 | } finally { |
| 5549 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5550 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5551 | } |
| 5552 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5553 | /** |
| 5554 | * {@hide} |
| 5555 | * Returns Default subId, 0 in the case of single standby. |
| 5556 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5557 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5558 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5559 | } |
| 5560 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5561 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5562 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5565 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5566 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5567 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5568 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5569 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5570 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5571 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5572 | } |
| 5573 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5574 | /** |
| 5575 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5576 | */ |
| 5577 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5580 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5582 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5583 | } finally { |
| 5584 | Binder.restoreCallingIdentity(identity); |
| 5585 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | /** |
| 5589 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5590 | */ |
| 5591 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5592 | final long identity = Binder.clearCallingIdentity(); |
| 5593 | try { |
| 5594 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5595 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5596 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5597 | } finally { |
| 5598 | Binder.restoreCallingIdentity(identity); |
| 5599 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5600 | } |
| 5601 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5602 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5603 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5604 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5605 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5606 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5607 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5608 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5609 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5610 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5611 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5612 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5613 | } |
| 5614 | return PhoneFactory.getPhone(phoneId); |
| 5615 | } |
| 5616 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5617 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5618 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5619 | @NonNull IccLogicalChannelRequest request) { |
| 5620 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5621 | /*message=*/ "iccOpenLogicalChannel"); |
| 5622 | |
| 5623 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5624 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5625 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5626 | |
| 5627 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5628 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5629 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5630 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5631 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5632 | Phone phone; |
| 5633 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5635 | mApp, request.subId, message); |
| 5636 | phone = getPhoneFromSubId(request.subId); |
| 5637 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5638 | enforceModifyPermission(); |
| 5639 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5640 | } else { |
| 5641 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5642 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5643 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5647 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5648 | final long identity = Binder.clearCallingIdentity(); |
| 5649 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5650 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5651 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5652 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5653 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5654 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5655 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5656 | loge("The calling package is not allowed to access ISD-R."); |
| 5657 | throw new SecurityException( |
| 5658 | "The calling package is not allowed to access ISD-R."); |
| 5659 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5660 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5661 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5662 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5663 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5664 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5665 | return response; |
| 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
| 5668 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5672 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5673 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5674 | /*message=*/"iccCloseLogicalChannel"); |
| 5675 | |
| 5676 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5677 | |
| 5678 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5679 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5680 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5681 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5682 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5683 | // before this feature is enabled, this API should only return false if |
| 5684 | // the operation fails instead of throwing runtime exception for |
| 5685 | // backward-compatibility. |
| 5686 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5687 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5688 | final long identity = Binder.clearCallingIdentity(); |
| 5689 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5690 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5691 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5693 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5694 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5695 | Boolean success = false; |
| 5696 | if (result instanceof RuntimeException) { |
| 5697 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5698 | if (shouldThrowExceptionOnFailure) { |
| 5699 | throw (RuntimeException) result; |
| 5700 | } else { |
| 5701 | return false; |
| 5702 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5703 | } else if (result instanceof Boolean) { |
| 5704 | success = (Boolean) result; |
| 5705 | } else { |
| 5706 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5707 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5708 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5709 | return success; |
| 5710 | } finally { |
| 5711 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5712 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5716 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5717 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5718 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5719 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5720 | if (DBG) { |
| 5721 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5722 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5723 | + p3 + " data=" + data); |
| 5724 | } |
| 5725 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5726 | command, p1, p2, p3, data); |
| 5727 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5728 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5729 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5730 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5731 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5732 | enforceModifyPermission(); |
| 5733 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5734 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5735 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5736 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5737 | } |
| 5738 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5739 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5740 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5744 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | final long identity = Binder.clearCallingIdentity(); |
| 5746 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5747 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5748 | return ""; |
| 5749 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5752 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5753 | null /* workSource */); |
| 5754 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5755 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5756 | // Append the returned status code to the end of the response payload. |
| 5757 | String s = Integer.toHexString( |
| 5758 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5759 | if (response.payload != null) { |
| 5760 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5761 | } |
| 5762 | return s; |
| 5763 | } finally { |
| 5764 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5765 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5766 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5767 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5768 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5769 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5770 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5771 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5772 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5773 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5774 | if (DBG) { |
| 5775 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5776 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5777 | } |
| 5778 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5779 | cla, command, p1, p2, p3, data); |
| 5780 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5781 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5782 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5783 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5784 | 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] | 5785 | enforceModifyPermission(); |
| 5786 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5787 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5788 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5789 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5790 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5794 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5795 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5799 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5800 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5801 | final long identity = Binder.clearCallingIdentity(); |
| 5802 | try { |
| 5803 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5804 | && TextUtils.equals(ISDR_AID, data)) { |
| 5805 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5806 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5807 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5808 | if (bestComponent == null |
| 5809 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5810 | loge("The calling package is not allowed to select ISD-R."); |
| 5811 | throw new SecurityException( |
| 5812 | "The calling package is not allowed to select ISD-R."); |
| 5813 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5814 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5815 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5816 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5817 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5818 | null /* workSource */); |
| 5819 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5820 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5821 | // Append the returned status code to the end of the response payload. |
| 5822 | String s = Integer.toHexString( |
| 5823 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5824 | if (response.payload != null) { |
| 5825 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5826 | } |
| 5827 | return s; |
| 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5830 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5834 | 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] | 5835 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5836 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5837 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | final long identity = Binder.clearCallingIdentity(); |
| 5840 | try { |
| 5841 | if (DBG) { |
| 5842 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5843 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5844 | } |
| 5845 | |
| 5846 | IccIoResult response = |
| 5847 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5848 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5849 | subId); |
| 5850 | |
| 5851 | if (DBG) { |
| 5852 | log("Exchange SIM_IO [R]" + response); |
| 5853 | } |
| 5854 | |
| 5855 | byte[] result = null; |
| 5856 | int length = 2; |
| 5857 | if (response.payload != null) { |
| 5858 | length = 2 + response.payload.length; |
| 5859 | result = new byte[length]; |
| 5860 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5861 | } else { |
| 5862 | result = new byte[length]; |
| 5863 | } |
| 5864 | |
| 5865 | result[length - 1] = (byte) response.sw2; |
| 5866 | result[length - 2] = (byte) response.sw1; |
| 5867 | return result; |
| 5868 | } finally { |
| 5869 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5870 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5871 | } |
| 5872 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5873 | /** |
| 5874 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5875 | * on a particular subscription |
| 5876 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5877 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5878 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5879 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5880 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5881 | return null; |
| 5882 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5883 | |
| 5884 | final long identity = Binder.clearCallingIdentity(); |
| 5885 | try { |
| 5886 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5887 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5888 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5889 | return null; |
| 5890 | } |
| 5891 | Object response = sendRequest( |
| 5892 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5893 | if (response instanceof String[]) { |
| 5894 | return (String[]) response; |
| 5895 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5896 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5898 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5899 | } finally { |
| 5900 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5901 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5902 | } |
| 5903 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5904 | /** |
| 5905 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5906 | * subscription. |
| 5907 | * |
| 5908 | * @param subId the id of the subscription. |
| 5909 | * @param appType the uicc app type, must be USIM or SIM. |
| 5910 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5911 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5912 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5913 | * @return number of fplmns that is successfully written to the SIM. |
| 5914 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5915 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5916 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5917 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5918 | mApp, subId, "setForbiddenPlmns"); |
| 5919 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5920 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5921 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5922 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5923 | } |
| 5924 | if (fplmns == null) { |
| 5925 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5926 | } |
| 5927 | for (String fplmn : fplmns) { |
| 5928 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5929 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5930 | } |
| 5931 | } |
| 5932 | final long identity = Binder.clearCallingIdentity(); |
| 5933 | try { |
| 5934 | Object response = sendRequest( |
| 5935 | CMD_SET_FORBIDDEN_PLMNS, |
| 5936 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5937 | subId); |
| 5938 | return (int) response; |
| 5939 | } finally { |
| 5940 | Binder.restoreCallingIdentity(identity); |
| 5941 | } |
| 5942 | } |
| 5943 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5944 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5945 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5946 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5947 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5948 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
| 5951 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5952 | if (response.payload == null) { |
| 5953 | return ""; |
| 5954 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5955 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5956 | // Append the returned status code to the end of the response payload. |
| 5957 | String s = Integer.toHexString( |
| 5958 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5959 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5960 | return s; |
| 5961 | } finally { |
| 5962 | Binder.restoreCallingIdentity(identity); |
| 5963 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5964 | } |
| 5965 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5966 | /** |
| 5967 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5968 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5969 | * |
| 5970 | * @param itemID the ID of the item to read |
| 5971 | * @return the NV item as a String, or null on error. |
| 5972 | */ |
| 5973 | @Override |
| 5974 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5975 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5977 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5978 | |
| 5979 | final long identity = Binder.clearCallingIdentity(); |
| 5980 | try { |
| 5981 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5982 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5983 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5984 | return value; |
| 5985 | } finally { |
| 5986 | Binder.restoreCallingIdentity(identity); |
| 5987 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | /** |
| 5991 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5992 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5993 | * |
| 5994 | * @param itemID the ID of the item to read |
| 5995 | * @param itemValue the value to write, as a String |
| 5996 | * @return true on success; false on any failure |
| 5997 | */ |
| 5998 | @Override |
| 5999 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6000 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6001 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6002 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6003 | |
| 6004 | final long identity = Binder.clearCallingIdentity(); |
| 6005 | try { |
| 6006 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6007 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6008 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6010 | return success; |
| 6011 | } finally { |
| 6012 | Binder.restoreCallingIdentity(identity); |
| 6013 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | /** |
| 6017 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6018 | * Used for device configuration by some CDMA operators. |
| 6019 | * |
| 6020 | * @param preferredRoamingList byte array containing the new PRL |
| 6021 | * @return true on success; false on any failure |
| 6022 | */ |
| 6023 | @Override |
| 6024 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6026 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | |
| 6028 | final long identity = Binder.clearCallingIdentity(); |
| 6029 | try { |
| 6030 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6031 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6032 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6033 | return success; |
| 6034 | } finally { |
| 6035 | Binder.restoreCallingIdentity(identity); |
| 6036 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6037 | } |
| 6038 | |
| 6039 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6040 | * 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] | 6041 | * Used for device configuration by some CDMA operators. |
| 6042 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6043 | * @param slotIndex - device slot. |
| 6044 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6045 | * @return true on success; false on any failure |
| 6046 | */ |
| 6047 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6048 | public boolean resetModemConfig(int slotIndex) { |
| 6049 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6050 | if (phone != null) { |
| 6051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6052 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6053 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6054 | final long identity = Binder.clearCallingIdentity(); |
| 6055 | try { |
| 6056 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6057 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6058 | return success; |
| 6059 | } finally { |
| 6060 | Binder.restoreCallingIdentity(identity); |
| 6061 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6062 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6063 | return false; |
| 6064 | } |
| 6065 | |
| 6066 | /** |
| 6067 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6068 | * |
| 6069 | * @param slotIndex - device slot. |
| 6070 | * |
| 6071 | * @return true on success; false on any failure |
| 6072 | */ |
| 6073 | @Override |
| 6074 | public boolean rebootModem(int slotIndex) { |
| 6075 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6076 | if (phone != null) { |
| 6077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6078 | mApp, phone.getSubId(), "rebootModem"); |
| 6079 | |
| 6080 | final long identity = Binder.clearCallingIdentity(); |
| 6081 | try { |
| 6082 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6083 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6084 | return success; |
| 6085 | } finally { |
| 6086 | Binder.restoreCallingIdentity(identity); |
| 6087 | } |
| 6088 | } |
| 6089 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6090 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6091 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6092 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6093 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6094 | * {@link #disableIms(int)}. |
| 6095 | * @param slotIndex device slot. |
| 6096 | */ |
| 6097 | public void resetIms(int slotIndex) { |
| 6098 | enforceModifyPermission(); |
| 6099 | |
| 6100 | final long identity = Binder.clearCallingIdentity(); |
| 6101 | try { |
| 6102 | if (mImsResolver == null) { |
| 6103 | // may happen if the does not support IMS. |
| 6104 | return; |
| 6105 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6106 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6107 | } finally { |
| 6108 | Binder.restoreCallingIdentity(identity); |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6113 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6114 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6115 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6116 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6117 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6118 | |
| 6119 | final long identity = Binder.clearCallingIdentity(); |
| 6120 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6121 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6122 | // may happen if the device does not support IMS. |
| 6123 | return; |
| 6124 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6125 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6126 | } finally { |
| 6127 | Binder.restoreCallingIdentity(identity); |
| 6128 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6132 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6133 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6134 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6135 | public void disableIms(int slotId) { |
| 6136 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | |
| 6138 | final long identity = Binder.clearCallingIdentity(); |
| 6139 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6140 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6141 | // may happen if the device does not support IMS. |
| 6142 | return; |
| 6143 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6144 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | } finally { |
| 6146 | Binder.restoreCallingIdentity(identity); |
| 6147 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6151 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6152 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6153 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6154 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6155 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6156 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | |
| 6158 | final long identity = Binder.clearCallingIdentity(); |
| 6159 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6160 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6161 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6162 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6163 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6164 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
| 6167 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6168 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6169 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6170 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6171 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6172 | @Override |
| 6173 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6174 | enforceModifyPermission(); |
| 6175 | |
| 6176 | final long identity = Binder.clearCallingIdentity(); |
| 6177 | try { |
| 6178 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6179 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6180 | } finally { |
| 6181 | Binder.restoreCallingIdentity(identity); |
| 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6186 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6187 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6188 | */ |
| 6189 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6190 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6191 | |
| 6192 | final long identity = Binder.clearCallingIdentity(); |
| 6193 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6194 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6195 | // may happen if the device does not support IMS. |
| 6196 | return null; |
| 6197 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6198 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6199 | } finally { |
| 6200 | Binder.restoreCallingIdentity(identity); |
| 6201 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6202 | } |
| 6203 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6204 | /** |
| 6205 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6206 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6207 | */ |
| 6208 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6209 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6210 | |
| 6211 | final long identity = Binder.clearCallingIdentity(); |
| 6212 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6213 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6214 | // may happen if the device does not support IMS. |
| 6215 | return null; |
| 6216 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6217 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6218 | } finally { |
| 6219 | Binder.restoreCallingIdentity(identity); |
| 6220 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6221 | } |
| 6222 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6223 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6224 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6225 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6226 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6227 | * @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] | 6228 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6229 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6230 | * @param packageName The name of the package that the current configuration will be replaced |
| 6231 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6232 | * @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] | 6233 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6234 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6235 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6236 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6237 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6238 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6239 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6240 | final long identity = Binder.clearCallingIdentity(); |
| 6241 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6242 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6243 | // may happen if the device does not support IMS. |
| 6244 | return false; |
| 6245 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6246 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6247 | for (int featureType : featureTypes) { |
| 6248 | featureConfig.put(featureType, packageName); |
| 6249 | } |
| 6250 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6251 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6252 | } finally { |
| 6253 | Binder.restoreCallingIdentity(identity); |
| 6254 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6255 | } |
| 6256 | |
| 6257 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6258 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6259 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6260 | * |
| 6261 | * This should only be used for testing. |
| 6262 | * |
| 6263 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6264 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6265 | */ |
| 6266 | @Override |
| 6267 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6268 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6269 | "clearCarrierImsServiceOverride"); |
| 6270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6271 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6272 | |
| 6273 | final long identity = Binder.clearCallingIdentity(); |
| 6274 | try { |
| 6275 | if (mImsResolver == null) { |
| 6276 | // may happen if the device does not support IMS. |
| 6277 | return false; |
| 6278 | } |
| 6279 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6280 | } finally { |
| 6281 | Binder.restoreCallingIdentity(identity); |
| 6282 | } |
| 6283 | } |
| 6284 | |
| 6285 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6286 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6287 | * |
| 6288 | * @param slotId The slot that the ImsService is associated with. |
| 6289 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6290 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6291 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6292 | * @return the package name of the ImsService configuration. |
| 6293 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6294 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6295 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6296 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6297 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6298 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6299 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6300 | final long identity = Binder.clearCallingIdentity(); |
| 6301 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6302 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6303 | // may happen if the device does not support IMS. |
| 6304 | return ""; |
| 6305 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6306 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6307 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6308 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6309 | } finally { |
| 6310 | Binder.restoreCallingIdentity(identity); |
| 6311 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6312 | } |
| 6313 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6314 | /** |
| 6315 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6316 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6317 | * @param callback A callback with an integer containing the |
| 6318 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6319 | */ |
| 6320 | @Override |
| 6321 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6322 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6323 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6324 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6325 | "IMS not available on device."); |
| 6326 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6327 | final long token = Binder.clearCallingIdentity(); |
| 6328 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6329 | int slotId = getSlotIndex(subId); |
| 6330 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6331 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6332 | + subId + "'"); |
| 6333 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6334 | } |
| 6335 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6336 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6337 | try { |
| 6338 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6339 | } catch (RemoteException e) { |
| 6340 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6341 | + "Ignore"); |
| 6342 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6343 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6344 | } catch (ImsException e) { |
| 6345 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(token); |
| 6348 | } |
| 6349 | } |
| 6350 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6351 | /** |
| 6352 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6353 | */ |
| 6354 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6355 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6356 | |
| 6357 | final long identity = Binder.clearCallingIdentity(); |
| 6358 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6359 | // NOTE: Before S, this method only set the default phone. |
| 6360 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6361 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6362 | phone.setImsRegistrationState(registered); |
| 6363 | } |
| 6364 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | } finally { |
| 6366 | Binder.restoreCallingIdentity(identity); |
| 6367 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6368 | } |
| 6369 | |
| 6370 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6371 | * Set the network selection mode to automatic. |
| 6372 | * |
| 6373 | */ |
| 6374 | @Override |
| 6375 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6377 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6378 | |
| 6379 | final long identity = Binder.clearCallingIdentity(); |
| 6380 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6381 | if (!isActiveSubscription(subId)) { |
| 6382 | return; |
| 6383 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6384 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6385 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6386 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6387 | } finally { |
| 6388 | Binder.restoreCallingIdentity(identity); |
| 6389 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6390 | } |
| 6391 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6392 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6393 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6394 | * |
| 6395 | * @param subId the id of the subscription. |
| 6396 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6397 | * the operator to attach to. |
| 6398 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6399 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6400 | * normal network selection next time. |
| 6401 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6402 | */ |
| 6403 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6404 | public boolean setNetworkSelectionModeManual( |
| 6405 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6407 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6408 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6409 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6410 | if (!isActiveSubscription(subId)) { |
| 6411 | return false; |
| 6412 | } |
| 6413 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6415 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6416 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6417 | if (DBG) { |
| 6418 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6419 | + " operator: " + operatorInfo); |
| 6420 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6422 | } finally { |
| 6423 | Binder.restoreCallingIdentity(identity); |
| 6424 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6425 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6426 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6427 | * Get the manual network selection |
| 6428 | * |
| 6429 | * @param subId the id of the subscription. |
| 6430 | * |
| 6431 | * @return the previously saved user selected PLMN |
| 6432 | */ |
| 6433 | @Override |
| 6434 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6435 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6436 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6437 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6438 | |
| 6439 | final long identity = Binder.clearCallingIdentity(); |
| 6440 | try { |
| 6441 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6442 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | final Phone phone = getPhone(subId); |
| 6446 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6447 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6448 | } |
| 6449 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6450 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6451 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6452 | } finally { |
| 6453 | Binder.restoreCallingIdentity(identity); |
| 6454 | } |
| 6455 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6456 | |
| 6457 | /** |
| 6458 | * Scans for available networks. |
| 6459 | */ |
| 6460 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6461 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6462 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6463 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6464 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6465 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6466 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6467 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6468 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6469 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6470 | .setCallingPid(Binder.getCallingPid()) |
| 6471 | .setCallingUid(Binder.getCallingUid()) |
| 6472 | .setMethod("getCellNetworkScanResults") |
| 6473 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6474 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6475 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6476 | .build()); |
| 6477 | switch (locationResult) { |
| 6478 | case DENIED_HARD: |
| 6479 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6480 | case DENIED_SOFT: |
| 6481 | return null; |
| 6482 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6483 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6484 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6485 | try { |
| 6486 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6487 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6488 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6489 | } finally { |
| 6490 | Binder.restoreCallingIdentity(identity); |
| 6491 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6492 | } |
| 6493 | |
| 6494 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6495 | * Get the call forwarding info, given the call forwarding reason. |
| 6496 | */ |
| 6497 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6498 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6499 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6500 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6501 | long identity = Binder.clearCallingIdentity(); |
| 6502 | try { |
| 6503 | if (DBG) { |
| 6504 | log("getCallForwarding: subId " + subId |
| 6505 | + " callForwardingReason" + callForwardingReason); |
| 6506 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6507 | |
| 6508 | Phone phone = getPhone(subId); |
| 6509 | if (phone == null) { |
| 6510 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6511 | callback.onError( |
| 6512 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6513 | } catch (RemoteException e) { |
| 6514 | // ignore |
| 6515 | } |
| 6516 | return; |
| 6517 | } |
| 6518 | |
| 6519 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6520 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6521 | @Override |
| 6522 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6523 | try { |
| 6524 | callback.onCallForwardingInfoAvailable(info); |
| 6525 | } catch (RemoteException e) { |
| 6526 | // ignore |
| 6527 | } |
| 6528 | } |
| 6529 | |
| 6530 | @Override |
| 6531 | public void onError(int error) { |
| 6532 | try { |
| 6533 | callback.onError(error); |
| 6534 | } catch (RemoteException e) { |
| 6535 | // ignore |
| 6536 | } |
| 6537 | } |
| 6538 | }); |
| 6539 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6540 | } finally { |
| 6541 | Binder.restoreCallingIdentity(identity); |
| 6542 | } |
| 6543 | } |
| 6544 | |
| 6545 | /** |
| 6546 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6547 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6548 | */ |
| 6549 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6550 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6551 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6552 | enforceModifyPermission(); |
| 6553 | long identity = Binder.clearCallingIdentity(); |
| 6554 | try { |
| 6555 | if (DBG) { |
| 6556 | log("setCallForwarding: subId " + subId |
| 6557 | + " callForwardingInfo" + callForwardingInfo); |
| 6558 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6559 | |
| 6560 | Phone phone = getPhone(subId); |
| 6561 | if (phone == null) { |
| 6562 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6563 | callback.accept( |
| 6564 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6565 | } catch (RemoteException e) { |
| 6566 | // ignore |
| 6567 | } |
| 6568 | return; |
| 6569 | } |
| 6570 | |
| 6571 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6572 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6573 | |
| 6574 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6575 | } finally { |
| 6576 | Binder.restoreCallingIdentity(identity); |
| 6577 | } |
| 6578 | } |
| 6579 | |
| 6580 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6581 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6582 | */ |
| 6583 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6584 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6585 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6586 | long identity = Binder.clearCallingIdentity(); |
| 6587 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6588 | Phone phone = getPhone(subId); |
| 6589 | if (phone == null) { |
| 6590 | try { |
| 6591 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6592 | } catch (RemoteException e) { |
| 6593 | // ignore |
| 6594 | } |
| 6595 | return; |
| 6596 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6597 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6598 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6599 | boolean requireUssd = c.getBoolean( |
| 6600 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6601 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6602 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6603 | if (requireUssd) { |
| 6604 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6605 | getSubscriptionCarrierId(subId)); |
| 6606 | String newUssdCommand = ""; |
| 6607 | try { |
| 6608 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6609 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6610 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6611 | } catch (NullPointerException e) { |
| 6612 | loge("Failed to generate USSD number" + e); |
| 6613 | } |
| 6614 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6615 | mMainThreadHandler, callback, carrierXmlParser, |
| 6616 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6617 | final String ussdCommand = newUssdCommand; |
| 6618 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6619 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6620 | }); |
| 6621 | } else { |
| 6622 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6623 | callback::accept); |
| 6624 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6625 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6626 | } finally { |
| 6627 | Binder.restoreCallingIdentity(identity); |
| 6628 | } |
| 6629 | } |
| 6630 | |
| 6631 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6632 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6633 | */ |
| 6634 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6635 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6636 | enforceModifyPermission(); |
| 6637 | long identity = Binder.clearCallingIdentity(); |
| 6638 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6639 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6640 | |
| 6641 | Phone phone = getPhone(subId); |
| 6642 | if (phone == null) { |
| 6643 | try { |
| 6644 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6645 | } catch (RemoteException e) { |
| 6646 | // ignore |
| 6647 | } |
| 6648 | return; |
| 6649 | } |
| 6650 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6651 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6652 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6653 | boolean requireUssd = c.getBoolean( |
| 6654 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6655 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6656 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6657 | if (requireUssd) { |
| 6658 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6659 | getSubscriptionCarrierId(subId)); |
| 6660 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6661 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6662 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6663 | String newUssdCommand = ""; |
| 6664 | try { |
| 6665 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6666 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6667 | .makeCommand(ssAction, null); |
| 6668 | } catch (NullPointerException e) { |
| 6669 | loge("Failed to generate USSD number" + e); |
| 6670 | } |
| 6671 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6672 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6673 | final String ussdCommand = newUssdCommand; |
| 6674 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6675 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6676 | }); |
| 6677 | } else { |
| 6678 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6679 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6680 | |
| 6681 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6682 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6683 | } finally { |
| 6684 | Binder.restoreCallingIdentity(identity); |
| 6685 | } |
| 6686 | } |
| 6687 | |
| 6688 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6689 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6690 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6691 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6692 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6693 | * location related information which will be sent if the caller already possess |
| 6694 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6695 | * @param request contains the radio access networks with bands/channels to scan |
| 6696 | * @param messenger callback messenger for scan results or errors |
| 6697 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6698 | * @return the id of the requested scan which can be used to stop the scan. |
| 6699 | */ |
| 6700 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6701 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6702 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6703 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6704 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6705 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6706 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6707 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6708 | if (!renounceFineLocationAccess) { |
| 6709 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6710 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6711 | .setCallingPackage(callingPackage) |
| 6712 | .setCallingFeatureId(callingFeatureId) |
| 6713 | .setCallingPid(Binder.getCallingPid()) |
| 6714 | .setCallingUid(Binder.getCallingUid()) |
| 6715 | .setMethod("requestNetworkScan") |
| 6716 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6717 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6718 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6719 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6720 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6721 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6722 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6723 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6724 | if (e != null) { |
| 6725 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6726 | throw e; |
| 6727 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6728 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6729 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6730 | } |
| 6731 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6733 | int callingUid = Binder.getCallingUid(); |
| 6734 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6735 | final long identity = Binder.clearCallingIdentity(); |
| 6736 | try { |
| 6737 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6738 | renounceFineLocationAccess, request, messenger, binder, |
| 6739 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6740 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6741 | } finally { |
| 6742 | Binder.restoreCallingIdentity(identity); |
| 6743 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6744 | } |
| 6745 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6746 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6747 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6748 | boolean hasCarrierPriv; |
| 6749 | final long identity = Binder.clearCallingIdentity(); |
| 6750 | try { |
| 6751 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6752 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6753 | } finally { |
| 6754 | Binder.restoreCallingIdentity(identity); |
| 6755 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6756 | boolean hasNetworkScanPermission = |
| 6757 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6758 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6759 | |
| 6760 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6761 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6762 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6766 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6767 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6768 | return new SecurityException("Specific channels must not be" |
| 6769 | + " scanned without location access."); |
| 6770 | } |
| 6771 | } |
| 6772 | } |
| 6773 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6774 | return null; |
| 6775 | } |
| 6776 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6777 | /** |
| 6778 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6779 | * |
| 6780 | * @param subId id of the subscription |
| 6781 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6782 | */ |
| 6783 | @Override |
| 6784 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6786 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6787 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6788 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | final long identity = Binder.clearCallingIdentity(); |
| 6790 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6791 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(identity); |
| 6794 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6795 | } |
| 6796 | |
| 6797 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6798 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6799 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6800 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6801 | */ |
| 6802 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6803 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6804 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6805 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6806 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6807 | |
| 6808 | final long identity = Binder.clearCallingIdentity(); |
| 6809 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6810 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6811 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6812 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6813 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6814 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6815 | } finally { |
| 6816 | Binder.restoreCallingIdentity(identity); |
| 6817 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6818 | } |
| 6819 | |
| 6820 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6821 | * Get the allowed network types for certain reason. |
| 6822 | * |
| 6823 | * @param subId the id of the subscription. |
| 6824 | * @param reason the reason the allowed network type change is taking place |
| 6825 | * @return the allowed network types. |
| 6826 | */ |
| 6827 | @Override |
| 6828 | public long getAllowedNetworkTypesForReason(int subId, |
| 6829 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6830 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6831 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6832 | final long identity = Binder.clearCallingIdentity(); |
| 6833 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6834 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6835 | } finally { |
| 6836 | Binder.restoreCallingIdentity(identity); |
| 6837 | } |
| 6838 | } |
| 6839 | |
| 6840 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6841 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6842 | * @param subId subscription id of the sim card |
| 6843 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6844 | * This can be passed following states |
| 6845 | * <ol> |
| 6846 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6847 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6848 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6849 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6850 | * </ol> |
| 6851 | * @return operation result. |
| 6852 | */ |
| 6853 | @Override |
| 6854 | public int setNrDualConnectivityState(int subId, |
| 6855 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6856 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6857 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6858 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6859 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6860 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6861 | } |
| 6862 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6863 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6864 | final long identity = Binder.clearCallingIdentity(); |
| 6865 | try { |
| 6866 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6867 | nrDualConnectivityState, subId, |
| 6868 | workSource); |
| 6869 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6870 | return result; |
| 6871 | } finally { |
| 6872 | Binder.restoreCallingIdentity(identity); |
| 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | /** |
| 6877 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6878 | * @return true if dual connectivity is enabled else false |
| 6879 | */ |
| 6880 | @Override |
| 6881 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6882 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6883 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6884 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6885 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6886 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6887 | return false; |
| 6888 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6889 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6890 | final long identity = Binder.clearCallingIdentity(); |
| 6891 | try { |
| 6892 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6893 | null, subId, workSource); |
| 6894 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6895 | return isEnabled; |
| 6896 | } finally { |
| 6897 | Binder.restoreCallingIdentity(identity); |
| 6898 | } |
| 6899 | } |
| 6900 | |
| 6901 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6902 | * Set the allowed network types of the device and |
| 6903 | * provide the reason triggering the allowed network change. |
| 6904 | * |
| 6905 | * @param subId the id of the subscription. |
| 6906 | * @param reason the reason the allowed network type change is taking place |
| 6907 | * @param allowedNetworkTypes the allowed network types. |
| 6908 | * @return true on success; false on any failure. |
| 6909 | */ |
| 6910 | @Override |
| 6911 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6912 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6913 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6914 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6915 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6916 | // If the caller only has carrier privileges, then they should not be able to override |
| 6917 | // any network types which were set for security reasons. |
| 6918 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6919 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6920 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6921 | throw new SecurityException( |
| 6922 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6923 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6924 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6925 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6926 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6927 | return false; |
| 6928 | } |
| 6929 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6930 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6931 | return false; |
| 6932 | } |
| 6933 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6934 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6935 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6936 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6937 | Phone phone = getPhone(subId); |
| 6938 | if (phone == null) { |
| 6939 | return false; |
| 6940 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6941 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6942 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6943 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6944 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6945 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6946 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6947 | final long identity = Binder.clearCallingIdentity(); |
| 6948 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6949 | Boolean success = (Boolean) sendRequest( |
| 6950 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6951 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6952 | |
| 6953 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6954 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6955 | } finally { |
| 6956 | Binder.restoreCallingIdentity(identity); |
| 6957 | } |
| 6958 | } |
| 6959 | |
| 6960 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6961 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6962 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6963 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6964 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6965 | * @hide |
| 6966 | */ |
| 6967 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6968 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6969 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6970 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6971 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6972 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6973 | if (phone != null) { |
| 6974 | return phone.hasMatchedTetherApnSetting(); |
| 6975 | } else { |
| 6976 | return false; |
| 6977 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6978 | } finally { |
| 6979 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6980 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6981 | } |
| 6982 | |
| 6983 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6984 | * Get the user enabled state of Mobile Data. |
| 6985 | * |
| 6986 | * TODO: remove and use isUserDataEnabled. |
| 6987 | * This can't be removed now because some vendor codes |
| 6988 | * calls through ITelephony directly while they should |
| 6989 | * use TelephonyManager. |
| 6990 | * |
| 6991 | * @return true on enabled |
| 6992 | */ |
| 6993 | @Override |
| 6994 | public boolean getDataEnabled(int subId) { |
| 6995 | return isUserDataEnabled(subId); |
| 6996 | } |
| 6997 | |
| 6998 | /** |
| 6999 | * Get whether mobile data is enabled per user setting. |
| 7000 | * |
| 7001 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7002 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7003 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7004 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7005 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7006 | * |
| 7007 | * @return {@code true} if data is enabled else {@code false} |
| 7008 | */ |
| 7009 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7010 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7011 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7012 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7013 | try { |
| 7014 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7015 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7016 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7017 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7018 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7019 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7020 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7021 | mApp, subId, functionName); |
| 7022 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7023 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7024 | |
| 7025 | final long identity = Binder.clearCallingIdentity(); |
| 7026 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7027 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7028 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7029 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7030 | if (phone != null) { |
| 7031 | boolean retVal = phone.isUserDataEnabled(); |
| 7032 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7033 | return retVal; |
| 7034 | } else { |
| 7035 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7036 | return false; |
| 7037 | } |
| 7038 | } finally { |
| 7039 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7044 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7045 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7046 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7047 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7048 | * @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] | 7049 | */ |
| 7050 | @Override |
| 7051 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7052 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7053 | try { |
| 7054 | try { |
| 7055 | mApp.enforceCallingOrSelfPermission( |
| 7056 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7057 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7058 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7059 | try { |
| 7060 | mApp.enforceCallingOrSelfPermission( |
| 7061 | android.Manifest.permission.READ_PHONE_STATE, |
| 7062 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7063 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7064 | mApp.enforceCallingOrSelfPermission( |
| 7065 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7066 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7067 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7068 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7069 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7070 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7071 | |
| 7072 | final long identity = Binder.clearCallingIdentity(); |
| 7073 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7074 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7076 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7077 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7078 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | return retVal; |
| 7080 | } else { |
| 7081 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7082 | return false; |
| 7083 | } |
| 7084 | } finally { |
| 7085 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7086 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7087 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7088 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7089 | /** |
| 7090 | * Check if data is enabled for a specific reason |
| 7091 | * @param subId Subscription index |
| 7092 | * @param reason the reason the data enable change is taking place |
| 7093 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7094 | */ |
| 7095 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7096 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7097 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7098 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7099 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7100 | try { |
| 7101 | mApp.enforceCallingOrSelfPermission( |
| 7102 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7103 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7104 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7105 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7106 | functionName); |
| 7107 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7108 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7109 | try { |
| 7110 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7111 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7112 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7114 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7115 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7116 | } |
| 7117 | |
| 7118 | |
| 7119 | final long identity = Binder.clearCallingIdentity(); |
| 7120 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7121 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7122 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7123 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7124 | + " reason=" + reason); |
| 7125 | } |
| 7126 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7127 | if (phone != null) { |
| 7128 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7129 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7130 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7131 | return retVal; |
| 7132 | } else { |
| 7133 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7134 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7135 | + subId + " retVal=false"); |
| 7136 | } |
| 7137 | return false; |
| 7138 | } |
| 7139 | } finally { |
| 7140 | Binder.restoreCallingIdentity(identity); |
| 7141 | } |
| 7142 | } |
| 7143 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7144 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7145 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7146 | // No permission needed; this only lets the caller inspect their own status. |
| 7147 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7148 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7149 | |
| 7150 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7151 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7152 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7153 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7154 | } |
| 7155 | |
| 7156 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7157 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7158 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7159 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7160 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7161 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7162 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7163 | if (cpt == null) { |
| 7164 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7165 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7166 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7167 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7171 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7172 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7173 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7174 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7175 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7176 | Phone phone = getPhone(subId); |
| 7177 | if (phone == null) { |
| 7178 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7179 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7180 | } |
| 7181 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7182 | if (cpt == null) { |
| 7183 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7184 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7185 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7186 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7187 | } |
| 7188 | |
| 7189 | @Override |
| 7190 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7191 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7192 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7193 | } |
| 7194 | |
| 7195 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7196 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7197 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7198 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7199 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7200 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7201 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7202 | if (phone == null) { |
| 7203 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7204 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7205 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7206 | if (cpt == null) { |
| 7207 | continue; |
| 7208 | } |
| 7209 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7210 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7211 | break; |
| 7212 | } |
| 7213 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7214 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7215 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7216 | |
| 7217 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7218 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7219 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7220 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7221 | if (phone == null) { |
| 7222 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7223 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7224 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7225 | if (cpt == null) { |
| 7226 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7227 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7228 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7229 | } |
| 7230 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7231 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7232 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7233 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7234 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7235 | if (phone == null) { |
| 7236 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7237 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7238 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7239 | if (cpt == null) { |
| 7240 | return Collections.emptyList(); |
| 7241 | } |
| 7242 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7243 | } |
| 7244 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7245 | @Override |
| 7246 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7247 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7248 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7249 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7250 | try { |
| 7251 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7252 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7253 | } |
| 7254 | } finally { |
| 7255 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7256 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7257 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7258 | } |
| 7259 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7260 | @Override |
| 7261 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7262 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7263 | |
| 7264 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7265 | if (phone == null) { |
| 7266 | return null; |
| 7267 | } |
| 7268 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7269 | if (cpt == null) { |
| 7270 | return null; |
| 7271 | } |
| 7272 | return cpt.getCarrierServicePackageName(); |
| 7273 | } |
| 7274 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7275 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7276 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7277 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7278 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7279 | return null; |
| 7280 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7281 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7282 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7283 | return null; |
| 7284 | } |
| 7285 | return iccId; |
| 7286 | } |
| 7287 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7288 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7289 | public void setCallComposerStatus(int subId, int status) { |
| 7290 | enforceModifyPermission(); |
| 7291 | |
| 7292 | final long identity = Binder.clearCallingIdentity(); |
| 7293 | try { |
| 7294 | Phone phone = getPhone(subId); |
| 7295 | if (phone != null) { |
| 7296 | Phone defaultPhone = phone.getImsPhone(); |
| 7297 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7298 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7299 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7300 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7301 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7302 | } |
| 7303 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7304 | } catch (ImsException e) { |
| 7305 | throw new ServiceSpecificException(e.getCode()); |
| 7306 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7307 | Binder.restoreCallingIdentity(identity); |
| 7308 | } |
| 7309 | } |
| 7310 | |
| 7311 | @Override |
| 7312 | public int getCallComposerStatus(int subId) { |
| 7313 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7314 | |
| 7315 | final long identity = Binder.clearCallingIdentity(); |
| 7316 | try { |
| 7317 | Phone phone = getPhone(subId); |
| 7318 | if (phone != null) { |
| 7319 | Phone defaultPhone = phone.getImsPhone(); |
| 7320 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7321 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7322 | return imsPhone.getCallComposerStatus(); |
| 7323 | } |
| 7324 | } |
| 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
| 7327 | } |
| 7328 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7329 | } |
| 7330 | |
| 7331 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7332 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7333 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7334 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7335 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7336 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7337 | final long identity = Binder.clearCallingIdentity(); |
| 7338 | try { |
| 7339 | final String iccId = getIccId(subId); |
| 7340 | final Phone phone = getPhone(subId); |
| 7341 | if (phone == null) { |
| 7342 | return false; |
| 7343 | } |
| 7344 | final String subscriberId = phone.getSubscriberId(); |
| 7345 | |
| 7346 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7347 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7348 | + subscriberId + " to " + number); |
| 7349 | } |
| 7350 | |
| 7351 | if (TextUtils.isEmpty(iccId)) { |
| 7352 | return false; |
| 7353 | } |
| 7354 | |
| 7355 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7356 | |
| 7357 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7358 | if (alphaTag == null) { |
| 7359 | editor.remove(alphaTagPrefKey); |
| 7360 | } else { |
| 7361 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7362 | } |
| 7363 | |
| 7364 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7365 | // track all merged IMSIs based on line number |
| 7366 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7367 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7368 | if (number == null) { |
| 7369 | editor.remove(numberPrefKey); |
| 7370 | editor.remove(subscriberPrefKey); |
| 7371 | } else { |
| 7372 | editor.putString(numberPrefKey, number); |
| 7373 | editor.putString(subscriberPrefKey, subscriberId); |
| 7374 | } |
| 7375 | |
| 7376 | editor.commit(); |
| 7377 | return true; |
| 7378 | } finally { |
| 7379 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7380 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7381 | } |
| 7382 | |
| 7383 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7384 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7385 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7386 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7387 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7388 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7389 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7390 | return null; |
| 7391 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7392 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7393 | final long identity = Binder.clearCallingIdentity(); |
| 7394 | try { |
| 7395 | String iccId = getIccId(subId); |
| 7396 | if (iccId != null) { |
| 7397 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7398 | if (DBG_MERGE) { |
| 7399 | log("getLine1NumberForDisplay returning " |
| 7400 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7401 | } |
| 7402 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7403 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7404 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7405 | return null; |
| 7406 | } finally { |
| 7407 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7408 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7409 | } |
| 7410 | |
| 7411 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7412 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7413 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7414 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7415 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7416 | return null; |
| 7417 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7418 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7419 | final long identity = Binder.clearCallingIdentity(); |
| 7420 | try { |
| 7421 | String iccId = getIccId(subId); |
| 7422 | if (iccId != null) { |
| 7423 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7424 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7425 | } |
| 7426 | return null; |
| 7427 | } finally { |
| 7428 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7429 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7430 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7431 | |
| 7432 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7433 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7434 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7435 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7436 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7437 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7438 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7439 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7440 | return null; |
| 7441 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7442 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7443 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7444 | // the process, where TelephonyManager was instantiated. |
| 7445 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7446 | final long identity = Binder.clearCallingIdentity(); |
| 7447 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7448 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7449 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7450 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7451 | |
| 7452 | // Figure out what subscribers are currently active |
| 7453 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7454 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7455 | // Only consider subs which match the current subId |
| 7456 | // This logic can be simplified. See b/131189269 for progress. |
| 7457 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7458 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7459 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7460 | |
| 7461 | // First pass, find a number override for an active subscriber |
| 7462 | String mergeNumber = null; |
| 7463 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7464 | for (String key : prefs.keySet()) { |
| 7465 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7466 | final String subscriberId = (String) prefs.get(key); |
| 7467 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7468 | final String iccId = key.substring( |
| 7469 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7470 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7471 | mergeNumber = (String) prefs.get(numberKey); |
| 7472 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7473 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7474 | + " for active subscriber " + subscriberId); |
| 7475 | } |
| 7476 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7477 | break; |
| 7478 | } |
| 7479 | } |
| 7480 | } |
| 7481 | } |
| 7482 | |
| 7483 | // Shortcut when no active merged subscribers |
| 7484 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7485 | return null; |
| 7486 | } |
| 7487 | |
| 7488 | // Second pass, find all subscribers under that line override |
| 7489 | final ArraySet<String> result = new ArraySet<>(); |
| 7490 | for (String key : prefs.keySet()) { |
| 7491 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7492 | final String number = (String) prefs.get(key); |
| 7493 | if (mergeNumber.equals(number)) { |
| 7494 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7495 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7496 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7497 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7498 | result.add(subscriberId); |
| 7499 | } |
| 7500 | } |
| 7501 | } |
| 7502 | } |
| 7503 | |
| 7504 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7505 | Arrays.sort(resultArray); |
| 7506 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7507 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7508 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7509 | } |
| 7510 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7511 | } finally { |
| 7512 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7513 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7514 | } |
| 7515 | |
| 7516 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7517 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7518 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7519 | |
| 7520 | final long identity = Binder.clearCallingIdentity(); |
| 7521 | try { |
| 7522 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7523 | TelephonyManager.class); |
| 7524 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7525 | if (subscriberId == null) { |
| 7526 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7527 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7528 | + subId); |
| 7529 | } |
| 7530 | return null; |
| 7531 | } |
| 7532 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7533 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7534 | .getSubscriptionInfo(subId); |
| 7535 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7536 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7537 | if (groupUuid == null) { |
| 7538 | return new String[]{subscriberId}; |
| 7539 | } |
| 7540 | |
| 7541 | // Get all subscriberIds from the group. |
| 7542 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7543 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7544 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7545 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7546 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7547 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7548 | if (subscriberId != null) { |
| 7549 | mergedSubscriberIds.add(subscriberId); |
| 7550 | } |
| 7551 | } |
| 7552 | |
| 7553 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7554 | } finally { |
| 7555 | Binder.restoreCallingIdentity(identity); |
| 7556 | |
| 7557 | } |
| 7558 | } |
| 7559 | |
| 7560 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7561 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7562 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7563 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | |
| 7565 | final long identity = Binder.clearCallingIdentity(); |
| 7566 | try { |
| 7567 | final Phone phone = getPhone(subId); |
| 7568 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7569 | } finally { |
| 7570 | Binder.restoreCallingIdentity(identity); |
| 7571 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7572 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7573 | |
| 7574 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7575 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7576 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7577 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7578 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7579 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7580 | |
| 7581 | final long identity = Binder.clearCallingIdentity(); |
| 7582 | try { |
| 7583 | final Phone phone = getPhone(subId); |
| 7584 | if (phone == null) { |
| 7585 | return false; |
| 7586 | } |
| 7587 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7588 | cdmaNonRoamingList); |
| 7589 | } finally { |
| 7590 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7591 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7592 | } |
| 7593 | |
| 7594 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7595 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7596 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7597 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7598 | if (phone == null) { |
| 7599 | return raf; |
| 7600 | } |
| 7601 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7602 | try { |
| 7603 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7604 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7605 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7606 | } catch (SecurityException e) { |
| 7607 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7608 | throw e; |
| 7609 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7611 | final long identity = Binder.clearCallingIdentity(); |
| 7612 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7613 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7614 | } finally { |
| 7615 | Binder.restoreCallingIdentity(identity); |
| 7616 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7617 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7618 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7619 | |
| 7620 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7621 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7622 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7623 | try { |
| 7624 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7625 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7626 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7627 | } |
| 7628 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7629 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7630 | } |
| 7631 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7632 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7633 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7634 | throw new SecurityException("App must be the dialer role holder to" |
| 7635 | + " upload a call composer pic"); |
| 7636 | } |
| 7637 | |
| 7638 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7639 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7640 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7641 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7642 | boolean readUntilEnd = false; |
| 7643 | int totalBytesRead = 0; |
| 7644 | byte[] buffer = new byte[16 * 1024]; |
| 7645 | while (true) { |
| 7646 | int numRead; |
| 7647 | try { |
| 7648 | numRead = input.read(buffer); |
| 7649 | } catch (IOException e) { |
| 7650 | try { |
| 7651 | fd.checkError(); |
| 7652 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7653 | null); |
| 7654 | } catch (IOException e1) { |
| 7655 | // This means that the other side closed explicitly with an error. If this |
| 7656 | // happens, log and ignore. |
| 7657 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7658 | } |
| 7659 | break; |
| 7660 | } |
| 7661 | if (numRead == -1) { |
| 7662 | readUntilEnd = true; |
| 7663 | break; |
| 7664 | } |
| 7665 | totalBytesRead += numRead; |
| 7666 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7667 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7668 | try { |
| 7669 | input.close(); |
| 7670 | } catch (IOException e) { |
| 7671 | // ignore |
| 7672 | } |
| 7673 | break; |
| 7674 | } |
| 7675 | output.write(buffer, 0, numRead); |
| 7676 | } |
| 7677 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7678 | // close is above, where the picture size is too big. |
| 7679 | |
| 7680 | try { |
| 7681 | fd.checkError(); |
| 7682 | } catch (IOException e) { |
| 7683 | loge("Remote end for call composer closed with an error: " + e); |
| 7684 | return; |
| 7685 | } |
| 7686 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7687 | if (!readUntilEnd) { |
| 7688 | loge("Did not finish reading entire image; aborting"); |
| 7689 | return; |
| 7690 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7691 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7692 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7693 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7694 | new CallComposerPictureTransfer.Factory() {}, |
| 7695 | imageData, |
| 7696 | (result) -> { |
| 7697 | if (result.first != null) { |
| 7698 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7699 | Bundle outputResult = new Bundle(); |
| 7700 | outputResult.putParcelable( |
| 7701 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7702 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7703 | outputResult); |
| 7704 | } else { |
| 7705 | callback.send(result.second, null); |
| 7706 | } |
| 7707 | } |
| 7708 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7709 | }); |
| 7710 | } |
| 7711 | |
| 7712 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7713 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7714 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7715 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7716 | |
| 7717 | final long identity = Binder.clearCallingIdentity(); |
| 7718 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7719 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7720 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7721 | } finally { |
| 7722 | Binder.restoreCallingIdentity(identity); |
| 7723 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7724 | } |
| 7725 | |
| 7726 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7727 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7728 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7729 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7730 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7731 | return false; |
| 7732 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7733 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7734 | final long identity = Binder.clearCallingIdentity(); |
| 7735 | try { |
| 7736 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7737 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7738 | // In the long run, we may instead need to check if there exists a connection service |
| 7739 | // which can support video calling. |
| 7740 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7741 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | return imsManager.isVtEnabledByPlatform() |
| 7743 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7744 | && imsManager.isVtEnabledByUser(); |
| 7745 | } finally { |
| 7746 | Binder.restoreCallingIdentity(identity); |
| 7747 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7748 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7749 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7750 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7751 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7752 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7753 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7754 | mApp, subId, callingPackage, callingFeatureId, |
| 7755 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7756 | return false; |
| 7757 | } |
| 7758 | |
| 7759 | final long identity = Binder.clearCallingIdentity(); |
| 7760 | try { |
| 7761 | CarrierConfigManager configManager = |
| 7762 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7763 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7764 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7765 | } finally { |
| 7766 | Binder.restoreCallingIdentity(identity); |
| 7767 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7768 | } |
| 7769 | |
| 7770 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7771 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7773 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7774 | return false; |
| 7775 | } |
| 7776 | |
| 7777 | final long identity = Binder.clearCallingIdentity(); |
| 7778 | try { |
| 7779 | CarrierConfigManager configManager = |
| 7780 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7781 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7782 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7783 | } finally { |
| 7784 | Binder.restoreCallingIdentity(identity); |
| 7785 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7786 | } |
| 7787 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7788 | @Override |
| 7789 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7790 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7791 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7792 | } |
| 7793 | |
| 7794 | @Override |
| 7795 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7796 | final long identity = Binder.clearCallingIdentity(); |
| 7797 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7798 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7799 | } finally { |
| 7800 | Binder.restoreCallingIdentity(identity); |
| 7801 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7802 | } |
| 7803 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7804 | /** |
| 7805 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7806 | * support for the feature and device firmware support. |
| 7807 | * |
| 7808 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7809 | */ |
| 7810 | @Override |
| 7811 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7812 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7813 | final Phone phone = getPhone(subscriptionId); |
| 7814 | if (phone == null) { |
| 7815 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7816 | return false; |
| 7817 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7818 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7819 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7821 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7822 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7823 | return isCarrierSupported && isDeviceSupported; |
| 7824 | } finally { |
| 7825 | Binder.restoreCallingIdentity(identity); |
| 7826 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7827 | } |
| 7828 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7829 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7830 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7831 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7832 | * 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] | 7833 | */ |
| 7834 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7835 | final long identity = Binder.clearCallingIdentity(); |
| 7836 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7837 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7838 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7839 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7840 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7841 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7842 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7843 | } finally { |
| 7844 | Binder.restoreCallingIdentity(identity); |
| 7845 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7846 | } |
| 7847 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7848 | @Deprecated |
| 7849 | @Override |
| 7850 | public String getDeviceId(String callingPackage) { |
| 7851 | return getDeviceIdWithFeature(callingPackage, null); |
| 7852 | } |
| 7853 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7854 | /** |
| 7855 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7856 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7857 | * |
| 7858 | * <p>Requires Permission: |
| 7859 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7860 | */ |
| 7861 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7862 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7863 | try { |
| 7864 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7865 | } catch (SecurityException se) { |
| 7866 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7867 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7868 | + Binder.getCallingUid()); |
| 7869 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7870 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7871 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7872 | return null; |
| 7873 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7874 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7875 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7876 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7877 | return null; |
| 7878 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7879 | |
| 7880 | final long identity = Binder.clearCallingIdentity(); |
| 7881 | try { |
| 7882 | return phone.getDeviceId(); |
| 7883 | } finally { |
| 7884 | Binder.restoreCallingIdentity(identity); |
| 7885 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7886 | } |
| 7887 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7888 | /** |
| 7889 | * {@hide} |
| 7890 | * Returns the IMS Registration Status on a particular subid |
| 7891 | * |
| 7892 | * @param subId |
| 7893 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7894 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7895 | Phone phone = getPhone(subId); |
| 7896 | if (phone != null) { |
| 7897 | return phone.isImsRegistered(); |
| 7898 | } else { |
| 7899 | return false; |
| 7900 | } |
| 7901 | } |
| 7902 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7903 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7904 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7905 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7906 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7907 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7908 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7909 | } |
| 7910 | final long identity = Binder.clearCallingIdentity(); |
| 7911 | try { |
| 7912 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7913 | } finally { |
| 7914 | Binder.restoreCallingIdentity(identity); |
| 7915 | } |
| 7916 | } |
| 7917 | |
| 7918 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7919 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7920 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7921 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7922 | mApp, |
| 7923 | subscriptionId, |
| 7924 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7925 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7926 | final long identity = Binder.clearCallingIdentity(); |
| 7927 | try { |
| 7928 | Phone phone = getPhone(subscriptionId); |
| 7929 | if (phone == null) { |
| 7930 | return null; |
| 7931 | } |
| 7932 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7933 | } finally { |
| 7934 | Binder.restoreCallingIdentity(identity); |
| 7935 | } |
| 7936 | } |
| 7937 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7938 | /** |
| 7939 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7940 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7941 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7942 | final long identity = Binder.clearCallingIdentity(); |
| 7943 | try { |
| 7944 | Phone phone = getPhone(subId); |
| 7945 | if (phone != null) { |
| 7946 | return phone.isWifiCallingEnabled(); |
| 7947 | } else { |
| 7948 | return false; |
| 7949 | } |
| 7950 | } finally { |
| 7951 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7952 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7953 | } |
| 7954 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7955 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7956 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7957 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7958 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7959 | final long identity = Binder.clearCallingIdentity(); |
| 7960 | try { |
| 7961 | Phone phone = getPhone(subId); |
| 7962 | if (phone != null) { |
| 7963 | return phone.isVideoEnabled(); |
| 7964 | } else { |
| 7965 | return false; |
| 7966 | } |
| 7967 | } finally { |
| 7968 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7969 | } |
| 7970 | } |
| 7971 | |
| 7972 | /** |
| 7973 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7974 | * defined in {@link ImsRegistrationImplBase}. |
| 7975 | */ |
| 7976 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7977 | final long identity = Binder.clearCallingIdentity(); |
| 7978 | try { |
| 7979 | Phone phone = getPhone(subId); |
| 7980 | if (phone != null) { |
| 7981 | return phone.getImsRegistrationTech(); |
| 7982 | } else { |
| 7983 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7984 | } |
| 7985 | } finally { |
| 7986 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7987 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7988 | } |
| 7989 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7990 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7991 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7992 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7993 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7994 | return; |
| 7995 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7996 | Phone defaultPhone = getDefaultPhone(); |
| 7997 | if (defaultPhone != null) { |
| 7998 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7999 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8000 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8001 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8002 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8003 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8004 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8005 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8006 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8007 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8008 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8009 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8010 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8011 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8012 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8013 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8014 | // There has been issues when Sms raw table somehow stores orphan |
| 8015 | // fragments. They lead to garbled message when new fragments come |
| 8016 | // in and combined with those stale ones. In case this happens again, |
| 8017 | // user can reset all network settings which will clean up this table. |
| 8018 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8019 | // Clean up IMS settings as well here. |
| 8020 | int slotId = getSlotIndex(subId); |
| 8021 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8022 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8023 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8024 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8025 | if (defaultPhone == null) { |
| 8026 | return; |
| 8027 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8028 | // Erase modem config if erase modem on network setting is enabled. |
| 8029 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8030 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8031 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8032 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8033 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8034 | |
| 8035 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8036 | } finally { |
| 8037 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8038 | } |
| 8039 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8040 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8041 | @VisibleForTesting |
| 8042 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8043 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8044 | return; |
| 8045 | } |
| 8046 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8047 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8048 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8049 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8050 | "user=" + defaultNetworkType); |
| 8051 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8052 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8053 | defaultNetworkType, null); |
| 8054 | } |
| 8055 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8056 | private void cleanUpSmsRawTable(Context context) { |
| 8057 | ContentResolver resolver = context.getContentResolver(); |
| 8058 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8059 | resolver.delete(uri, null, null); |
| 8060 | } |
| 8061 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8062 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8063 | public String getSimLocaleForSubscriber(int subId) { |
| 8064 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8065 | final Phone phone = getPhone(subId); |
| 8066 | if (phone == null) { |
| 8067 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8068 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8070 | final long identity = Binder.clearCallingIdentity(); |
| 8071 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8072 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8073 | phone.getContext().getOpPackageName(), |
| 8074 | phone.getContext().getAttributionTag()); |
| 8075 | if (info == null) { |
| 8076 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8077 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8078 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8079 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8080 | // preferences (EF-PL and EF-LI)... |
| 8081 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8082 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8083 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8084 | if (localeFromDefaultSim != null) { |
| 8085 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8086 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8087 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8088 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8089 | } else { |
| 8090 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8091 | } |
| 8092 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8093 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8094 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8095 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8096 | // the SIM and carrier preferences does not include a country we add the country |
| 8097 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8098 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8099 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8100 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8101 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8102 | } |
| 8103 | |
| 8104 | if (DBG) log("No locale found - returning null"); |
| 8105 | return null; |
| 8106 | } finally { |
| 8107 | Binder.restoreCallingIdentity(identity); |
| 8108 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8109 | } |
| 8110 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8111 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8112 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8113 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8114 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8115 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8116 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8117 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8118 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8119 | return localeTag; |
| 8120 | } |
| 8121 | } |
| 8122 | return inputLocale.toLanguageTag(); |
| 8123 | } |
| 8124 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8125 | /** |
| 8126 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8127 | */ |
| 8128 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8129 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8130 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8131 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8132 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8133 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8134 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8135 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8136 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8137 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8138 | * representing the state of the modem. |
| 8139 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8140 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8141 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8142 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8143 | */ |
| 8144 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8145 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8146 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8147 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8148 | |
| 8149 | final long identity = Binder.clearCallingIdentity(); |
| 8150 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8151 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8152 | } finally { |
| 8153 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8154 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8155 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8156 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8157 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8158 | // less than total activity duration. |
| 8159 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8160 | if (info == null) { |
| 8161 | return false; |
| 8162 | } |
| 8163 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8164 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8165 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8166 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8167 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8168 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8169 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8170 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8171 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8172 | } |
| 8173 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8174 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8175 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8176 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8177 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8178 | |
| 8179 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8180 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8181 | } |
| 8182 | |
| 8183 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8184 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8185 | rat, |
| 8186 | freq, |
| 8187 | info.getReceiveTimeMillis(rat, freq) |
| 8188 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8189 | } |
| 8190 | |
| 8191 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8192 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8193 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8194 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8195 | |
| 8196 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8197 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8198 | } |
| 8199 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8200 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8201 | rat, |
| 8202 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8203 | } |
| 8204 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8205 | /** |
| 8206 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8207 | * @param info recent ModemActivityInfo |
| 8208 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8209 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8210 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8211 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8212 | boolean matched; |
| 8213 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8214 | matched = false; |
| 8215 | int rat = info.getSpecificInfoRat(i); |
| 8216 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8217 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8218 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8219 | //if it already exists |
| 8220 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8221 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8222 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8223 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8224 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8225 | updateLastModemActivityInfo(info, rat, freq); |
| 8226 | matched = true; |
| 8227 | } |
| 8228 | } else { |
| 8229 | updateLastModemActivityInfo(info, rat); |
| 8230 | matched = true; |
| 8231 | } |
| 8232 | } |
| 8233 | } |
| 8234 | |
| 8235 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8236 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8237 | new ActivityStatsTechSpecificInfo( |
| 8238 | rat, |
| 8239 | freq, |
| 8240 | info.getTransmitTimeMillis(rat, freq), |
| 8241 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8242 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8243 | } |
| 8244 | } |
| 8245 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8246 | mLastModemActivitySpecificInfo = |
| 8247 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8248 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8249 | |
| 8250 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8251 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8252 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8253 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8254 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8255 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8256 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8257 | |
| 8258 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8259 | new ModemActivityInfo( |
| 8260 | mLastModemActivityInfo.getTimestampMillis(), |
| 8261 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8262 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8263 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8264 | } |
| 8265 | |
| 8266 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8267 | ActivityStatsTechSpecificInfo[] info) { |
| 8268 | int infoSize = info.length; |
| 8269 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8270 | for (int i = 0; i < infoSize; i++) { |
| 8271 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8272 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8273 | info[i].getTransmitTimeMillis(), |
| 8274 | (int) info[i].getReceiveTimeMillis()); |
| 8275 | } |
| 8276 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8277 | } |
| 8278 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8279 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8280 | * Returns the service state information on specified subscription. |
| 8281 | */ |
| 8282 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8283 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8284 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8285 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8286 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8287 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8288 | return null; |
| 8289 | } |
| 8290 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8291 | boolean hasFinePermission = false; |
| 8292 | boolean hasCoarsePermission = false; |
| 8293 | if (!renounceFineLocationAccess) { |
| 8294 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8295 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8296 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8297 | .setCallingPackage(callingPackage) |
| 8298 | .setCallingFeatureId(callingFeatureId) |
| 8299 | .setCallingPid(Binder.getCallingPid()) |
| 8300 | .setCallingUid(Binder.getCallingUid()) |
| 8301 | .setMethod("getServiceStateForSubscriber") |
| 8302 | .setLogAsInfo(true) |
| 8303 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8304 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8305 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8306 | .build()); |
| 8307 | hasFinePermission = |
| 8308 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8309 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8310 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8311 | if (!renounceCoarseLocationAccess) { |
| 8312 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8313 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8314 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8315 | .setCallingPackage(callingPackage) |
| 8316 | .setCallingFeatureId(callingFeatureId) |
| 8317 | .setCallingPid(Binder.getCallingPid()) |
| 8318 | .setCallingUid(Binder.getCallingUid()) |
| 8319 | .setMethod("getServiceStateForSubscriber") |
| 8320 | .setLogAsInfo(true) |
| 8321 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8322 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8323 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8324 | .build()); |
| 8325 | hasCoarsePermission = |
| 8326 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8327 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8328 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8329 | final Phone phone = getPhone(subId); |
| 8330 | if (phone == null) { |
| 8331 | return null; |
| 8332 | } |
| 8333 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8334 | final long identity = Binder.clearCallingIdentity(); |
| 8335 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8336 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8337 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8338 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8339 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8340 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8341 | .getSubscriptionInfoInternal(subId); |
| 8342 | if (subInfo == null || !subInfo.isActive()) { |
| 8343 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8344 | + "subId=" + subId); |
| 8345 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8346 | } |
| 8347 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8348 | ServiceState ss = phone.getServiceState(); |
| 8349 | |
| 8350 | // Scrub out the location info in ServiceState depending on what level of access |
| 8351 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8352 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8353 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8354 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8355 | } finally { |
| 8356 | Binder.restoreCallingIdentity(identity); |
| 8357 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8358 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8359 | |
| 8360 | /** |
| 8361 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8362 | * |
| 8363 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8364 | * voicemail ringtone. |
| 8365 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8366 | * PhoneAccount. |
| 8367 | */ |
| 8368 | @Override |
| 8369 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8370 | final long identity = Binder.clearCallingIdentity(); |
| 8371 | try { |
| 8372 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8373 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8374 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8375 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8376 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8377 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8378 | } finally { |
| 8379 | Binder.restoreCallingIdentity(identity); |
| 8380 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8381 | } |
| 8382 | |
| 8383 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8384 | * Sets the per-account voicemail ringtone. |
| 8385 | * |
| 8386 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8387 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8388 | * |
| 8389 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8390 | * voicemail ringtone. |
| 8391 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8392 | * PhoneAccount. |
| 8393 | */ |
| 8394 | @Override |
| 8395 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8396 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8397 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8398 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8399 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8400 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8402 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8403 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8404 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8405 | |
| 8406 | final long identity = Binder.clearCallingIdentity(); |
| 8407 | try { |
| 8408 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8409 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8410 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8411 | } |
| 8412 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8413 | } finally { |
| 8414 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8415 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8416 | } |
| 8417 | |
| 8418 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8419 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8420 | * |
| 8421 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8422 | * voicemail vibration setting. |
| 8423 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8424 | */ |
| 8425 | @Override |
| 8426 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8427 | final long identity = Binder.clearCallingIdentity(); |
| 8428 | try { |
| 8429 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8430 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8431 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8432 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8433 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8434 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8435 | } finally { |
| 8436 | Binder.restoreCallingIdentity(identity); |
| 8437 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8438 | } |
| 8439 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8440 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8441 | * Sets the per-account voicemail vibration. |
| 8442 | * |
| 8443 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8444 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8445 | * |
| 8446 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8447 | * voicemail vibration setting. |
| 8448 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8449 | * specific PhoneAccount. |
| 8450 | */ |
| 8451 | @Override |
| 8452 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8453 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8454 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8455 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8456 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8457 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8458 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8459 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8460 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8461 | } |
| 8462 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8463 | final long identity = Binder.clearCallingIdentity(); |
| 8464 | try { |
| 8465 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8466 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8467 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8468 | } |
| 8469 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8470 | } finally { |
| 8471 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8472 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8473 | } |
| 8474 | |
| 8475 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8476 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8477 | * |
| 8478 | * @throws SecurityException if the caller does not have the required permission |
| 8479 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8480 | @VisibleForTesting |
| 8481 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8482 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8483 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8484 | } |
| 8485 | |
| 8486 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8487 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8488 | * permission. |
| 8489 | * |
| 8490 | * @throws SecurityException if the caller does not have the required permission |
| 8491 | */ |
| 8492 | private void enforceSendSmsPermission() { |
| 8493 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8494 | } |
| 8495 | |
| 8496 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8497 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8498 | * users permission. |
| 8499 | * |
| 8500 | * @throws SecurityException if the caller does not have the required permission |
| 8501 | */ |
| 8502 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8503 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8504 | } |
| 8505 | |
| 8506 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8507 | * Make sure called from the package in charge of visual voicemail. |
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 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8510 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8511 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8512 | final long identity = Binder.clearCallingIdentity(); |
| 8513 | try { |
| 8514 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8515 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8516 | if (componentName == null) { |
| 8517 | throw new SecurityException( |
| 8518 | "Caller not current active visual voicemail package[null]"); |
| 8519 | } |
| 8520 | String vvmPackage = componentName.getPackageName(); |
| 8521 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8522 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8523 | } |
| 8524 | } finally { |
| 8525 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8526 | } |
| 8527 | } |
| 8528 | |
| 8529 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8530 | * Return the application ID for the app type. |
| 8531 | * |
| 8532 | * @param subId the subscription ID that this request applies to. |
| 8533 | * @param appType the uicc app type. |
| 8534 | * @return Application ID for specificied app type, or null if no uicc. |
| 8535 | */ |
| 8536 | @Override |
| 8537 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8538 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8539 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8540 | |
| 8541 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8542 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8543 | if (phone == null) { |
| 8544 | return null; |
| 8545 | } |
| 8546 | String aid = null; |
| 8547 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8548 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8549 | .getApplicationByType(appType).getAid(); |
| 8550 | } catch (Exception e) { |
| 8551 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8552 | } |
| 8553 | return aid; |
| 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8556 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8557 | } |
| 8558 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8559 | /** |
| 8560 | * Return the Electronic Serial Number. |
| 8561 | * |
| 8562 | * @param subId the subscription ID that this request applies to. |
| 8563 | * @return ESN or null if error. |
| 8564 | */ |
| 8565 | @Override |
| 8566 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8567 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8568 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8569 | |
| 8570 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8571 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8572 | if (phone == null) { |
| 8573 | return null; |
| 8574 | } |
| 8575 | String esn = null; |
| 8576 | try { |
| 8577 | esn = phone.getEsn(); |
| 8578 | } catch (Exception e) { |
| 8579 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8580 | } |
| 8581 | return esn; |
| 8582 | } finally { |
| 8583 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8584 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8585 | } |
| 8586 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8587 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8588 | * Return the Preferred Roaming List Version. |
| 8589 | * |
| 8590 | * @param subId the subscription ID that this request applies to. |
| 8591 | * @return PRLVersion or null if error. |
| 8592 | */ |
| 8593 | @Override |
| 8594 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8595 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8596 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8597 | |
| 8598 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8599 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8600 | if (phone == null) { |
| 8601 | return null; |
| 8602 | } |
| 8603 | String cdmaPrlVersion = null; |
| 8604 | try { |
| 8605 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8606 | } catch (Exception e) { |
| 8607 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8608 | } |
| 8609 | return cdmaPrlVersion; |
| 8610 | } finally { |
| 8611 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8612 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8613 | } |
| 8614 | |
| 8615 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8616 | * Get snapshot of Telephony histograms |
| 8617 | * @return List of Telephony histograms |
| 8618 | * @hide |
| 8619 | */ |
| 8620 | @Override |
| 8621 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8622 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8623 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8624 | |
| 8625 | final long identity = Binder.clearCallingIdentity(); |
| 8626 | try { |
| 8627 | return RIL.getTelephonyRILTimingHistograms(); |
| 8628 | } finally { |
| 8629 | Binder.restoreCallingIdentity(identity); |
| 8630 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8631 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8632 | |
| 8633 | /** |
| 8634 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8635 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8636 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8637 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8638 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8639 | * @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] | 8640 | */ |
| 8641 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8642 | @TelephonyManager.SetCarrierRestrictionResult |
| 8643 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8644 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8645 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8646 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8647 | if (carrierRestrictionRules == null) { |
| 8648 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8649 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8650 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8651 | final long identity = Binder.clearCallingIdentity(); |
| 8652 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8653 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8654 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8655 | } finally { |
| 8656 | Binder.restoreCallingIdentity(identity); |
| 8657 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8658 | } |
| 8659 | |
| 8660 | /** |
| 8661 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8662 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8663 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8664 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8665 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8666 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8667 | */ |
| 8668 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8669 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8670 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8671 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8672 | |
| 8673 | final long identity = Binder.clearCallingIdentity(); |
| 8674 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8675 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8676 | if (response instanceof CarrierRestrictionRules) { |
| 8677 | return (CarrierRestrictionRules) response; |
| 8678 | } |
| 8679 | // Response is an Exception of some kind, |
| 8680 | // which is signalled to the user as a NULL retval |
| 8681 | return null; |
| 8682 | } catch (Exception e) { |
| 8683 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8684 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8685 | } finally { |
| 8686 | Binder.restoreCallingIdentity(identity); |
| 8687 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8688 | } |
| 8689 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8690 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8691 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8692 | * through the callback. |
| 8693 | * |
| 8694 | * @param callback The callback that will be used to send the result. |
| 8695 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8696 | * the caller is not allowlisted. |
| 8697 | */ |
| 8698 | @Override |
| 8699 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8700 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8701 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8702 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8703 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8704 | throw new SecurityException("Not an authorized caller"); |
| 8705 | } |
| 8706 | final long identity = Binder.clearCallingIdentity(); |
| 8707 | try { |
| 8708 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8709 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8710 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8711 | } finally { |
| 8712 | Binder.restoreCallingIdentity(identity); |
| 8713 | } |
| 8714 | } |
| 8715 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 8716 | @Override |
| 8717 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 8718 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 8719 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8720 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 8721 | } |
| 8722 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8723 | @VisibleForTesting |
| 8724 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8725 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8726 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8727 | } |
| 8728 | |
| 8729 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8730 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8731 | * @param subId the subscription ID that this action applies to. |
| 8732 | * @param enabled control enable or disable radio. |
| 8733 | * {@hide} |
| 8734 | */ |
| 8735 | @Override |
| 8736 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8737 | enforceModifyPermission(); |
| 8738 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8739 | |
| 8740 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8741 | if (phone == null) { |
| 8742 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8743 | return; |
| 8744 | } |
| 8745 | try { |
| 8746 | phone.carrierActionSetRadioEnabled(enabled); |
| 8747 | } catch (Exception e) { |
| 8748 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8749 | } finally { |
| 8750 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8751 | } |
| 8752 | } |
| 8753 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8754 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8755 | * Enable or disable Voice over NR (VoNR) |
| 8756 | * @param subId the subscription ID that this action applies to. |
| 8757 | * @param enabled enable or disable VoNR. |
| 8758 | * @return operation result. |
| 8759 | */ |
| 8760 | @Override |
| 8761 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8762 | enforceModifyPermission(); |
| 8763 | final Phone phone = getPhone(subId); |
| 8764 | |
| 8765 | final long identity = Binder.clearCallingIdentity(); |
| 8766 | if (phone == null) { |
| 8767 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8768 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8769 | } |
| 8770 | |
| 8771 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8772 | try { |
| 8773 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8774 | workSource); |
| 8775 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8776 | |
| 8777 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8778 | if (DBG) { |
| 8779 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8780 | } |
| 8781 | SubscriptionManager.setSubscriptionProperty( |
| 8782 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8783 | (enabled ? "1" : "0")); |
| 8784 | } |
| 8785 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8786 | return result; |
| 8787 | } finally { |
| 8788 | Binder.restoreCallingIdentity(identity); |
| 8789 | } |
| 8790 | } |
| 8791 | |
| 8792 | /** |
| 8793 | * Is voice over NR enabled |
| 8794 | * @return true if VoNR is enabled else false |
| 8795 | */ |
| 8796 | @Override |
| 8797 | public boolean isVoNrEnabled(int subId) { |
| 8798 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8799 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8800 | final long identity = Binder.clearCallingIdentity(); |
| 8801 | try { |
| 8802 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8803 | null, subId, workSource); |
| 8804 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8805 | return isEnabled; |
| 8806 | } finally { |
| 8807 | Binder.restoreCallingIdentity(identity); |
| 8808 | } |
| 8809 | } |
| 8810 | |
| 8811 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8812 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8813 | * network status based on which carrier apps could apply actions accordingly, |
| 8814 | * enable/disable default url handler for example. |
| 8815 | * |
| 8816 | * @param subId the subscription ID that this action applies to. |
| 8817 | * @param report control start/stop reporting the default network status. |
| 8818 | * {@hide} |
| 8819 | */ |
| 8820 | @Override |
| 8821 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8822 | enforceModifyPermission(); |
| 8823 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8824 | |
| 8825 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8826 | if (phone == null) { |
| 8827 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8828 | return; |
| 8829 | } |
| 8830 | try { |
| 8831 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8832 | } catch (Exception e) { |
| 8833 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8834 | } finally { |
| 8835 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8836 | } |
| 8837 | } |
| 8838 | |
| 8839 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8840 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8841 | * @param subId the subscription ID that this action applies to. |
| 8842 | * {@hide} |
| 8843 | */ |
| 8844 | @Override |
| 8845 | public void carrierActionResetAll(int subId) { |
| 8846 | enforceModifyPermission(); |
| 8847 | final Phone phone = getPhone(subId); |
| 8848 | if (phone == null) { |
| 8849 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8850 | return; |
| 8851 | } |
| 8852 | try { |
| 8853 | phone.carrierActionResetAll(); |
| 8854 | } catch (Exception e) { |
| 8855 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8856 | } |
| 8857 | } |
| 8858 | |
| 8859 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8860 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8861 | * bug report is being generated. |
| 8862 | */ |
| 8863 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8864 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8865 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8866 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8867 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8868 | + Binder.getCallingPid() |
| 8869 | + ", uid=" + Binder.getCallingUid() |
| 8870 | + "without permission " |
| 8871 | + android.Manifest.permission.DUMP); |
| 8872 | return; |
| 8873 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8874 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8875 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8876 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8877 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8878 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8879 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8880 | @NonNull String[] args) { |
| 8881 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8882 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8883 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8884 | } |
| 8885 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8886 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8887 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8888 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8889 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8890 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8891 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8892 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8893 | */ |
| 8894 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8895 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8896 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8897 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8898 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8899 | try { |
| 8900 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8901 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8902 | } catch (SecurityException se) { |
| 8903 | enforceModifyPermission(); |
| 8904 | } |
| 8905 | } else { |
| 8906 | enforceModifyPermission(); |
| 8907 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8908 | |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 8909 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 8910 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 8911 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(), |
| 8912 | callingPackage, null, null); |
| 8913 | } |
| 8914 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8915 | final long identity = Binder.clearCallingIdentity(); |
| 8916 | try { |
| 8917 | Phone phone = getPhone(subId); |
| 8918 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8919 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8920 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8921 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8922 | phone.getDataSettingsManager().setDataEnabled( |
| 8923 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8924 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8925 | } |
| 8926 | } finally { |
| 8927 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8928 | } |
| 8929 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8930 | |
| 8931 | /** |
| 8932 | * Get Client request stats |
| 8933 | * @return List of Client Request Stats |
| 8934 | * @hide |
| 8935 | */ |
| 8936 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8937 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8938 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8939 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8940 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8941 | return null; |
| 8942 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8943 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8944 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8945 | final long identity = Binder.clearCallingIdentity(); |
| 8946 | try { |
| 8947 | if (phone != null) { |
| 8948 | return phone.getClientRequestStats(); |
| 8949 | } |
| 8950 | |
| 8951 | return null; |
| 8952 | } finally { |
| 8953 | Binder.restoreCallingIdentity(identity); |
| 8954 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8955 | } |
| 8956 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8957 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8958 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8959 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8960 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8961 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8962 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8963 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8964 | // commands that plumb through the RIL as root, like so: |
| 8965 | // $ adb root |
| 8966 | // $ adb shell cmd phone ... |
| 8967 | packageName = "root"; |
| 8968 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8969 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8970 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8971 | |
| 8972 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8973 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8974 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8975 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8976 | * @param state State of SIM (power down, power up, pass through) |
| 8977 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8978 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8979 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8980 | * |
| 8981 | **/ |
| 8982 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8983 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8984 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8985 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8986 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8987 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8988 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8989 | final long identity = Binder.clearCallingIdentity(); |
| 8990 | try { |
| 8991 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8992 | phone.setSimPowerState(state, null, workSource); |
| 8993 | } |
| 8994 | } finally { |
| 8995 | Binder.restoreCallingIdentity(identity); |
| 8996 | } |
| 8997 | } |
| 8998 | |
| 8999 | /** |
| 9000 | * Set SIM card power state. |
| 9001 | * |
| 9002 | * @param slotIndex SIM slot id. |
| 9003 | * @param state State of SIM (power down, power up, pass through) |
| 9004 | * @param callback callback to trigger after success or failure |
| 9005 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9006 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9007 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9008 | * |
| 9009 | **/ |
| 9010 | @Override |
| 9011 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9012 | IIntegerConsumer callback) { |
| 9013 | enforceModifyPermission(); |
| 9014 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9015 | |
| 9016 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9017 | |
| 9018 | final long identity = Binder.clearCallingIdentity(); |
| 9019 | try { |
| 9020 | if (phone != null) { |
| 9021 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9022 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9023 | } |
| 9024 | } finally { |
| 9025 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9026 | } |
| 9027 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9028 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9029 | private boolean isUssdApiAllowed(int subId) { |
| 9030 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9031 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9032 | if (configManager == null) { |
| 9033 | return false; |
| 9034 | } |
| 9035 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9036 | if (pb == null) { |
| 9037 | return false; |
| 9038 | } |
| 9039 | return pb.getBoolean( |
| 9040 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9041 | } |
| 9042 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9043 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9044 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9045 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9046 | * @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] | 9047 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9048 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9049 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9050 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9051 | final long identity = Binder.clearCallingIdentity(); |
| 9052 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9053 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9054 | } finally { |
| 9055 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9056 | } |
| 9057 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9058 | |
| 9059 | /** |
| 9060 | * Get the current signal strength information for the given subscription. |
| 9061 | * Because this information is not updated when the device is in a low power state |
| 9062 | * it should not be relied-upon to be current. |
| 9063 | * @param subId Subscription index |
| 9064 | * @return the most recent cached signal strength info from the modem |
| 9065 | */ |
| 9066 | @Override |
| 9067 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9068 | final long identity = Binder.clearCallingIdentity(); |
| 9069 | try { |
| 9070 | Phone p = getPhone(subId); |
| 9071 | if (p == null) { |
| 9072 | return null; |
| 9073 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9074 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9075 | return p.getSignalStrength(); |
| 9076 | } finally { |
| 9077 | Binder.restoreCallingIdentity(identity); |
| 9078 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9079 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9080 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9081 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9082 | * Get the current modem radio state for the given slot. |
| 9083 | * @param slotIndex slot index. |
| 9084 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9085 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9086 | * @return the current radio power state from the modem |
| 9087 | */ |
| 9088 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9089 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9090 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9091 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9093 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9094 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9095 | } |
| 9096 | |
| 9097 | final long identity = Binder.clearCallingIdentity(); |
| 9098 | try { |
| 9099 | return phone.getRadioPowerState(); |
| 9100 | } finally { |
| 9101 | Binder.restoreCallingIdentity(identity); |
| 9102 | } |
| 9103 | } |
| 9104 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9105 | } |
| 9106 | |
| 9107 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9108 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9109 | * |
| 9110 | * <p>Requires one of the following permissions: |
| 9111 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9112 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9113 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9114 | * privileges. |
| 9115 | * |
| 9116 | * @param subId subscription id |
| 9117 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9118 | * {@code false}. |
| 9119 | */ |
| 9120 | @Override |
| 9121 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9122 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9123 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9124 | try { |
| 9125 | mApp.enforceCallingOrSelfPermission( |
| 9126 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9127 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9128 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9129 | mApp.enforceCallingOrSelfPermission( |
| 9130 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9131 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9132 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9133 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9134 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9135 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9136 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9137 | boolean isEnabled = false; |
| 9138 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9139 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9140 | Phone phone = getPhone(subId); |
| 9141 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9142 | } finally { |
| 9143 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9144 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9145 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9146 | } |
| 9147 | |
| 9148 | |
| 9149 | /** |
| 9150 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9151 | * |
| 9152 | * <p> Requires permission: |
| 9153 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9154 | * privileges. |
| 9155 | * |
| 9156 | * @param subId subscription id |
| 9157 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9158 | */ |
| 9159 | @Override |
| 9160 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9162 | mApp, subId, "setDataRoamingEnabled"); |
| 9163 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9164 | final long identity = Binder.clearCallingIdentity(); |
| 9165 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9166 | Phone phone = getPhone(subId); |
| 9167 | if (phone != null) { |
| 9168 | phone.setDataRoamingEnabled(isEnabled); |
| 9169 | } |
| 9170 | } finally { |
| 9171 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9172 | } |
| 9173 | } |
| 9174 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9175 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9176 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9177 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9178 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9179 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9180 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9181 | boolean isAllowed = true; |
| 9182 | final long identity = Binder.clearCallingIdentity(); |
| 9183 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9184 | Phone phone = getPhone(subId); |
| 9185 | if (phone != null) { |
| 9186 | isAllowed = phone.isCspPlmnEnabled(); |
| 9187 | } |
| 9188 | } finally { |
| 9189 | Binder.restoreCallingIdentity(identity); |
| 9190 | } |
| 9191 | return isAllowed; |
| 9192 | } |
| 9193 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9194 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9195 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9196 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9197 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9198 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9199 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9200 | if (phone == null) { |
| 9201 | return false; |
| 9202 | } |
| 9203 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9204 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9205 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9206 | } |
| 9207 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9208 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9209 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9210 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9211 | mApp.getSystemService(AppOpsManager.class) |
| 9212 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9213 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9214 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9215 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9216 | try { |
| 9217 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9218 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9219 | } catch (SecurityException e) { |
| 9220 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9221 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9222 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9223 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9224 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9225 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9226 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9227 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9228 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9229 | Binder.getCallingUid())) { |
| 9230 | isIccIdAccessRestricted = true; |
| 9231 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9232 | final long identity = Binder.clearCallingIdentity(); |
| 9233 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9234 | UiccController uiccController = UiccController.getInstance(); |
| 9235 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9236 | if (hasReadPermission) { |
| 9237 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9238 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9239 | |
| 9240 | // Remove private info if the caller doesn't have access |
| 9241 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9242 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9243 | //setting the value after compatibility check |
| 9244 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9245 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9246 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9247 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9248 | if (card == null) { |
| 9249 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9250 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9251 | continue; |
| 9252 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9253 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9254 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9255 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9256 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9257 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9258 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9259 | for (UiccPortInfo portInfo : portInfos) { |
| 9260 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9261 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9262 | if (port == null) { |
| 9263 | // assume no access if port is null |
| 9264 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9265 | continue; |
| 9266 | } |
| 9267 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9268 | uiccPortInfos.add(portInfo); |
| 9269 | } else { |
| 9270 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9271 | } |
| 9272 | } |
| 9273 | filteredInfos.add(new UiccCardInfo( |
| 9274 | cardInfo.isEuicc(), |
| 9275 | cardInfo.getCardId(), |
| 9276 | null, |
| 9277 | cardInfo.getPhysicalSlotIndex(), |
| 9278 | cardInfo.isRemovable(), |
| 9279 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9280 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9281 | } |
| 9282 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9283 | } finally { |
| 9284 | Binder.restoreCallingIdentity(identity); |
| 9285 | } |
| 9286 | } |
| 9287 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9288 | /** |
| 9289 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9290 | * generally private and require carrier privileges to view. |
| 9291 | * |
| 9292 | * @hide |
| 9293 | */ |
| 9294 | @NonNull |
| 9295 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9296 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9297 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9298 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9299 | } |
| 9300 | return new UiccCardInfo( |
| 9301 | cardInfo.isEuicc(), |
| 9302 | cardInfo.getCardId(), |
| 9303 | null, |
| 9304 | cardInfo.getPhysicalSlotIndex(), |
| 9305 | cardInfo.isRemovable(), |
| 9306 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9307 | portinfo |
| 9308 | ); |
| 9309 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9310 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9311 | /** |
| 9312 | * @hide |
| 9313 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9314 | * These values are generally private and require carrier privileges to view. |
| 9315 | */ |
| 9316 | @NonNull |
| 9317 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9318 | return new UiccPortInfo( |
| 9319 | UiccPortInfo.ICCID_REDACTED, |
| 9320 | portInfo.getPortIndex(), |
| 9321 | portInfo.getLogicalSlotIndex(), |
| 9322 | portInfo.isActive() |
| 9323 | ); |
| 9324 | } |
| 9325 | @Override |
| 9326 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9327 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9328 | mApp.getSystemService(AppOpsManager.class) |
| 9329 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9330 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9331 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9332 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9333 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9334 | // we are reading iccId which is PII data. |
| 9335 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9336 | |
| 9337 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9338 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9339 | Binder.getCallingUid())) { |
| 9340 | isLogicalSlotAccessRestricted = true; |
| 9341 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9342 | final long identity = Binder.clearCallingIdentity(); |
| 9343 | try { |
| 9344 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9345 | if (slots == null || slots.length == 0) { |
| 9346 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9347 | return null; |
| 9348 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9349 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9350 | for (int i = 0; i < slots.length; i++) { |
| 9351 | UiccSlot slot = slots[i]; |
| 9352 | if (slot == null) { |
| 9353 | continue; |
| 9354 | } |
| 9355 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9356 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9357 | UiccCard card = slot.getUiccCard(); |
| 9358 | if (card != null) { |
| 9359 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9360 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9361 | cardId = slot.getEid(); |
| 9362 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9363 | // If cardId is null, use iccId of default port as cardId. |
| 9364 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9365 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9366 | } |
| 9367 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9368 | if (cardId != null) { |
| 9369 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9370 | // if cardId is an EID, it's all digits so this is fine |
| 9371 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9372 | } |
| 9373 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9374 | int cardState = 0; |
| 9375 | switch (slot.getCardState()) { |
| 9376 | case CARDSTATE_ABSENT: |
| 9377 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9378 | break; |
| 9379 | case CARDSTATE_PRESENT: |
| 9380 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9381 | break; |
| 9382 | case CARDSTATE_ERROR: |
| 9383 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9384 | break; |
| 9385 | case CARDSTATE_RESTRICTED: |
| 9386 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9387 | break; |
| 9388 | default: |
| 9389 | break; |
| 9390 | |
| 9391 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9392 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9393 | int[] portIndexes = slot.getPortList(); |
| 9394 | for (int portIdx : portIndexes) { |
| 9395 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9396 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9397 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9398 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9399 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9400 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9401 | slot.isEuicc(), |
| 9402 | cardId, |
| 9403 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9404 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9405 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9406 | //setting the value after compatibility check |
| 9407 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9408 | } |
| 9409 | return infos; |
| 9410 | } finally { |
| 9411 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9412 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9413 | } |
| 9414 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9415 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9416 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9417 | boolean hasReadPermission) { |
| 9418 | String iccId = slot.getIccId(portIndex); |
| 9419 | if (hasReadPermission) { // if has read permission |
| 9420 | return iccId; |
| 9421 | } else { |
| 9422 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9423 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9424 | // if no read permission, checking carrier privilege access |
| 9425 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9426 | return iccId; |
| 9427 | } |
| 9428 | } |
| 9429 | } |
| 9430 | // No read permission or carrier privilege access. |
| 9431 | return UiccPortInfo.ICCID_REDACTED; |
| 9432 | } |
| 9433 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9434 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9435 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9436 | public boolean switchSlots(int[] physicalSlots) { |
| 9437 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9438 | |
| 9439 | final long identity = Binder.clearCallingIdentity(); |
| 9440 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9441 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9442 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9443 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9444 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9445 | physicalSlots[i], i)); |
| 9446 | } |
| 9447 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9448 | } finally { |
| 9449 | Binder.restoreCallingIdentity(identity); |
| 9450 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9451 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9452 | |
| 9453 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9454 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9455 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9456 | enforceModifyPermission(); |
| 9457 | |
| 9458 | final long identity = Binder.clearCallingIdentity(); |
| 9459 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9460 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9461 | } finally { |
| 9462 | Binder.restoreCallingIdentity(identity); |
| 9463 | } |
| 9464 | } |
| 9465 | |
| 9466 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9467 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9468 | final long identity = Binder.clearCallingIdentity(); |
| 9469 | try { |
| 9470 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9471 | } finally { |
| 9472 | Binder.restoreCallingIdentity(identity); |
| 9473 | } |
| 9474 | } |
| 9475 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9476 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9477 | * A test API to reload the UICC profile. |
| 9478 | * |
| 9479 | * <p>Requires that the calling app has permission |
| 9480 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9481 | * @hide |
| 9482 | */ |
| 9483 | @Override |
| 9484 | public void refreshUiccProfile(int subId) { |
| 9485 | enforceModifyPermission(); |
| 9486 | |
| 9487 | final long identity = Binder.clearCallingIdentity(); |
| 9488 | try { |
| 9489 | Phone phone = getPhone(subId); |
| 9490 | if (phone == null) { |
| 9491 | return; |
| 9492 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9493 | UiccPort uiccPort = phone.getUiccPort(); |
| 9494 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9495 | return; |
| 9496 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9497 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9498 | if (uiccProfile == null) { |
| 9499 | return; |
| 9500 | } |
| 9501 | uiccProfile.refresh(); |
| 9502 | } finally { |
| 9503 | Binder.restoreCallingIdentity(identity); |
| 9504 | } |
| 9505 | } |
| 9506 | |
| 9507 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9508 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9509 | */ |
| 9510 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9511 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9512 | } |
| 9513 | |
| 9514 | /** |
| 9515 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9516 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9517 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9518 | */ |
| 9519 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9520 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9521 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9522 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9523 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9524 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9525 | return isDataRoamingEnabled; |
| 9526 | } |
| 9527 | |
| 9528 | /** |
| 9529 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9530 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9531 | */ |
| 9532 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9533 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9534 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9535 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9536 | return list.get(phoneId); |
| 9537 | } |
| 9538 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9539 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9540 | |
| 9541 | @Override |
| 9542 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9543 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9544 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9545 | |
| 9546 | final long identity = Binder.clearCallingIdentity(); |
| 9547 | try { |
| 9548 | final Phone phone = getPhone(subId); |
| 9549 | if (phone == null) { |
| 9550 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9551 | return; |
| 9552 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9553 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9554 | if (cpt != null) { |
| 9555 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9556 | } |
| 9557 | // 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] | 9558 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9559 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9560 | if (carrierPrivilegeRules == null) { |
| 9561 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9562 | } else { |
| 9563 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9565 | } finally { |
| 9566 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9567 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9568 | } |
| 9569 | |
| 9570 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9571 | public void setCarrierServicePackageOverride( |
| 9572 | int subId, String carrierServicePackage, String callingPackage) { |
| 9573 | TelephonyPermissions.enforceShellOnly( |
| 9574 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9575 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9576 | final long identity = Binder.clearCallingIdentity(); |
| 9577 | try { |
| 9578 | final Phone phone = getPhone(subId); |
| 9579 | if (phone == null || phone.getSubId() != subId) { |
| 9580 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9581 | throw new IllegalArgumentException("No phone for subid"); |
| 9582 | } |
| 9583 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9584 | if (cpt == null) { |
| 9585 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9586 | throw new IllegalStateException("No CPT for phone"); |
| 9587 | } |
| 9588 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9589 | } finally { |
| 9590 | Binder.restoreCallingIdentity(identity); |
| 9591 | } |
| 9592 | } |
| 9593 | |
| 9594 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9595 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9596 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9597 | |
| 9598 | final long identity = Binder.clearCallingIdentity(); |
| 9599 | try { |
| 9600 | final Phone phone = getPhone(subId); |
| 9601 | if (phone == null) { |
| 9602 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9603 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9604 | } |
| 9605 | return phone.getCarrierIdListVersion(); |
| 9606 | } finally { |
| 9607 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9608 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9609 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9610 | |
| 9611 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9612 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9613 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9614 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9615 | mApp, subId, callingPackage, callingFeatureId, |
| 9616 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9617 | return -1; |
| 9618 | } |
| 9619 | |
| 9620 | final long identity = Binder.clearCallingIdentity(); |
| 9621 | try { |
| 9622 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9623 | } finally { |
| 9624 | Binder.restoreCallingIdentity(identity); |
| 9625 | } |
| 9626 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9627 | |
| 9628 | @Override |
| 9629 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9630 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9631 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9632 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9633 | |
| 9634 | final long identity = Binder.clearCallingIdentity(); |
| 9635 | try { |
| 9636 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9637 | } finally { |
| 9638 | Binder.restoreCallingIdentity(identity); |
| 9639 | } |
| 9640 | } |
| 9641 | |
| 9642 | @Override |
| 9643 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9645 | mApp, subId, "setCdmaRoamingMode"); |
| 9646 | |
| 9647 | final long identity = Binder.clearCallingIdentity(); |
| 9648 | try { |
| 9649 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9650 | } finally { |
| 9651 | Binder.restoreCallingIdentity(identity); |
| 9652 | } |
| 9653 | } |
| 9654 | |
| 9655 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9656 | public int getCdmaSubscriptionMode(int subId) { |
| 9657 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9658 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9659 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9660 | |
| 9661 | final long identity = Binder.clearCallingIdentity(); |
| 9662 | try { |
| 9663 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9664 | } finally { |
| 9665 | Binder.restoreCallingIdentity(identity); |
| 9666 | } |
| 9667 | } |
| 9668 | |
| 9669 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9670 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9671 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9672 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9673 | |
| 9674 | final long identity = Binder.clearCallingIdentity(); |
| 9675 | try { |
| 9676 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9677 | } finally { |
| 9678 | Binder.restoreCallingIdentity(identity); |
| 9679 | } |
| 9680 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9681 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9682 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9683 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9684 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9685 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9686 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9687 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9688 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9689 | } |
| 9690 | final long identity = Binder.clearCallingIdentity(); |
| 9691 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9692 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9693 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9694 | if (phone.getEmergencyNumberTracker() != null |
| 9695 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9696 | emergencyNumberListInternal.put( |
| 9697 | phone.getSubId(), |
| 9698 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9699 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9700 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9701 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9702 | } finally { |
| 9703 | Binder.restoreCallingIdentity(identity); |
| 9704 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9705 | } |
| 9706 | |
| 9707 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9708 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9709 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9710 | if (!exactMatch) { |
| 9711 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9712 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9713 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9714 | } |
| 9715 | final long identity = Binder.clearCallingIdentity(); |
| 9716 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9717 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9718 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9719 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9720 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9721 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9722 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9723 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9724 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9725 | } |
| 9726 | return false; |
| 9727 | } finally { |
| 9728 | Binder.restoreCallingIdentity(identity); |
| 9729 | } |
| 9730 | } |
| 9731 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9732 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9733 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9734 | */ |
| 9735 | @Override |
| 9736 | public void startEmergencyCallbackMode() { |
| 9737 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9738 | "startEmergencyCallbackMode"); |
| 9739 | enforceModifyPermission(); |
| 9740 | final long identity = Binder.clearCallingIdentity(); |
| 9741 | try { |
| 9742 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9743 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9744 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9745 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9746 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9747 | gsmCdmaPhone.obtainMessage( |
| 9748 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9749 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9750 | } |
| 9751 | } |
| 9752 | } finally { |
| 9753 | Binder.restoreCallingIdentity(identity); |
| 9754 | } |
| 9755 | } |
| 9756 | |
| 9757 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9758 | * Update emergency number list for test mode. |
| 9759 | */ |
| 9760 | @Override |
| 9761 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9762 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9763 | "updateEmergencyNumberListTestMode"); |
| 9764 | |
| 9765 | final long identity = Binder.clearCallingIdentity(); |
| 9766 | try { |
| 9767 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9768 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9769 | if (tracker != null) { |
| 9770 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9771 | } |
| 9772 | } |
| 9773 | } finally { |
| 9774 | Binder.restoreCallingIdentity(identity); |
| 9775 | } |
| 9776 | } |
| 9777 | |
| 9778 | /** |
| 9779 | * Get the full emergency number list for test mode. |
| 9780 | */ |
| 9781 | @Override |
| 9782 | public List<String> getEmergencyNumberListTestMode() { |
| 9783 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9784 | "getEmergencyNumberListTestMode"); |
| 9785 | |
| 9786 | final long identity = Binder.clearCallingIdentity(); |
| 9787 | try { |
| 9788 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9789 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9790 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9791 | if (tracker != null) { |
| 9792 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9793 | emergencyNumbers.add(num.getNumber()); |
| 9794 | } |
| 9795 | } |
| 9796 | } |
| 9797 | return new ArrayList<>(emergencyNumbers); |
| 9798 | } finally { |
| 9799 | Binder.restoreCallingIdentity(identity); |
| 9800 | } |
| 9801 | } |
| 9802 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9803 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9804 | public int getEmergencyNumberDbVersion(int subId) { |
| 9805 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9806 | |
| 9807 | final long identity = Binder.clearCallingIdentity(); |
| 9808 | try { |
| 9809 | final Phone phone = getPhone(subId); |
| 9810 | if (phone == null) { |
| 9811 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9812 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9813 | } |
| 9814 | return phone.getEmergencyNumberDbVersion(); |
| 9815 | } finally { |
| 9816 | Binder.restoreCallingIdentity(identity); |
| 9817 | } |
| 9818 | } |
| 9819 | |
| 9820 | @Override |
| 9821 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9822 | enforceModifyPermission(); |
| 9823 | |
| 9824 | final long identity = Binder.clearCallingIdentity(); |
| 9825 | try { |
| 9826 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9827 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9828 | if (tracker != null) { |
| 9829 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9830 | } |
| 9831 | } |
| 9832 | } finally { |
| 9833 | Binder.restoreCallingIdentity(identity); |
| 9834 | } |
| 9835 | } |
| 9836 | |
| 9837 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9838 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9839 | enforceActiveEmergencySessionPermission(); |
| 9840 | |
| 9841 | final long identity = Binder.clearCallingIdentity(); |
| 9842 | try { |
| 9843 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9844 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9845 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9846 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9847 | } |
| 9848 | } |
| 9849 | } finally { |
| 9850 | Binder.restoreCallingIdentity(identity); |
| 9851 | } |
| 9852 | } |
| 9853 | |
| 9854 | @Override |
| 9855 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9856 | enforceActiveEmergencySessionPermission(); |
| 9857 | |
| 9858 | final long identity = Binder.clearCallingIdentity(); |
| 9859 | try { |
| 9860 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9861 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9862 | if (tracker != null) { |
| 9863 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9864 | } |
| 9865 | } |
| 9866 | } finally { |
| 9867 | Binder.restoreCallingIdentity(identity); |
| 9868 | } |
| 9869 | } |
| 9870 | |
| 9871 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9872 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9873 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9874 | Phone phone = getPhone(subId); |
| 9875 | if (phone == null) { |
| 9876 | return null; |
| 9877 | } |
| 9878 | final long identity = Binder.clearCallingIdentity(); |
| 9879 | try { |
| 9880 | UiccProfile profile = UiccController.getInstance() |
| 9881 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9882 | if (profile != null) { |
| 9883 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9884 | } |
| 9885 | } finally { |
| 9886 | Binder.restoreCallingIdentity(identity); |
| 9887 | } |
| 9888 | return null; |
| 9889 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9890 | |
| 9891 | /** |
| 9892 | * Enable or disable a modem stack. |
| 9893 | */ |
| 9894 | @Override |
| 9895 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9896 | enforceModifyPermission(); |
| 9897 | |
| 9898 | final long identity = Binder.clearCallingIdentity(); |
| 9899 | try { |
| 9900 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9901 | if (phone == null) { |
| 9902 | return false; |
| 9903 | } else { |
| 9904 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9905 | } |
| 9906 | } finally { |
| 9907 | Binder.restoreCallingIdentity(identity); |
| 9908 | } |
| 9909 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9910 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9911 | /** |
| 9912 | * Whether a modem stack is enabled or not. |
| 9913 | */ |
| 9914 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9915 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9916 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9917 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9918 | if (phone == null) return false; |
| 9919 | |
| 9920 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9921 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9922 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9923 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9924 | } |
| 9925 | |
| 9926 | final long identity = Binder.clearCallingIdentity(); |
| 9927 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9928 | try { |
| 9929 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9930 | } catch (NoSuchElementException ex) { |
| 9931 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9932 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9933 | } finally { |
| 9934 | Binder.restoreCallingIdentity(identity); |
| 9935 | } |
| 9936 | } |
| 9937 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9938 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9939 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9940 | enforceModifyPermission(); |
| 9941 | |
| 9942 | final long identity = Binder.clearCallingIdentity(); |
| 9943 | try { |
| 9944 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9945 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9946 | .commit(); |
| 9947 | } finally { |
| 9948 | Binder.restoreCallingIdentity(identity); |
| 9949 | } |
| 9950 | } |
| 9951 | |
| 9952 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9953 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9954 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9955 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9956 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9957 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9958 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9959 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9960 | |
| 9961 | final long identity = Binder.clearCallingIdentity(); |
| 9962 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9963 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9964 | } finally { |
| 9965 | Binder.restoreCallingIdentity(identity); |
| 9966 | } |
| 9967 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9968 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9969 | @TelephonyManager.IsMultiSimSupportedResult |
| 9970 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9971 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9972 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9973 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9974 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9975 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9976 | } |
| 9977 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9978 | // supported by the modem, indicate that it is restricted. |
| 9979 | PhoneCapability staticCapability = |
| 9980 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9981 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9982 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9983 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9984 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9985 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9986 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9987 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9988 | } |
| 9989 | // Check if support of multiple SIMs is restricted by carrier |
| 9990 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9991 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9992 | } |
| 9993 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9994 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9995 | } |
| 9996 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9997 | /** |
| 9998 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9999 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10000 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10001 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10002 | * @param numOfSims number of active sims we want to switch to |
| 10003 | */ |
| 10004 | @Override |
| 10005 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10006 | if (numOfSims == 1) { |
| 10007 | enforceModifyPermission(); |
| 10008 | } else { |
| 10009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10010 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10011 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10012 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10013 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10014 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10015 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10016 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10017 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10018 | return; |
| 10019 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10020 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10021 | } finally { |
| 10022 | Binder.restoreCallingIdentity(identity); |
| 10023 | } |
| 10024 | } |
| 10025 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10026 | @Override |
| 10027 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10028 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10029 | Phone phone = getPhone(subId); |
| 10030 | if (phone == null) { |
| 10031 | return false; |
| 10032 | } |
| 10033 | final long identity = Binder.clearCallingIdentity(); |
| 10034 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10035 | UiccPort uiccPort = phone.getUiccPort(); |
| 10036 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10037 | return false; |
| 10038 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10039 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10040 | if (uiccProfile == null) { |
| 10041 | return false; |
| 10042 | } |
| 10043 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10044 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10045 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10046 | } |
| 10047 | return false; |
| 10048 | } finally { |
| 10049 | Binder.restoreCallingIdentity(identity); |
| 10050 | } |
| 10051 | } |
| 10052 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10053 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10054 | * Get whether making changes to modem configurations will trigger reboot. |
| 10055 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10056 | */ |
| 10057 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10058 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10059 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10060 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10061 | mApp, subId, callingPackage, callingFeatureId, |
| 10062 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10063 | return false; |
| 10064 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10065 | final long identity = Binder.clearCallingIdentity(); |
| 10066 | try { |
| 10067 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10068 | } finally { |
| 10069 | Binder.restoreCallingIdentity(identity); |
| 10070 | } |
| 10071 | } |
| 10072 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10073 | private void updateModemStateMetrics() { |
| 10074 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10075 | // TODO: check the state for each modem if the api is ready. |
| 10076 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10077 | } |
| 10078 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10079 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10080 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10081 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10082 | // Verify that the callingPackage belongs to the calling UID |
| 10083 | mApp.getSystemService(AppOpsManager.class) |
| 10084 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10085 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10086 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10087 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10088 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10089 | if (slotInfos != null) { |
| 10090 | for (int i = 0; i < slotInfos.length; i++) { |
| 10091 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10092 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10093 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10094 | portInfo.getLogicalSlotIndex())); |
| 10095 | } |
| 10096 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10097 | } |
| 10098 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10099 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10100 | } finally { |
| 10101 | Binder.restoreCallingIdentity(identity); |
| 10102 | } |
| 10103 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10104 | |
| 10105 | /** |
| 10106 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10107 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10108 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10109 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10110 | @Override |
| 10111 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10112 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10113 | } |
| 10114 | |
| 10115 | /** |
| 10116 | * Get the HAL Version of a specific service |
| 10117 | */ |
| 10118 | @Override |
| 10119 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10120 | Phone phone = getDefaultPhone(); |
| 10121 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10122 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10123 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10124 | return hv.major * 100 + hv.minor; |
| 10125 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10126 | |
| 10127 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10128 | * Get the current calling package name. |
| 10129 | * @return the current calling package name |
| 10130 | */ |
| 10131 | @Override |
| 10132 | public String getCurrentPackageName() { |
| 10133 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10134 | } |
| 10135 | |
| 10136 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10137 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10138 | * corresponding network requests on a subId. |
| 10139 | * |
| 10140 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10141 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10142 | * 2) APN is un-metered for this subscription, or |
| 10143 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10144 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10145 | * |
| 10146 | * @return whether data is allowed for a apn type. |
| 10147 | * |
| 10148 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10149 | */ |
| 10150 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10151 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10152 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10153 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10154 | |
| 10155 | // Now that all security checks passes, perform the operation as ourselves. |
| 10156 | final long identity = Binder.clearCallingIdentity(); |
| 10157 | try { |
| 10158 | Phone phone = getPhone(subId); |
| 10159 | if (phone == null) return false; |
| 10160 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10161 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10162 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10163 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10164 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10165 | phone.getServiceState().getDataRoaming()); |
| 10166 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10167 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10168 | } finally { |
| 10169 | Binder.restoreCallingIdentity(identity); |
| 10170 | } |
| 10171 | } |
| 10172 | |
| 10173 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10174 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10175 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10176 | |
| 10177 | // Now that all security checks passes, perform the operation as ourselves. |
| 10178 | final long identity = Binder.clearCallingIdentity(); |
| 10179 | try { |
| 10180 | Phone phone = getPhone(subId); |
| 10181 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10182 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10183 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10184 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10185 | } finally { |
| 10186 | Binder.restoreCallingIdentity(identity); |
| 10187 | } |
| 10188 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10189 | |
| 10190 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10191 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10192 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10193 | enforceModifyPermission(); |
| 10194 | long token = Binder.clearCallingIdentity(); |
| 10195 | try { |
| 10196 | Phone phone = getPhone(subscriptionId); |
| 10197 | if (phone == null) { |
| 10198 | try { |
| 10199 | if (resultCallback != null) { |
| 10200 | resultCallback.accept(false); |
| 10201 | } |
| 10202 | } catch (RemoteException e) { |
| 10203 | // ignore |
| 10204 | } |
| 10205 | return; |
| 10206 | } |
| 10207 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10208 | Pair.create(specifiers, (x) -> { |
| 10209 | try { |
| 10210 | if (resultCallback != null) { |
| 10211 | resultCallback.accept(x); |
| 10212 | } |
| 10213 | } catch (RemoteException e) { |
| 10214 | // ignore |
| 10215 | } |
| 10216 | }); |
| 10217 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10218 | } finally { |
| 10219 | Binder.restoreCallingIdentity(token); |
| 10220 | } |
| 10221 | } |
| 10222 | |
| 10223 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10224 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10225 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10226 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10227 | mApp, subId, "getSystemSelectionChannels"); |
| 10228 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10229 | final long identity = Binder.clearCallingIdentity(); |
| 10230 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10231 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10232 | if (result instanceof IllegalStateException) { |
| 10233 | throw (IllegalStateException) result; |
| 10234 | } |
| 10235 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10236 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10237 | return specifiers; |
| 10238 | } finally { |
| 10239 | Binder.restoreCallingIdentity(identity); |
| 10240 | } |
| 10241 | } |
| 10242 | |
| 10243 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10244 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10245 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10246 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10247 | } |
| 10248 | |
| 10249 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10250 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10251 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10252 | if (callingPackage == null) { |
| 10253 | callingPackage = getCurrentPackageName(); |
| 10254 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10255 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10256 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10257 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10258 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10259 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10260 | } |
| 10261 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10262 | Intent intent = new Intent(); |
| 10263 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10264 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10265 | // Bring up choose default SMS subscription dialog right now |
| 10266 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10267 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10268 | mApp.startActivity(intent); |
| 10269 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10270 | |
| 10271 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10272 | public void showSwitchToManagedProfileDialog() { |
| 10273 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10274 | try { |
| 10275 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10276 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10277 | // for work telephony. |
| 10278 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10279 | intent.setData(Uri.parse("smsto:")); |
| 10280 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10281 | mApp.startActivity(intent); |
| 10282 | } catch (ActivityNotFoundException e) { |
| 10283 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10284 | Intent intent = new Intent(); |
| 10285 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10286 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10287 | mApp.startActivity(intent); |
| 10288 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10289 | } |
| 10290 | |
| 10291 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10292 | public String getMmsUAProfUrl(int subId) { |
| 10293 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10294 | final long identity = Binder.clearCallingIdentity(); |
| 10295 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10296 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10297 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10298 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10299 | return carrierUAProfUrl; |
| 10300 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10301 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10302 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10303 | } finally { |
| 10304 | Binder.restoreCallingIdentity(identity); |
| 10305 | } |
| 10306 | } |
| 10307 | |
| 10308 | @Override |
| 10309 | public String getMmsUserAgent(int subId) { |
| 10310 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10311 | final long identity = Binder.clearCallingIdentity(); |
| 10312 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10313 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10314 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10315 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10316 | return carrierUserAgent; |
| 10317 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10318 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10319 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10320 | } finally { |
| 10321 | Binder.restoreCallingIdentity(identity); |
| 10322 | } |
| 10323 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10324 | |
| 10325 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10326 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10327 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10328 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10329 | final long identity = Binder.clearCallingIdentity(); |
| 10330 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10331 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10332 | if (phone == null) return false; |
| 10333 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10334 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10335 | } finally { |
| 10336 | Binder.restoreCallingIdentity(identity); |
| 10337 | } |
| 10338 | } |
| 10339 | |
| 10340 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10341 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10342 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10343 | enforceModifyPermission(); |
| 10344 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10345 | final long identity = Binder.clearCallingIdentity(); |
| 10346 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10347 | Phone phone = getPhone(subscriptionId); |
| 10348 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10349 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10350 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10351 | } finally { |
| 10352 | Binder.restoreCallingIdentity(identity); |
| 10353 | } |
| 10354 | } |
| 10355 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10356 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10357 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10358 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10359 | * otherwise. |
| 10360 | */ |
| 10361 | @Override |
| 10362 | public void setCepEnabled(boolean isCepEnabled) { |
| 10363 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10364 | |
| 10365 | final long identity = Binder.clearCallingIdentity(); |
| 10366 | try { |
| 10367 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10368 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10369 | Phone defaultPhone = phone.getImsPhone(); |
| 10370 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10371 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10372 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10373 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10374 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10375 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10376 | + imsPhone.getMsisdn()); |
| 10377 | } |
| 10378 | } |
| 10379 | } finally { |
| 10380 | Binder.restoreCallingIdentity(identity); |
| 10381 | } |
| 10382 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10383 | |
| 10384 | /** |
| 10385 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10386 | * |
| 10387 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10388 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10389 | * before being read. |
| 10390 | */ |
| 10391 | @Override |
| 10392 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10393 | isCompressed) { |
| 10394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10395 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10396 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10397 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10398 | } |
| 10399 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10400 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10401 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10402 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10403 | } |
| 10404 | |
| 10405 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10406 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10407 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10408 | } finally { |
| 10409 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10410 | } |
| 10411 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10412 | |
| 10413 | @Override |
| 10414 | public boolean isIccLockEnabled(int subId) { |
| 10415 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10416 | |
| 10417 | // Now that all security checks passes, perform the operation as ourselves. |
| 10418 | final long identity = Binder.clearCallingIdentity(); |
| 10419 | try { |
| 10420 | Phone phone = getPhone(subId); |
| 10421 | if (phone != null && phone.getIccCard() != null) { |
| 10422 | return phone.getIccCard().getIccLockEnabled(); |
| 10423 | } else { |
| 10424 | return false; |
| 10425 | } |
| 10426 | } finally { |
| 10427 | Binder.restoreCallingIdentity(identity); |
| 10428 | } |
| 10429 | } |
| 10430 | |
| 10431 | /** |
| 10432 | * Set the ICC pin lock enabled or disabled. |
| 10433 | * |
| 10434 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10435 | * three cases: |
| 10436 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10437 | * successfully. |
| 10438 | * - Positive number and zero for remaining password attempts. |
| 10439 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10440 | * |
| 10441 | */ |
| 10442 | @Override |
| 10443 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10444 | enforceModifyPermission(); |
| 10445 | |
| 10446 | Phone phone = getPhone(subId); |
| 10447 | if (phone == null) { |
| 10448 | return 0; |
| 10449 | } |
| 10450 | // Now that all security checks passes, perform the operation as ourselves. |
| 10451 | final long identity = Binder.clearCallingIdentity(); |
| 10452 | try { |
| 10453 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10454 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10455 | return attemptsRemaining; |
| 10456 | |
| 10457 | } catch (Exception e) { |
| 10458 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10459 | } finally { |
| 10460 | Binder.restoreCallingIdentity(identity); |
| 10461 | } |
| 10462 | return 0; |
| 10463 | } |
| 10464 | |
| 10465 | /** |
| 10466 | * Change the ICC password used in ICC pin lock. |
| 10467 | * |
| 10468 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10469 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10470 | * - Positive number and zero for remaining password attempts. |
| 10471 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10472 | * |
| 10473 | */ |
| 10474 | @Override |
| 10475 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10476 | enforceModifyPermission(); |
| 10477 | |
| 10478 | Phone phone = getPhone(subId); |
| 10479 | if (phone == null) { |
| 10480 | return 0; |
| 10481 | } |
| 10482 | // Now that all security checks passes, perform the operation as ourselves. |
| 10483 | final long identity = Binder.clearCallingIdentity(); |
| 10484 | try { |
| 10485 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10486 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10487 | return attemptsRemaining; |
| 10488 | |
| 10489 | } catch (Exception e) { |
| 10490 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10491 | } finally { |
| 10492 | Binder.restoreCallingIdentity(identity); |
| 10493 | } |
| 10494 | return 0; |
| 10495 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10496 | |
| 10497 | /** |
| 10498 | * Request for receiving user activity notification |
| 10499 | */ |
| 10500 | @Override |
| 10501 | public void requestUserActivityNotification() { |
| 10502 | if (!mNotifyUserActivity.get() |
| 10503 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10504 | mNotifyUserActivity.set(true); |
| 10505 | } |
| 10506 | } |
| 10507 | |
| 10508 | /** |
| 10509 | * Called when userActivity is signalled in the power manager. |
| 10510 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10511 | */ |
| 10512 | @Override |
| 10513 | public void userActivity() { |
| 10514 | // *************************************** |
| 10515 | // * Inherited from PhoneWindowManager * |
| 10516 | // *************************************** |
| 10517 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10518 | // WITH ITS LOCKS HELD. |
| 10519 | // |
| 10520 | // This code must be VERY careful about the locks |
| 10521 | // it acquires. |
| 10522 | // In fact, the current code acquires way too many, |
| 10523 | // and probably has lurking deadlocks. |
| 10524 | |
| 10525 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10526 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10527 | } |
| 10528 | |
| 10529 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10530 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10531 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10532 | } |
| 10533 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10534 | |
| 10535 | @Override |
| 10536 | public boolean canConnectTo5GInDsdsMode() { |
| 10537 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10538 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10539 | |
| 10540 | @Override |
| 10541 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10542 | String callingFeatureId) { |
| 10543 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10544 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10545 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10546 | } |
| 10547 | |
| 10548 | Phone phone = getPhone(subId); |
| 10549 | if (phone == null) { |
| 10550 | throw new RuntimeException("phone is not available"); |
| 10551 | } |
| 10552 | // Now that all security checks passes, perform the operation as ourselves. |
| 10553 | final long identity = Binder.clearCallingIdentity(); |
| 10554 | try { |
| 10555 | return phone.getEquivalentHomePlmns(); |
| 10556 | } finally { |
| 10557 | Binder.restoreCallingIdentity(identity); |
| 10558 | } |
| 10559 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10560 | |
| 10561 | @Override |
| 10562 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10563 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10564 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10565 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10566 | if (radioInterfaceCapabilities == null) { |
| 10567 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10568 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10569 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10570 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10571 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10572 | @Override |
| 10573 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10574 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10575 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10576 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10577 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10578 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10579 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10580 | if (DBG) { |
| 10581 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10582 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10583 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10584 | } |
| 10585 | |
| 10586 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10587 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10588 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10589 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10590 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10591 | if (callback != null) { |
| 10592 | try { |
| 10593 | callback.onAuthenticationFailure( |
| 10594 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10595 | } catch (RemoteException exception) { |
| 10596 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10597 | } |
| 10598 | return; |
| 10599 | } |
| 10600 | } |
| 10601 | |
| 10602 | final long token = Binder.clearCallingIdentity(); |
| 10603 | try { |
| 10604 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10605 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10606 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10607 | } finally { |
| 10608 | Binder.restoreCallingIdentity(token); |
| 10609 | } |
| 10610 | } |
| 10611 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10612 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10613 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10614 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10615 | * requested radio power state will actually be set. See {@link |
| 10616 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10617 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10618 | * @param enable {@code true} if trying to turn radio on. |
| 10619 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10620 | * false}. |
| 10621 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10622 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10623 | boolean isPhoneAvailable = false; |
| 10624 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10625 | Phone phone = PhoneFactory.getPhone(i); |
| 10626 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10627 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10628 | isPhoneAvailable = true; |
| 10629 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10630 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10631 | |
| 10632 | // return true if successfully informed the phone object about the thermal radio power |
| 10633 | // request. |
| 10634 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10635 | } |
| 10636 | |
| 10637 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10638 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10639 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10640 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10641 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10642 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10643 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10644 | } |
| 10645 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10646 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10647 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10648 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10649 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10650 | } |
| 10651 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10652 | setDataEnabledForReason( |
| 10653 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10654 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10655 | if (isDataThrottlingSupported) { |
| 10656 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10657 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10658 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10659 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10660 | } else if (thermalMitigationResult |
| 10661 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10662 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10663 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10664 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10665 | } |
| 10666 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10667 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10668 | |
| 10669 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10670 | } |
| 10671 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10672 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10673 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10674 | for (String pckg : context.getResources() |
| 10675 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10676 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10677 | } |
| 10678 | } |
| 10679 | |
| 10680 | return sThermalMitigationAllowlistedPackages; |
| 10681 | } |
| 10682 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10683 | private boolean isAnyPhoneInEmergencyState() { |
| 10684 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10685 | if (tm.isInEmergencyCall()) { |
| 10686 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10687 | return true; |
| 10688 | } |
| 10689 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10690 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10691 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10692 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10693 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10694 | return true; |
| 10695 | } |
| 10696 | } |
| 10697 | |
| 10698 | return false; |
| 10699 | } |
| 10700 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10701 | /** |
| 10702 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10703 | * @param packageName name of package to be allowlisted |
| 10704 | * @param context |
| 10705 | */ |
| 10706 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10707 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10708 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10709 | } |
| 10710 | |
| 10711 | /** |
| 10712 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10713 | * @param packageName name of package to remove from allowlist |
| 10714 | * @param context |
| 10715 | */ |
| 10716 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10717 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10718 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10719 | } |
| 10720 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10721 | /** |
| 10722 | * Thermal mitigation request to control functionalities at modem. |
| 10723 | * |
| 10724 | * @param subId the id of the subscription. |
| 10725 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10726 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10727 | * |
| 10728 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10729 | */ |
| 10730 | @Override |
| 10731 | @ThermalMitigationResult |
| 10732 | public int sendThermalMitigationRequest( |
| 10733 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10734 | ThermalMitigationRequest thermalMitigationRequest, |
| 10735 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10736 | enforceModifyPermission(); |
| 10737 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10738 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10739 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10740 | .contains(callingPackage)) { |
| 10741 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10742 | + "calling package: " + callingPackage); |
| 10743 | } |
| 10744 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10745 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10746 | final long identity = Binder.clearCallingIdentity(); |
| 10747 | |
| 10748 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10749 | try { |
| 10750 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10751 | switch (thermalMitigationAction) { |
| 10752 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10753 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10754 | handleDataThrottlingRequest(subId, |
| 10755 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10756 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10757 | break; |
| 10758 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10759 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10760 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10761 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10762 | } |
| 10763 | |
| 10764 | // Ensure that radio is on. If not able to power on due to phone being |
| 10765 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10766 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10767 | thermalMitigationResult = |
| 10768 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10769 | break; |
| 10770 | } |
| 10771 | |
| 10772 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10773 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10774 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10775 | break; |
| 10776 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10777 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10778 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10779 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10780 | } |
| 10781 | |
| 10782 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10783 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10784 | Phone phone = getPhone(subId); |
| 10785 | if (phone == null) { |
| 10786 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10787 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10788 | break; |
| 10789 | } |
| 10790 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10791 | TelephonyConnectionService service = |
| 10792 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10793 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10794 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10795 | thermalMitigationResult = |
| 10796 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10797 | break; |
| 10798 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10799 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10800 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10801 | break; |
| 10802 | } |
| 10803 | } else { |
| 10804 | thermalMitigationResult = |
| 10805 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10806 | break; |
| 10807 | } |
| 10808 | |
| 10809 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10810 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10811 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10812 | thermalMitigationResult = |
| 10813 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10814 | break; |
| 10815 | } |
| 10816 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10817 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10818 | break; |
| 10819 | default: |
| 10820 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10821 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10822 | } |
| 10823 | } catch (IllegalArgumentException e) { |
| 10824 | throw e; |
| 10825 | } catch (Exception e) { |
| 10826 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10827 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10828 | } finally { |
| 10829 | Binder.restoreCallingIdentity(identity); |
| 10830 | } |
| 10831 | |
| 10832 | if (DBG) { |
| 10833 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10834 | + thermalMitigationResult); |
| 10835 | } |
| 10836 | |
| 10837 | return thermalMitigationResult; |
| 10838 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10839 | |
| 10840 | /** |
| 10841 | * Set the GbaService Package Name that Telephony will bind to. |
| 10842 | * |
| 10843 | * @param subId The sim that the GbaService is associated with. |
| 10844 | * @param packageName The name of the package to be replaced with. |
| 10845 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10846 | */ |
| 10847 | @Override |
| 10848 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10849 | enforceModifyPermission(); |
| 10850 | |
| 10851 | final long identity = Binder.clearCallingIdentity(); |
| 10852 | try { |
| 10853 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10854 | } finally { |
| 10855 | Binder.restoreCallingIdentity(identity); |
| 10856 | } |
| 10857 | } |
| 10858 | |
| 10859 | /** |
| 10860 | * Return the package name of the currently bound GbaService. |
| 10861 | * |
| 10862 | * @param subId The sim that the GbaService is associated with. |
| 10863 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10864 | */ |
| 10865 | @Override |
| 10866 | public String getBoundGbaService(int subId) { |
| 10867 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10868 | |
| 10869 | final long identity = Binder.clearCallingIdentity(); |
| 10870 | try { |
| 10871 | return getGbaManager(subId).getServicePackage(); |
| 10872 | } finally { |
| 10873 | Binder.restoreCallingIdentity(identity); |
| 10874 | } |
| 10875 | } |
| 10876 | |
| 10877 | /** |
| 10878 | * Set the release time for telephony to unbind GbaService. |
| 10879 | * |
| 10880 | * @param subId The sim that the GbaService is associated with. |
| 10881 | * @param interval The release time to unbind GbaService by millisecond. |
| 10882 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10883 | */ |
| 10884 | @Override |
| 10885 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10886 | enforceModifyPermission(); |
| 10887 | |
| 10888 | final long identity = Binder.clearCallingIdentity(); |
| 10889 | try { |
| 10890 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10891 | } finally { |
| 10892 | Binder.restoreCallingIdentity(identity); |
| 10893 | } |
| 10894 | } |
| 10895 | |
| 10896 | /** |
| 10897 | * Return the release time for telephony to unbind GbaService. |
| 10898 | * |
| 10899 | * @param subId The sim that the GbaService is associated with. |
| 10900 | * @return The release time to unbind GbaService by millisecond. |
| 10901 | */ |
| 10902 | @Override |
| 10903 | public int getGbaReleaseTime(int subId) { |
| 10904 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10905 | |
| 10906 | final long identity = Binder.clearCallingIdentity(); |
| 10907 | try { |
| 10908 | return getGbaManager(subId).getReleaseTime(); |
| 10909 | } finally { |
| 10910 | Binder.restoreCallingIdentity(identity); |
| 10911 | } |
| 10912 | } |
| 10913 | |
| 10914 | private GbaManager getGbaManager(int subId) { |
| 10915 | GbaManager instance = GbaManager.getInstance(subId); |
| 10916 | if (instance == null) { |
| 10917 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10918 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10919 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10920 | } |
| 10921 | return instance; |
| 10922 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10923 | |
| 10924 | /** |
| 10925 | * indicate whether the device and the carrier can support |
| 10926 | * RCS VoLTE single registration. |
| 10927 | */ |
| 10928 | @Override |
| 10929 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10930 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10931 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10932 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10933 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10934 | |
| 10935 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10936 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10937 | } |
| 10938 | |
| 10939 | final long identity = Binder.clearCallingIdentity(); |
| 10940 | try { |
| 10941 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10942 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10943 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10944 | if (isCapable != null) { |
| 10945 | return isCapable; |
| 10946 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10947 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10948 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10949 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10950 | } finally { |
| 10951 | Binder.restoreCallingIdentity(identity); |
| 10952 | } |
| 10953 | } |
| 10954 | |
| 10955 | /** |
| 10956 | * Register RCS provisioning callback. |
| 10957 | */ |
| 10958 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10959 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10960 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10961 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10962 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10963 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10964 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10965 | |
| 10966 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10967 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10968 | } |
| 10969 | if (!isImsAvailableOnDevice()) { |
| 10970 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10971 | "IMS not available on device."); |
| 10972 | } |
| 10973 | |
| 10974 | final long identity = Binder.clearCallingIdentity(); |
| 10975 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10976 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10977 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10978 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10979 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10980 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10981 | } finally { |
| 10982 | Binder.restoreCallingIdentity(identity); |
| 10983 | } |
| 10984 | } |
| 10985 | |
| 10986 | /** |
| 10987 | * Unregister RCS provisioning callback. |
| 10988 | */ |
| 10989 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10990 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10991 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10992 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10993 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10994 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10995 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10996 | |
| 10997 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10998 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10999 | } |
| 11000 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11001 | // operation failed silently |
| 11002 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11003 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11004 | } |
| 11005 | |
| 11006 | final long identity = Binder.clearCallingIdentity(); |
| 11007 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11008 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11009 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11010 | } finally { |
| 11011 | Binder.restoreCallingIdentity(identity); |
| 11012 | } |
| 11013 | } |
| 11014 | |
| 11015 | /** |
| 11016 | * trigger RCS reconfiguration. |
| 11017 | */ |
| 11018 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11019 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11020 | "triggerRcsReconfiguration", |
| 11021 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11022 | |
| 11023 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11024 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11025 | } |
| 11026 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11027 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11028 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11029 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11030 | } |
| 11031 | |
| 11032 | final long identity = Binder.clearCallingIdentity(); |
| 11033 | try { |
| 11034 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11035 | } finally { |
| 11036 | Binder.restoreCallingIdentity(identity); |
| 11037 | } |
| 11038 | } |
| 11039 | |
| 11040 | /** |
| 11041 | * Provide the client configuration parameters of the RCS application. |
| 11042 | */ |
| 11043 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11044 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11045 | "setRcsClientConfiguration", |
| 11046 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11047 | |
| 11048 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11049 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11050 | } |
| 11051 | if (!isImsAvailableOnDevice()) { |
| 11052 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11053 | "IMS not available on device."); |
| 11054 | } |
| 11055 | |
| 11056 | final long identity = Binder.clearCallingIdentity(); |
| 11057 | |
| 11058 | try { |
| 11059 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11060 | if (configBinder == null) { |
| 11061 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11062 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11063 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11064 | } else { |
| 11065 | configBinder.setRcsClientConfiguration(rcc); |
| 11066 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11067 | |
| 11068 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11069 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11070 | } catch (RemoteException e) { |
| 11071 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11072 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11073 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11074 | } finally { |
| 11075 | Binder.restoreCallingIdentity(identity); |
| 11076 | } |
| 11077 | } |
| 11078 | |
| 11079 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11080 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11081 | */ |
| 11082 | @Override |
| 11083 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11084 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11085 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11086 | |
| 11087 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11088 | } |
| 11089 | |
| 11090 | /** |
| 11091 | * Gets the test mode for RCS VoLTE single registration. |
| 11092 | */ |
| 11093 | @Override |
| 11094 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11095 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11096 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11097 | |
| 11098 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11099 | } |
| 11100 | |
| 11101 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11102 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11103 | */ |
| 11104 | @Override |
| 11105 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11106 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11107 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11108 | enforceModifyPermission(); |
| 11109 | |
| 11110 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11111 | : Boolean.parseBoolean(enabledStr); |
| 11112 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11113 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11114 | } |
| 11115 | |
| 11116 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11117 | * Sends a device to device communication message. Only usable via shell. |
| 11118 | * @param message message to send. |
| 11119 | * @param value message value. |
| 11120 | */ |
| 11121 | @Override |
| 11122 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11123 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11124 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11125 | enforceModifyPermission(); |
| 11126 | |
| 11127 | final long identity = Binder.clearCallingIdentity(); |
| 11128 | try { |
| 11129 | TelephonyConnectionService service = |
| 11130 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11131 | if (service == null) { |
| 11132 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11133 | return; |
| 11134 | } |
| 11135 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11136 | } finally { |
| 11137 | Binder.restoreCallingIdentity(identity); |
| 11138 | } |
| 11139 | } |
| 11140 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11141 | /** |
| 11142 | * Sets the specified device to device transport active. |
| 11143 | * @param transport The transport to set active. |
| 11144 | */ |
| 11145 | @Override |
| 11146 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11147 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11148 | "setActiveDeviceToDeviceTransport"); |
| 11149 | enforceModifyPermission(); |
| 11150 | |
| 11151 | final long identity = Binder.clearCallingIdentity(); |
| 11152 | try { |
| 11153 | TelephonyConnectionService service = |
| 11154 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11155 | if (service == null) { |
| 11156 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11157 | return; |
| 11158 | } |
| 11159 | service.setActiveDeviceToDeviceTransport(transport); |
| 11160 | } finally { |
| 11161 | Binder.restoreCallingIdentity(identity); |
| 11162 | } |
| 11163 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11164 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11165 | @Override |
| 11166 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11167 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11168 | "setDeviceToDeviceForceEnabled"); |
| 11169 | |
| 11170 | final long identity = Binder.clearCallingIdentity(); |
| 11171 | try { |
| 11172 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11173 | p -> { |
| 11174 | Phone thePhone = p.getImsPhone(); |
| 11175 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11176 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11177 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11178 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11179 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11180 | (ImsPhoneCallTracker) tracker; |
| 11181 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11182 | } |
| 11183 | } |
| 11184 | } |
| 11185 | ); |
| 11186 | } finally { |
| 11187 | Binder.restoreCallingIdentity(identity); |
| 11188 | } |
| 11189 | } |
| 11190 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11191 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11192 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11193 | */ |
| 11194 | @Override |
| 11195 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11196 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11197 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11198 | } |
| 11199 | |
| 11200 | /** |
| 11201 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11202 | */ |
| 11203 | @Override |
| 11204 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11205 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11206 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11207 | enforceModifyPermission(); |
| 11208 | |
| 11209 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11210 | : Boolean.parseBoolean(enabledStr); |
| 11211 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11212 | subId, enabled); |
| 11213 | } |
| 11214 | |
| 11215 | /** |
| 11216 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11217 | */ |
| 11218 | @Override |
| 11219 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11220 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11221 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11222 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11223 | |
| 11224 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11225 | * Overrides the ims feature validation result |
| 11226 | */ |
| 11227 | @Override |
| 11228 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11229 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11230 | "setImsFeatureValidationOverride"); |
| 11231 | |
| 11232 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11233 | : Boolean.parseBoolean(enabledStr); |
| 11234 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11235 | subId, enabled); |
| 11236 | } |
| 11237 | |
| 11238 | /** |
| 11239 | * Gets the ims feature validation override value |
| 11240 | */ |
| 11241 | @Override |
| 11242 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11243 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11244 | "getImsFeatureValidationOverride"); |
| 11245 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11246 | } |
| 11247 | |
| 11248 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11249 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11250 | * their mobile plan. |
| 11251 | */ |
| 11252 | @Override |
| 11253 | public String getMobileProvisioningUrl() { |
| 11254 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11255 | final long identity = Binder.clearCallingIdentity(); |
| 11256 | try { |
| 11257 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11258 | } finally { |
| 11259 | Binder.restoreCallingIdentity(identity); |
| 11260 | } |
| 11261 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11262 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11263 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11264 | * Get the EAB contact from the EAB database. |
| 11265 | */ |
| 11266 | @Override |
| 11267 | public String getContactFromEab(String contact) { |
| 11268 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11269 | enforceModifyPermission(); |
| 11270 | final long identity = Binder.clearCallingIdentity(); |
| 11271 | try { |
| 11272 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11273 | } finally { |
| 11274 | Binder.restoreCallingIdentity(identity); |
| 11275 | } |
| 11276 | } |
| 11277 | |
| 11278 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11279 | * Get the EAB capability from the EAB database. |
| 11280 | */ |
| 11281 | @Override |
| 11282 | public String getCapabilityFromEab(String contact) { |
| 11283 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11284 | enforceModifyPermission(); |
| 11285 | final long identity = Binder.clearCallingIdentity(); |
| 11286 | try { |
| 11287 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11288 | } finally { |
| 11289 | Binder.restoreCallingIdentity(identity); |
| 11290 | } |
| 11291 | } |
| 11292 | |
| 11293 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11294 | * Remove the EAB contacts from the EAB database. |
| 11295 | */ |
| 11296 | @Override |
| 11297 | public int removeContactFromEab(int subId, String contacts) { |
| 11298 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11299 | enforceModifyPermission(); |
| 11300 | final long identity = Binder.clearCallingIdentity(); |
| 11301 | try { |
| 11302 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11303 | } finally { |
| 11304 | Binder.restoreCallingIdentity(identity); |
| 11305 | } |
| 11306 | } |
| 11307 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11308 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11309 | public boolean getDeviceUceEnabled() { |
| 11310 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11311 | final long identity = Binder.clearCallingIdentity(); |
| 11312 | try { |
| 11313 | return mApp.getDeviceUceEnabled(); |
| 11314 | } finally { |
| 11315 | Binder.restoreCallingIdentity(identity); |
| 11316 | } |
| 11317 | } |
| 11318 | |
| 11319 | @Override |
| 11320 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11321 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11322 | final long identity = Binder.clearCallingIdentity(); |
| 11323 | try { |
| 11324 | mApp.setDeviceUceEnabled(isEnabled); |
| 11325 | } finally { |
| 11326 | Binder.restoreCallingIdentity(identity); |
| 11327 | } |
| 11328 | } |
| 11329 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11330 | /** |
| 11331 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11332 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11333 | */ |
| 11334 | // Used for SHELL command only right now. |
| 11335 | @Override |
| 11336 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11337 | List<String> featureTags) { |
| 11338 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11339 | "addUceRegistrationOverrideShell"); |
| 11340 | final long identity = Binder.clearCallingIdentity(); |
| 11341 | try { |
| 11342 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11343 | new ArraySet<>(featureTags)); |
| 11344 | } catch (ImsException e) { |
| 11345 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11346 | } finally { |
| 11347 | Binder.restoreCallingIdentity(identity); |
| 11348 | } |
| 11349 | } |
| 11350 | |
| 11351 | /** |
| 11352 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11353 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11354 | */ |
| 11355 | // Used for SHELL command only right now. |
| 11356 | @Override |
| 11357 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11358 | List<String> featureTags) { |
| 11359 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11360 | "removeUceRegistrationOverrideShell"); |
| 11361 | final long identity = Binder.clearCallingIdentity(); |
| 11362 | try { |
| 11363 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11364 | new ArraySet<>(featureTags)); |
| 11365 | } catch (ImsException e) { |
| 11366 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11367 | } finally { |
| 11368 | Binder.restoreCallingIdentity(identity); |
| 11369 | } |
| 11370 | } |
| 11371 | |
| 11372 | /** |
| 11373 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11374 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11375 | */ |
| 11376 | // Used for SHELL command only right now. |
| 11377 | @Override |
| 11378 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11379 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11380 | "clearUceRegistrationOverrideShell"); |
| 11381 | final long identity = Binder.clearCallingIdentity(); |
| 11382 | try { |
| 11383 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11384 | } catch (ImsException e) { |
| 11385 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11386 | } finally { |
| 11387 | Binder.restoreCallingIdentity(identity); |
| 11388 | } |
| 11389 | } |
| 11390 | |
| 11391 | /** |
| 11392 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11393 | */ |
| 11394 | // Used for SHELL command only right now. |
| 11395 | @Override |
| 11396 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11397 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11398 | "getLatestRcsContactUceCapabilityShell"); |
| 11399 | final long identity = Binder.clearCallingIdentity(); |
| 11400 | try { |
| 11401 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11402 | } catch (ImsException e) { |
| 11403 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11404 | } finally { |
| 11405 | Binder.restoreCallingIdentity(identity); |
| 11406 | } |
| 11407 | } |
| 11408 | |
| 11409 | /** |
| 11410 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11411 | * device does not have an active PUBLISH. |
| 11412 | */ |
| 11413 | // Used for SHELL command only right now. |
| 11414 | @Override |
| 11415 | public String getLastUcePidfXmlShell(int subId) { |
| 11416 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11417 | final long identity = Binder.clearCallingIdentity(); |
| 11418 | try { |
| 11419 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11420 | } catch (ImsException e) { |
| 11421 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11422 | } finally { |
| 11423 | Binder.restoreCallingIdentity(identity); |
| 11424 | } |
| 11425 | } |
| 11426 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11427 | /** |
| 11428 | * Remove UCE requests cannot be sent to the network status. |
| 11429 | */ |
| 11430 | // Used for SHELL command only right now. |
| 11431 | @Override |
| 11432 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11433 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11434 | final long identity = Binder.clearCallingIdentity(); |
| 11435 | try { |
| 11436 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11437 | } catch (ImsException e) { |
| 11438 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11439 | } finally { |
| 11440 | Binder.restoreCallingIdentity(identity); |
| 11441 | } |
| 11442 | } |
| 11443 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11444 | /** |
| 11445 | * Remove UCE requests cannot be sent to the network status. |
| 11446 | */ |
| 11447 | // Used for SHELL command only. |
| 11448 | @Override |
| 11449 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11450 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11451 | final long identity = Binder.clearCallingIdentity(); |
| 11452 | try { |
| 11453 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11454 | } catch (ImsException e) { |
| 11455 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11456 | } finally { |
| 11457 | Binder.restoreCallingIdentity(identity); |
| 11458 | } |
| 11459 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11460 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11461 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11462 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11463 | String callingPackage) { |
| 11464 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11465 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11466 | |
| 11467 | final int callingUid = Binder.getCallingUid(); |
| 11468 | // Verify that tha callingPackage belongs to the calling UID |
| 11469 | mApp.getSystemService(AppOpsManager.class) |
| 11470 | .checkPackage(callingUid, callingPackage); |
| 11471 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11472 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11473 | |
| 11474 | final long identity = Binder.clearCallingIdentity(); |
| 11475 | try { |
| 11476 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11477 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11478 | |
| 11479 | if (result instanceof IllegalStateException) { |
| 11480 | throw (IllegalStateException) result; |
| 11481 | } |
| 11482 | } finally { |
| 11483 | Binder.restoreCallingIdentity(identity); |
| 11484 | } |
| 11485 | } |
| 11486 | |
| 11487 | @Override |
| 11488 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11489 | String callingPackage) { |
| 11490 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11491 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11492 | |
| 11493 | final int callingUid = Binder.getCallingUid(); |
| 11494 | // Verify that tha callingPackage belongs to the calling UID |
| 11495 | mApp.getSystemService(AppOpsManager.class) |
| 11496 | .checkPackage(callingUid, callingPackage); |
| 11497 | |
| 11498 | final long identity = Binder.clearCallingIdentity(); |
| 11499 | try { |
| 11500 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11501 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11502 | |
| 11503 | if (result instanceof IllegalStateException) { |
| 11504 | throw (IllegalStateException) result; |
| 11505 | } |
| 11506 | } finally { |
| 11507 | Binder.restoreCallingIdentity(identity); |
| 11508 | } |
| 11509 | } |
| 11510 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11511 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11512 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11513 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11514 | // phone/system process do not have further restriction on request |
| 11515 | return; |
| 11516 | } |
| 11517 | |
| 11518 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11519 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11520 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11521 | context.enforceCallingOrSelfPermission( |
| 11522 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11523 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11524 | } |
| 11525 | |
| 11526 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11527 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11528 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11529 | || info.isEnabled()) { |
| 11530 | throw new IllegalArgumentException( |
| 11531 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11532 | } |
| 11533 | |
| 11534 | // Thresholds length for each RAN need in range. This has been validated in |
| 11535 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11536 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11537 | final int[] thresholds = info.getThresholds(); |
| 11538 | Objects.requireNonNull(thresholds); |
| 11539 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11540 | || thresholds.length |
| 11541 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11542 | throw new IllegalArgumentException( |
| 11543 | "thresholds length is out of range: " + thresholds.length); |
| 11544 | } |
| 11545 | } |
| 11546 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11547 | |
| 11548 | /** |
| 11549 | * Gets the current phone capability. |
| 11550 | * |
| 11551 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11552 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11553 | * It's used to evaluate possible phone config change, for example from single |
| 11554 | * SIM device to multi-SIM device. |
| 11555 | */ |
| 11556 | @Override |
| 11557 | public PhoneCapability getPhoneCapability() { |
| 11558 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11559 | final long identity = Binder.clearCallingIdentity(); |
| 11560 | try { |
| 11561 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11562 | } finally { |
| 11563 | Binder.restoreCallingIdentity(identity); |
| 11564 | } |
| 11565 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11566 | |
| 11567 | /** |
| 11568 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11569 | * required to be done shortly after the API is invoked. |
| 11570 | */ |
| 11571 | @Override |
| 11572 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11573 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11574 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11575 | enforceRebootPermission(); |
| 11576 | |
| 11577 | final long identity = Binder.clearCallingIdentity(); |
| 11578 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11579 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11580 | } finally { |
| 11581 | Binder.restoreCallingIdentity(identity); |
| 11582 | } |
| 11583 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11584 | |
| 11585 | /** |
| 11586 | * Request to get the current slicing configuration including URSP rules and |
| 11587 | * NSSAIs (configured, allowed and rejected). |
| 11588 | * |
| 11589 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11590 | */ |
| 11591 | @Override |
| 11592 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11593 | TelephonyPermissions |
| 11594 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11595 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11596 | |
| 11597 | final long identity = Binder.clearCallingIdentity(); |
| 11598 | try { |
| 11599 | Phone phone = getDefaultPhone(); |
| 11600 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11601 | } finally { |
| 11602 | Binder.restoreCallingIdentity(identity); |
| 11603 | } |
| 11604 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11605 | |
| 11606 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11607 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11608 | * |
| 11609 | * @param capability The premium capability to check. |
| 11610 | * @param subId The subId to check the premium capability for. |
| 11611 | * |
| 11612 | * @return Whether the given premium capability is available to purchase. |
| 11613 | */ |
| 11614 | @Override |
| 11615 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11616 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11617 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11618 | log("Premium capability " |
| 11619 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11620 | + " is not available for purchase due to missing permissions."); |
| 11621 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11622 | + "permission READ_BASIC_PHONE_STATE."); |
| 11623 | } |
| 11624 | |
| 11625 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11626 | if (phone == null) { |
| 11627 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11628 | return false; |
| 11629 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11630 | final long identity = Binder.clearCallingIdentity(); |
| 11631 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 11632 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11633 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11634 | } finally { |
| 11635 | Binder.restoreCallingIdentity(identity); |
| 11636 | } |
| 11637 | } |
| 11638 | |
| 11639 | /** |
| 11640 | * Purchase the given premium capability from the carrier. |
| 11641 | * |
| 11642 | * @param capability The premium capability to purchase. |
| 11643 | * @param callback The result of the purchase request. |
| 11644 | * @param subId The subId to purchase the premium capability for. |
| 11645 | */ |
| 11646 | @Override |
| 11647 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11648 | log("purchasePremiumCapability: capability=" |
| 11649 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11650 | + getCurrentPackageName()); |
| 11651 | |
| 11652 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11653 | mApp, "purchasePremiumCapability")) { |
| 11654 | log("purchasePremiumCapability " |
| 11655 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11656 | + " failed due to missing permissions."); |
| 11657 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11658 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11659 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11660 | mApp, "purchasePremiumCapability")) { |
| 11661 | log("purchasePremiumCapability " |
| 11662 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11663 | + " failed due to missing permissions."); |
| 11664 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11665 | } |
| 11666 | |
| 11667 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11668 | if (phone == null) { |
| 11669 | try { |
| 11670 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11671 | callback.accept(result); |
| 11672 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11673 | } catch (RemoteException e) { |
| 11674 | String logStr = "Purchase premium capability " |
| 11675 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11676 | + " failed due to RemoteException handling null phone: " + e; |
| 11677 | if (DBG) log(logStr); |
| 11678 | AnomalyReporter.reportAnomaly( |
| 11679 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11680 | } |
| 11681 | return; |
| 11682 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11683 | |
| 11684 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11685 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11686 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11687 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11688 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11689 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11690 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11691 | |
| 11692 | boolean isVisible = false; |
| 11693 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11694 | if (am != null) { |
| 11695 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11696 | if (processes != null) { |
| 11697 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11698 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 11699 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11700 | if (process.processName.equals(callingProcess) && process.importance |
| 11701 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11702 | isVisible = true; |
| 11703 | break; |
| 11704 | } |
| 11705 | } |
| 11706 | } |
| 11707 | } |
| 11708 | |
| 11709 | if (!isVisible) { |
| 11710 | try { |
| 11711 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11712 | callback.accept(result); |
| 11713 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11714 | } catch (RemoteException e) { |
| 11715 | String logStr = "Purchase premium capability " |
| 11716 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11717 | + " failed due to RemoteException handling background application: " + e; |
| 11718 | if (DBG) log(logStr); |
| 11719 | AnomalyReporter.reportAnomaly( |
| 11720 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11721 | } |
| 11722 | return; |
| 11723 | } |
| 11724 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11725 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11726 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11727 | } |
| 11728 | |
| 11729 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11730 | * Register an IMS connection state callback |
| 11731 | */ |
| 11732 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11733 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11734 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11735 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11736 | // ImsMmTelManager |
| 11737 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11738 | TelephonyPermissions |
| 11739 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11740 | mApp, subId, "registerImsStateCallback"); |
| 11741 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11742 | // ImsRcsManager or SipDelegateManager |
| 11743 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11744 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11745 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11746 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11747 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11748 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11749 | } |
| 11750 | |
| 11751 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11752 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11753 | "IMS not available on device."); |
| 11754 | } |
| 11755 | |
| 11756 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11757 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11758 | } |
| 11759 | |
| 11760 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11761 | if (controller == null) { |
| 11762 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11763 | "IMS not available on device."); |
| 11764 | } |
| 11765 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11766 | if (callingPackage == null) { |
| 11767 | callingPackage = getCurrentPackageName(); |
| 11768 | } |
| 11769 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11770 | final long token = Binder.clearCallingIdentity(); |
| 11771 | try { |
| 11772 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11773 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11774 | } catch (ImsException e) { |
| 11775 | throw new ServiceSpecificException(e.getCode()); |
| 11776 | } finally { |
| 11777 | Binder.restoreCallingIdentity(token); |
| 11778 | } |
| 11779 | } |
| 11780 | |
| 11781 | /** |
| 11782 | * Unregister an IMS connection state callback |
| 11783 | */ |
| 11784 | @Override |
| 11785 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11786 | final long token = Binder.clearCallingIdentity(); |
| 11787 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11788 | if (controller == null) { |
| 11789 | return; |
| 11790 | } |
| 11791 | try { |
| 11792 | controller.unregisterImsStateCallback(cb); |
| 11793 | } finally { |
| 11794 | Binder.restoreCallingIdentity(token); |
| 11795 | } |
| 11796 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11797 | |
| 11798 | /** |
| 11799 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11800 | * |
| 11801 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11802 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11803 | * SecurityException. |
| 11804 | * If there is current registered network this value will be same as the registered cell |
| 11805 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11806 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11807 | * it will be cleared and null will be returned. |
| 11808 | * |
| 11809 | */ |
| 11810 | @Override |
| 11811 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11812 | String callingFeatureId) { |
| 11813 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11814 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11815 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11816 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11817 | .setCallingPackage(callingPackage) |
| 11818 | .setCallingFeatureId(callingFeatureId) |
| 11819 | .setCallingPid(Binder.getCallingPid()) |
| 11820 | .setCallingUid(Binder.getCallingUid()) |
| 11821 | .setMethod("getLastKnownCellIdentity") |
| 11822 | .setLogAsInfo(true) |
| 11823 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11824 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11825 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11826 | .build()); |
| 11827 | |
| 11828 | boolean hasFinePermission = |
| 11829 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11830 | if (!hasFinePermission |
| 11831 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11832 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11833 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11834 | } |
| 11835 | |
| 11836 | final long identity = Binder.clearCallingIdentity(); |
| 11837 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11838 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11839 | if (sst == null) return null; |
| 11840 | return sst.getLastKnownCellIdentity(); |
| 11841 | } finally { |
| 11842 | Binder.restoreCallingIdentity(identity); |
| 11843 | } |
| 11844 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11845 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11846 | /** |
| 11847 | * Sets the modem service class Name that Telephony will bind to. |
| 11848 | * |
| 11849 | * @param serviceName The class name of the modem service. |
| 11850 | * @return true if the operation is succeed, otherwise false. |
| 11851 | */ |
| 11852 | public boolean setModemService(String serviceName) { |
| 11853 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11854 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11856 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11857 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11858 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11859 | } |
| 11860 | |
| 11861 | /** |
| 11862 | * Return the class name of the currently bounded modem service. |
| 11863 | * |
| 11864 | * @return the class name of the modem service. |
| 11865 | */ |
| 11866 | public String getModemService() { |
| 11867 | String result; |
| 11868 | Log.d(LOG_TAG, "getModemService"); |
| 11869 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11870 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11871 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11872 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11873 | "getModemService"); |
| 11874 | result = mPhoneConfigurationManager.getModemService(); |
| 11875 | Log.d(LOG_TAG, "result = " + result); |
| 11876 | return result; |
| 11877 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11878 | |
| 11879 | @Override |
| 11880 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11881 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11882 | mApp.enforceCallingOrSelfPermission( |
| 11883 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11884 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11885 | |
| 11886 | final long identity = Binder.clearCallingIdentity(); |
| 11887 | try { |
| 11888 | Phone phone = getPhone(subId); |
| 11889 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11890 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11891 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11892 | phone.setVoiceServiceStateOverride(hasService); |
| 11893 | } finally { |
| 11894 | Binder.restoreCallingIdentity(identity); |
| 11895 | } |
| 11896 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11897 | |
| 11898 | /** |
| 11899 | * set removable eSIM as default eUICC. |
| 11900 | * |
| 11901 | * @hide |
| 11902 | */ |
| 11903 | @Override |
| 11904 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11905 | enforceModifyPermission(); |
| 11906 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11907 | |
| 11908 | final long identity = Binder.clearCallingIdentity(); |
| 11909 | try { |
| 11910 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11911 | } finally { |
| 11912 | Binder.restoreCallingIdentity(identity); |
| 11913 | } |
| 11914 | } |
| 11915 | |
| 11916 | /** |
| 11917 | * Returns whether the removable eSIM is default eUICC or not. |
| 11918 | * |
| 11919 | * @hide |
| 11920 | */ |
| 11921 | @Override |
| 11922 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11923 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11924 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11925 | |
| 11926 | final long identity = Binder.clearCallingIdentity(); |
| 11927 | try { |
| 11928 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11929 | } finally { |
| 11930 | Binder.restoreCallingIdentity(identity); |
| 11931 | } |
| 11932 | } |
| 11933 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11934 | /** |
| 11935 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11936 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11937 | * application currently configured for this user. |
| 11938 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11939 | * {@code null} if the functionality is not supported. |
| 11940 | * @hide |
| 11941 | */ |
| 11942 | @Override |
| 11943 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11944 | boolean updateIfNeeded) { |
| 11945 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11946 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11947 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11948 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11949 | UserHandle userHandle = null; |
| 11950 | final long identity = Binder.clearCallingIdentity(); |
| 11951 | try { |
| 11952 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11953 | } finally { |
| 11954 | Binder.restoreCallingIdentity(identity); |
| 11955 | } |
| 11956 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11957 | updateIfNeeded, userHandle); |
| 11958 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11959 | |
| 11960 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11961 | * Set whether the device is able to connect with null ciphering or integrity |
| 11962 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11963 | * and all new subscriptions after this. |
| 11964 | * |
| 11965 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11966 | * @hide |
| 11967 | */ |
| 11968 | @Override |
| 11969 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11970 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11971 | enforceModifyPermission(); |
| 11972 | checkForNullCipherAndIntegritySupport(); |
| 11973 | |
| 11974 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11975 | // for listening to these preference changes and applying them immediately. |
| 11976 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11977 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11978 | editor.apply(); |
| 11979 | |
| 11980 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11981 | phone.handleNullCipherEnabledChange(); |
| 11982 | } |
| 11983 | } |
| 11984 | |
| 11985 | |
| 11986 | /** |
| 11987 | * Get whether the device is able to connect with null ciphering or integrity |
| 11988 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11989 | * the state of the radio. |
| 11990 | * |
| 11991 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11992 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11993 | * version for this feature. |
| 11994 | * @hide |
| 11995 | */ |
| 11996 | @Override |
| 11997 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11998 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11999 | enforceReadPermission(); |
| 12000 | checkForNullCipherAndIntegritySupport(); |
| 12001 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12002 | } |
| 12003 | |
| 12004 | private void checkForNullCipherAndIntegritySupport() { |
| 12005 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12006 | throw new UnsupportedOperationException( |
| 12007 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12008 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12009 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12010 | throw new UnsupportedOperationException( |
| 12011 | "Null cipher and integrity operations unsupported by modem"); |
| 12012 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12013 | } |
| 12014 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12015 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12016 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12017 | throw new UnsupportedOperationException( |
| 12018 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12019 | + "above"); |
| 12020 | } |
| 12021 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12022 | throw new UnsupportedOperationException( |
| 12023 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12024 | } |
| 12025 | } |
| 12026 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame^] | 12027 | private void checkForNullCipherNotificationSupport() { |
| 12028 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12029 | throw new UnsupportedOperationException( |
| 12030 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12031 | } |
| 12032 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12033 | throw new UnsupportedOperationException( |
| 12034 | "Null cipher notification operations unsupported by modem"); |
| 12035 | } |
| 12036 | } |
| 12037 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12038 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12039 | * Get the SIM state for the slot index. |
| 12040 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12041 | * |
| 12042 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12043 | */ |
| 12044 | @Override |
| 12045 | @SimState |
| 12046 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12047 | IccCardConstants.State simState; |
| 12048 | if (slotIndex < 0) { |
| 12049 | simState = IccCardConstants.State.UNKNOWN; |
| 12050 | } else { |
| 12051 | Phone phone = null; |
| 12052 | try { |
| 12053 | phone = PhoneFactory.getPhone(slotIndex); |
| 12054 | } catch (IllegalStateException e) { |
| 12055 | // ignore |
| 12056 | } |
| 12057 | if (phone == null) { |
| 12058 | simState = IccCardConstants.State.UNKNOWN; |
| 12059 | } else { |
| 12060 | IccCard icc = phone.getIccCard(); |
| 12061 | if (icc == null) { |
| 12062 | simState = IccCardConstants.State.UNKNOWN; |
| 12063 | } else { |
| 12064 | simState = icc.getState(); |
| 12065 | } |
| 12066 | } |
| 12067 | } |
| 12068 | return simState.ordinal(); |
| 12069 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12070 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12071 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12072 | boolean enableLogcat, |
| 12073 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12074 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12075 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 12076 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 12077 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 12078 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 12079 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 12080 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 12081 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 12082 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12083 | Executors.newCachedThreadPool(), db, |
| 12084 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 12085 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12086 | } |
| 12087 | |
| 12088 | /** |
| 12089 | * Request telephony to persist state for debugging emergency call failures. |
| 12090 | * |
| 12091 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 12092 | * @param enableLogcat whether to collect logcat output |
| 12093 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12094 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12095 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12096 | */ |
| 12097 | @Override |
| 12098 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12099 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12100 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12101 | boolean enableTelephonyDump) { |
| 12102 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12103 | "persistEmergencyCallDiagnosticData"); |
| 12104 | final long identity = Binder.clearCallingIdentity(); |
| 12105 | try { |
| 12106 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12107 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12108 | |
| 12109 | } finally { |
| 12110 | Binder.restoreCallingIdentity(identity); |
| 12111 | } |
| 12112 | } |
| 12113 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12114 | /** |
| 12115 | * Get current cell broadcast ranges. |
| 12116 | */ |
| 12117 | @Override |
| 12118 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12119 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12120 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12121 | "getCellBroadcastIdRanges"); |
| 12122 | final long identity = Binder.clearCallingIdentity(); |
| 12123 | try { |
| 12124 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12125 | } finally { |
| 12126 | Binder.restoreCallingIdentity(identity); |
| 12127 | } |
| 12128 | } |
| 12129 | |
| 12130 | /** |
| 12131 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12132 | * |
| 12133 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12134 | */ |
| 12135 | @Override |
| 12136 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12137 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12138 | @Nullable IIntegerConsumer callback) { |
| 12139 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12140 | "setCellBroadcastIdRanges"); |
| 12141 | final long identity = Binder.clearCallingIdentity(); |
| 12142 | try { |
| 12143 | Phone phone = getPhoneFromSubId(subId); |
| 12144 | if (DBG) { |
| 12145 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12146 | } |
| 12147 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12148 | if (callback != null) { |
| 12149 | try { |
| 12150 | callback.accept(result); |
| 12151 | } catch (RemoteException e) { |
| 12152 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12153 | } |
| 12154 | } |
| 12155 | }); |
| 12156 | } finally { |
| 12157 | Binder.restoreCallingIdentity(identity); |
| 12158 | } |
| 12159 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12160 | |
| 12161 | /** |
| 12162 | * Returns whether the device supports the domain selection service. |
| 12163 | * |
| 12164 | * @return {@code true} if the device supports the domain selection service. |
| 12165 | */ |
| 12166 | @Override |
| 12167 | public boolean isDomainSelectionSupported() { |
| 12168 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12169 | "isDomainSelectionSupported"); |
| 12170 | |
| 12171 | final long identity = Binder.clearCallingIdentity(); |
| 12172 | try { |
| 12173 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12174 | } finally { |
| 12175 | Binder.restoreCallingIdentity(identity); |
| 12176 | } |
| 12177 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12178 | |
| 12179 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12180 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12181 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12182 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12183 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12184 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12185 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12186 | * {@code false} to disable. |
| 12187 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12188 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12189 | * |
| 12190 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12191 | */ |
| 12192 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12193 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12194 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12195 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12196 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12197 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12198 | } |
| 12199 | |
| 12200 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12201 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12202 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12203 | * @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] | 12204 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12205 | * 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] | 12206 | * |
| 12207 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12208 | */ |
| 12209 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12210 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12211 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12212 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12213 | } |
| 12214 | |
| 12215 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12216 | * Request to get whether the satellite service demo mode is enabled. |
| 12217 | * |
| 12218 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12219 | * is enabled for. |
| 12220 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12221 | * if the request is successful or an error code if the request failed. |
| 12222 | * |
| 12223 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12224 | */ |
| 12225 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12226 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12227 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12228 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12229 | } |
| 12230 | |
| 12231 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12232 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12233 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12234 | * @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] | 12235 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12236 | * 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] | 12237 | */ |
| 12238 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12239 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12240 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12241 | } |
| 12242 | |
| 12243 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12244 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12245 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12246 | * @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] | 12247 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12248 | * 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] | 12249 | * |
| 12250 | * @throws SecurityException if the caller doesn't have required permission. |
| 12251 | */ |
| 12252 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12253 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12254 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12255 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12256 | } |
| 12257 | |
| 12258 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12259 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12260 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12261 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12262 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12263 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12264 | * @param resultCallback The callback to get the result of the request. |
| 12265 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12266 | * |
| 12267 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12268 | */ |
| 12269 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12270 | public void startSatelliteTransmissionUpdates(int subId, |
| 12271 | @NonNull IIntegerConsumer resultCallback, |
| 12272 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12273 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12274 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12275 | } |
| 12276 | |
| 12277 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12278 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12279 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12280 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12281 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12282 | * @param resultCallback The callback to get the result of the request. |
| 12283 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12284 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12285 | * |
| 12286 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12287 | */ |
| 12288 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12289 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12290 | @NonNull IIntegerConsumer resultCallback, |
| 12291 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12292 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12293 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12294 | } |
| 12295 | |
| 12296 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12297 | * Register the subscription with a satellite provider. |
| 12298 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12299 | * |
| 12300 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12301 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12302 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12303 | * @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] | 12304 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12305 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12306 | * @return The signal transport used by the caller to cancel the provision request, |
| 12307 | * or {@code null} if the request failed. |
| 12308 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12309 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12310 | */ |
| 12311 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12312 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12313 | @NonNull String token, @NonNull byte[] provisionData, |
| 12314 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12315 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12316 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 12317 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12318 | } |
| 12319 | |
| 12320 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12321 | * Unregister the device/subscription with the satellite provider. |
| 12322 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12323 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12324 | * should report as deprovisioned. |
| 12325 | * |
| 12326 | * @param subId The subId of the subscription to be deprovisioned. |
| 12327 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12328 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12329 | * |
| 12330 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12331 | */ |
| 12332 | @Override |
| 12333 | public void deprovisionSatelliteService(int subId, |
| 12334 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12335 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12336 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12337 | } |
| 12338 | |
| 12339 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12340 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12341 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12342 | * @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] | 12343 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12344 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12345 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12346 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12347 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12348 | */ |
| 12349 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12350 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 12351 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12352 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12353 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12354 | } |
| 12355 | |
| 12356 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12357 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12358 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12359 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12360 | * @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] | 12361 | * @param callback The callback that was passed to |
| 12362 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12363 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12364 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12365 | */ |
| 12366 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12367 | public void unregisterForSatelliteProvisionStateChanged( |
| 12368 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12369 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12370 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12371 | } |
| 12372 | |
| 12373 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12374 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12375 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12376 | * @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] | 12377 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12378 | * satellite provider if the request is successful or an error code if the |
| 12379 | * request failed. |
| 12380 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12381 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12382 | */ |
| 12383 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12384 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12385 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12386 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12387 | } |
| 12388 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12389 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12390 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12391 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12392 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12393 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12394 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12395 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12396 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12397 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12398 | */ |
| 12399 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12400 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12401 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12402 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12403 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12404 | } |
| 12405 | |
| 12406 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12407 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12408 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12409 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12410 | * @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] | 12411 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12412 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12413 | * |
| 12414 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12415 | */ |
| 12416 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12417 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12418 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12419 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12420 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12421 | } |
| 12422 | |
| 12423 | /** |
| 12424 | * Register to receive incoming datagrams over satellite. |
| 12425 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12426 | * @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] | 12427 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12428 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12429 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12430 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12431 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12432 | */ |
| 12433 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12434 | @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12435 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12436 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12437 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12438 | } |
| 12439 | |
| 12440 | /** |
| 12441 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12442 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12443 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12444 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12445 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12446 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12447 | * |
| 12448 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12449 | */ |
| 12450 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12451 | public void unregisterForSatelliteDatagram(int subId, |
| 12452 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12453 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12454 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12455 | } |
| 12456 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12457 | /** |
| 12458 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12459 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12460 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12461 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 12462 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12463 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12464 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12465 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12466 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12467 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12468 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12469 | @Override |
| 12470 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12471 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12472 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12473 | } |
| 12474 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12475 | /** |
| 12476 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12477 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12478 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 12479 | * input to this method. Datagram received here will be passed down to modem without any |
| 12480 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12481 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12482 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 12483 | * @param datagramType datagram type indicating whether the datagram is of type |
| 12484 | * SOS_SMS or LOCATION_SHARING. |
| 12485 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 12486 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12487 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 12488 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12489 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12490 | * |
| 12491 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12492 | */ |
| 12493 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12494 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 12495 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 12496 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12497 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12498 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 12499 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12500 | } |
| 12501 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12502 | /** |
| 12503 | * Request to get whether satellite communication is allowed for the current location. |
| 12504 | * |
| 12505 | * @param subId The subId of the subscription to check whether satellite communication is |
| 12506 | * allowed for the current location for. |
| 12507 | * @param result The result receiver that returns whether satellite communication is allowed |
| 12508 | * for the current location if the request is successful or an error code |
| 12509 | * if the request failed. |
| 12510 | * |
| 12511 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12512 | */ |
| 12513 | @Override |
| 12514 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 12515 | @NonNull ResultReceiver result) { |
| 12516 | enforceSatelliteCommunicationPermission( |
| 12517 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12518 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 12519 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12520 | } |
| 12521 | |
| 12522 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12523 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12524 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12525 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12526 | * @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] | 12527 | * be visible if the request is successful or an error code if the request failed. |
| 12528 | * |
| 12529 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12530 | */ |
| 12531 | @Override |
| 12532 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 12533 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12534 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12535 | } |
| 12536 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12537 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12538 | * Inform that Device is aligned to satellite for demo mode. |
| 12539 | * |
| 12540 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12541 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 12542 | * {@code false} Device fails to align with the satellite for demo mode. |
| 12543 | * |
| 12544 | * @throws SecurityException if the caller doesn't have required permission. |
| 12545 | */ |
| 12546 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 12547 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12548 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12549 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12550 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12551 | } |
| 12552 | |
| 12553 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 12554 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12555 | * by modem. |
| 12556 | * |
| 12557 | * @param subId The subId of the subscription to request for. |
| 12558 | * @param reason Reason for disallowing satellite communication for carrier. |
| 12559 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12560 | * operation. |
| 12561 | * |
| 12562 | * @throws SecurityException if the caller doesn't have required permission. |
| 12563 | */ |
| 12564 | public void addSatelliteAttachRestrictionForCarrier(int subId, |
| 12565 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12566 | @NonNull IIntegerConsumer callback) { |
| 12567 | enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier"); |
| 12568 | final long identity = Binder.clearCallingIdentity(); |
| 12569 | try { |
| 12570 | mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback); |
| 12571 | } finally { |
| 12572 | Binder.restoreCallingIdentity(identity); |
| 12573 | } |
| 12574 | } |
| 12575 | |
| 12576 | /** |
| 12577 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12578 | * by modem. |
| 12579 | * |
| 12580 | * @param subId The subId of the subscription to request for. |
| 12581 | * @param reason Reason for disallowing satellite communication. |
| 12582 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12583 | * operation. |
| 12584 | * |
| 12585 | * @throws SecurityException if the caller doesn't have required permission. |
| 12586 | */ |
| 12587 | public void removeSatelliteAttachRestrictionForCarrier(int subId, |
| 12588 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12589 | @NonNull IIntegerConsumer callback) { |
| 12590 | enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier"); |
| 12591 | final long identity = Binder.clearCallingIdentity(); |
| 12592 | try { |
| 12593 | mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason, |
| 12594 | callback); |
| 12595 | } finally { |
| 12596 | Binder.restoreCallingIdentity(identity); |
| 12597 | } |
| 12598 | } |
| 12599 | |
| 12600 | /** |
| 12601 | * Get reasons for disallowing satellite communication, as requested by |
| 12602 | * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
| 12603 | * |
| 12604 | * @param subId The subId of the subscription to request for. |
| 12605 | * |
| 12606 | * @return Integer array of reasons for disallowing satellite communication. |
| 12607 | * |
| 12608 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12609 | */ |
| 12610 | public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier( |
| 12611 | int subId) { |
| 12612 | enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier"); |
| 12613 | final long identity = Binder.clearCallingIdentity(); |
| 12614 | try { |
| 12615 | Set<Integer> reasonSet = |
| 12616 | mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId); |
| 12617 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 12618 | } finally { |
| 12619 | Binder.restoreCallingIdentity(identity); |
| 12620 | } |
| 12621 | } |
| 12622 | |
| 12623 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12624 | * Request to get the signal strength of the satellite connection. |
| 12625 | * |
| 12626 | * @param subId The subId of the subscription to request for. |
| 12627 | * @param result Result receiver to get the error code of the request and the current signal |
| 12628 | * strength of the satellite connection. |
| 12629 | * |
| 12630 | * @throws SecurityException if the caller doesn't have required permission. |
| 12631 | */ |
| 12632 | @Override |
| 12633 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 12634 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 12635 | final long identity = Binder.clearCallingIdentity(); |
| 12636 | try { |
| 12637 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 12638 | } finally { |
| 12639 | Binder.restoreCallingIdentity(identity); |
| 12640 | } |
| 12641 | } |
| 12642 | |
| 12643 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12644 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 12645 | * is not successful, a {@link ServiceSpecificException} that contains |
| 12646 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12647 | * |
| 12648 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12649 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 12650 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 12651 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 12652 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 12653 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12654 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12655 | * @throws SecurityException If the caller doesn't have the required permission. |
| 12656 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12657 | */ |
| 12658 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12659 | public void registerForNtnSignalStrengthChanged(int subId, |
| 12660 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12661 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 12662 | final long identity = Binder.clearCallingIdentity(); |
| 12663 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 12664 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12665 | } finally { |
| 12666 | Binder.restoreCallingIdentity(identity); |
| 12667 | } |
| 12668 | } |
| 12669 | |
| 12670 | /** |
| 12671 | * Unregisters for NTN signal strength changed from satellite modem. |
| 12672 | * If callback was not registered before, the request will be ignored. |
| 12673 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12674 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 12675 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12676 | * @param callback The callback that was passed to |
| 12677 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 12678 | * |
| 12679 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12680 | */ |
| 12681 | @Override |
| 12682 | public void unregisterForNtnSignalStrengthChanged( |
| 12683 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 12684 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 12685 | final long identity = Binder.clearCallingIdentity(); |
| 12686 | try { |
| 12687 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 12688 | } finally { |
| 12689 | Binder.restoreCallingIdentity(identity); |
| 12690 | } |
| 12691 | } |
| 12692 | |
| 12693 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12694 | * Registers for satellite capabilities change event from the satellite service. |
| 12695 | * |
| 12696 | * @param subId The subId of the subscription to request for. |
| 12697 | * @param callback The callback to handle the satellite capabilities changed event. |
| 12698 | * |
| 12699 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 12700 | * |
| 12701 | * @throws SecurityException if the caller doesn't have required permission. |
| 12702 | */ |
| 12703 | @Override |
| 12704 | @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged( |
| 12705 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12706 | enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged"); |
| 12707 | final long identity = Binder.clearCallingIdentity(); |
| 12708 | try { |
| 12709 | return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback); |
| 12710 | } finally { |
| 12711 | Binder.restoreCallingIdentity(identity); |
| 12712 | } |
| 12713 | } |
| 12714 | |
| 12715 | /** |
| 12716 | * Unregisters for satellite capabilities change event from the satellite service. |
| 12717 | * If callback was not registered before, the request will be ignored. |
| 12718 | * |
| 12719 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 12720 | * @param callback The callback that was passed to. |
| 12721 | * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
| 12722 | * |
| 12723 | * @throws SecurityException if the caller doesn't have required permission. |
| 12724 | */ |
| 12725 | @Override |
| 12726 | public void unregisterForSatelliteCapabilitiesChanged( |
| 12727 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12728 | enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged"); |
| 12729 | final long identity = Binder.clearCallingIdentity(); |
| 12730 | try { |
| 12731 | mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback); |
| 12732 | } finally { |
| 12733 | Binder.restoreCallingIdentity(identity); |
| 12734 | } |
| 12735 | } |
| 12736 | |
| 12737 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 12738 | * This API can be used by only CTS to update satellite vendor service package name. |
| 12739 | * |
| 12740 | * @param servicePackageName The package name of the satellite vendor service. |
| 12741 | * @return {@code true} if the satellite vendor service is set successfully, |
| 12742 | * {@code false} otherwise. |
| 12743 | */ |
| 12744 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 12745 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 12746 | TelephonyPermissions.enforceShellOnly( |
| 12747 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 12748 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12749 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12750 | "setSatelliteServicePackageName"); |
| 12751 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 12752 | } |
| 12753 | |
| 12754 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 12755 | * This API can be used by only CTS to update satellite gateway service package name. |
| 12756 | * |
| 12757 | * @param servicePackageName The package name of the satellite gateway service. |
| 12758 | * @return {@code true} if the satellite gateway service is set successfully, |
| 12759 | * {@code false} otherwise. |
| 12760 | */ |
| 12761 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 12762 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 12763 | TelephonyPermissions.enforceShellOnly( |
| 12764 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 12765 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12766 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12767 | "setSatelliteGatewayServicePackageName"); |
| 12768 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 12769 | } |
| 12770 | |
| 12771 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 12772 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 12773 | * |
| 12774 | * @param packageName The package name of the satellite pointing UI app. |
| 12775 | * @param className The class name of the satellite pointing UI app. |
| 12776 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 12777 | * {@code false} otherwise. |
| 12778 | */ |
| 12779 | public boolean setSatellitePointingUiClassName( |
| 12780 | @Nullable String packageName, @Nullable String className) { |
| 12781 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 12782 | + ", className=" + className); |
| 12783 | TelephonyPermissions.enforceShellOnly( |
| 12784 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 12785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12786 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12787 | "setSatelliteGatewayServicePackageName"); |
| 12788 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 12789 | } |
| 12790 | |
| 12791 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 12792 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 12793 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 12794 | * listening mode. |
| 12795 | * |
| 12796 | * @param timeoutMillis The timeout duration in millisecond. |
| 12797 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12798 | */ |
| 12799 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 12800 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 12801 | TelephonyPermissions.enforceShellOnly( |
| 12802 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 12803 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12804 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12805 | "setSatelliteListeningTimeoutDuration"); |
| 12806 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 12807 | } |
| 12808 | |
| 12809 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12810 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 12811 | * the device is aligned with the satellite for demo mode |
| 12812 | * |
| 12813 | * @param timeoutMillis The timeout duration in millisecond. |
| 12814 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12815 | */ |
| 12816 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 12817 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 12818 | TelephonyPermissions.enforceShellOnly( |
| 12819 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 12820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12821 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12822 | "setDeviceAlignedTimeoutDuration"); |
| 12823 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 12824 | } |
| 12825 | |
| 12826 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 12827 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 12828 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 12829 | * |
| 12830 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 12831 | * of the following values to enable the override: |
| 12832 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 12833 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 12834 | * To disable the override, use -1 for handoverType. |
| 12835 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 12836 | * delaySeconds after the emergency call starts. |
| 12837 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 12838 | */ |
| 12839 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 12840 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 12841 | TelephonyPermissions.enforceShellOnly( |
| 12842 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 12843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12844 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12845 | "setEmergencyCallToSatelliteHandoverType"); |
| 12846 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 12847 | handoverType, delaySeconds); |
| 12848 | } |
| 12849 | |
| 12850 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 12851 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 12852 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 12853 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 12854 | * |
| 12855 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 12856 | * satellite modem or not. |
| 12857 | * |
| 12858 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 12859 | */ |
| 12860 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 12861 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 12862 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 12863 | + "disabled"); |
| 12864 | return false; |
| 12865 | } |
| 12866 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 12867 | TelephonyPermissions.enforceShellOnly( |
| 12868 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 12869 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12870 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12871 | "setShouldSendDatagramToModemInDemoMode"); |
| 12872 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 12873 | shouldSendToModemInDemoMode); |
| 12874 | } |
| 12875 | |
| 12876 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12877 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 12878 | * |
| 12879 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 12880 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 12881 | * identifier is sent in the clear, which has privacy implications for the user. |
| 12882 | * |
| 12883 | * @param enable if notifications about disclosure events should be enabled |
| 12884 | * @throws SecurityException if the caller does not have the required privileges |
| 12885 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 12886 | */ |
| 12887 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 12888 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12889 | enforceModifyPermission(); |
| 12890 | checkForIdentifierDisclosureNotificationSupport(); |
| 12891 | |
| 12892 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12893 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 12894 | editor.apply(); |
| 12895 | |
| 12896 | // Each phone instance is responsible for updating its respective modem immediately |
| 12897 | // after we've made a preference change. |
| 12898 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12899 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 12900 | } |
| 12901 | } |
| 12902 | |
| 12903 | /** |
| 12904 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 12905 | * |
| 12906 | * @throws SecurityException if the caller does not have the required privileges |
| 12907 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 12908 | */ |
| 12909 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 12910 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12911 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 12912 | checkForIdentifierDisclosureNotificationSupport(); |
| 12913 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 12914 | } |
| 12915 | |
| 12916 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame^] | 12917 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 12918 | * are in use by the cellular modem. |
| 12919 | * |
| 12920 | * @throws IllegalStateException if the Telephony process is not currently available |
| 12921 | * @throws SecurityException if the caller does not have the required privileges |
| 12922 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 12923 | * and integrity algorithms in use |
| 12924 | * @hide |
| 12925 | */ |
| 12926 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 12927 | public void setEnableNullCipherNotifications(boolean enable) { |
| 12928 | enforceModifyPermission(); |
| 12929 | checkForNullCipherNotificationSupport(); |
| 12930 | |
| 12931 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12932 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 12933 | editor.apply(); |
| 12934 | |
| 12935 | // Each phone instance is responsible for updating its respective modem immediately |
| 12936 | // after a preference change. |
| 12937 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12938 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 12939 | } |
| 12940 | } |
| 12941 | |
| 12942 | /** |
| 12943 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 12944 | * cellular modem. |
| 12945 | * |
| 12946 | * @throws IllegalStateException if the Telephony process is not currently available |
| 12947 | * @throws SecurityException if the caller does not have the required privileges |
| 12948 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 12949 | * and integrity algorithms in use |
| 12950 | * @hide |
| 12951 | */ |
| 12952 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 12953 | public boolean isNullCipherNotificationsEnabled() { |
| 12954 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 12955 | checkForNullCipherNotificationSupport(); |
| 12956 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 12957 | } |
| 12958 | |
| 12959 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12960 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12961 | * |
| 12962 | * <p>This method behaves in one of the following ways: |
| 12963 | * <ul> |
| 12964 | * <li>return true : if the calling package has the appop permission {@link |
| 12965 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12966 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12967 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12968 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12969 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12970 | * </ul> |
| 12971 | */ |
| 12972 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12973 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12974 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12975 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12976 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12977 | return true; |
| 12978 | } |
| 12979 | } |
| 12980 | return false; |
| 12981 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12982 | |
| 12983 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12984 | * @return The subscription manager service instance. |
| 12985 | */ |
| 12986 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12987 | return SubscriptionManagerService.getInstance(); |
| 12988 | } |
| 12989 | |
| 12990 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12991 | * Class binds the consumer[callback] and carrierId. |
| 12992 | */ |
| 12993 | private static class CallerCallbackInfo { |
| 12994 | private final Consumer<Integer> mConsumer; |
| 12995 | private final int mCarrierId; |
| 12996 | |
| 12997 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12998 | mConsumer = consumer; |
| 12999 | mCarrierId = carrierId; |
| 13000 | } |
| 13001 | |
| 13002 | public Consumer<Integer> getConsumer() { |
| 13003 | return mConsumer; |
| 13004 | } |
| 13005 | |
| 13006 | public int getCarrierId() { |
| 13007 | return mCarrierId; |
| 13008 | } |
| 13009 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13010 | } |