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; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 156 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 157 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 158 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 159 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 160 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 161 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 162 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 163 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 164 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 165 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 166 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 167 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 168 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 169 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 170 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 185 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 202 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 205 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.SmsPermissions; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 208 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 211 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 212 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 215 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 217 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 218 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 219 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 220 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 222 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.uicc.IccIoResult; |
| 225 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 229 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 230 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 231 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 232 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 233 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 234 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 235 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 236 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 237 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 238 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 239 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 240 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 241 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 242 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 243 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 244 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 245 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 246 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 247 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 248 | import com.android.services.telephony.TelecomAccountRegistry; |
| 249 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 250 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 251 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 252 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 253 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 254 | import java.io.IOException; |
| 255 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 256 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 258 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 259 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 260 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 261 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 262 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 263 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 264 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 265 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 266 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 267 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 268 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 269 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 270 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 271 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 272 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 273 | |
| 274 | /** |
| 275 | * Implementation of the ITelephony interface. |
| 276 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 277 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 278 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 279 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 280 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 281 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 282 | |
| 283 | // Message codes used with mMainThreadHandler |
| 284 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 285 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 286 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 287 | private static final int CMD_OPEN_CHANNEL = 9; |
| 288 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 289 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 290 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 291 | private static final int CMD_NV_READ_ITEM = 13; |
| 292 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 293 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 294 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 295 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 296 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 297 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 298 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 299 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 300 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 301 | private static final int CMD_SEND_ENVELOPE = 25; |
| 302 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 303 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 304 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 305 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 306 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 307 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 308 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 309 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 310 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 311 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 312 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 313 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 314 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 315 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 316 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 317 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 318 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 319 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 320 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 321 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 322 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 323 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 324 | private static final int CMD_SWITCH_SLOTS = 50; |
| 325 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 326 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 327 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 328 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 329 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 330 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 331 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 332 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 333 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 334 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 335 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 336 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 337 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 338 | private static final int CMD_MODEM_REBOOT = 64; |
| 339 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 340 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 341 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 342 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 343 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 344 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 345 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 346 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 347 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 348 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 349 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 350 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 351 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 352 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 353 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 354 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 355 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 356 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 357 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 358 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 359 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 360 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 361 | private static final int CMD_GET_CALL_WAITING = 87; |
| 362 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 363 | private static final int CMD_SET_CALL_WAITING = 89; |
| 364 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 365 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 366 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 367 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 368 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 369 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 370 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 371 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 372 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 373 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 374 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 375 | private static final int CMD_SET_SIM_POWER = 101; |
| 376 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 377 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 378 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 379 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 380 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 381 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 382 | 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] | 383 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 384 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 385 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 386 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 387 | private static final int CMD_ENABLE_VONR = 113; |
| 388 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 389 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 390 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 391 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 392 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 393 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 394 | // Parameters of select command. |
| 395 | private static final int SELECT_COMMAND = 0xA4; |
| 396 | private static final int SELECT_P1 = 0x04; |
| 397 | private static final int SELECT_P2 = 0; |
| 398 | private static final int SELECT_P3 = 0x10; |
| 399 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 400 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 401 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 402 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 403 | /** The singleton instance. */ |
| 404 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 405 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 406 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 407 | private final PhoneGlobals mApp; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 408 | private final FeatureFlags mFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 409 | private final CallManager mCM; |
| 410 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 411 | |
| 412 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 413 | private final UserManager mUserManager; |
| 414 | private final AppOpsManager mAppOps; |
| 415 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 416 | private final SharedPreferences mTelephonySharedPreferences; |
| 417 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 418 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 419 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 420 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 421 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 422 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 423 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 424 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 425 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 426 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 427 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 428 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 429 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 430 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 431 | // String to store multi SIM allowed |
| 432 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 433 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 434 | // The AID of ISD-R. |
| 435 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 436 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 437 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 438 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 439 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 440 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 441 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 442 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 443 | 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] | 444 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 445 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 446 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 447 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 448 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 449 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 450 | */ |
| 451 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 452 | "reset_network_erase_modem_config_enabled"; |
| 453 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 454 | 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] | 455 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 456 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 457 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 458 | /** |
| 459 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 460 | * one ICCID active at the same time. |
| 461 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 462 | * |
| 463 | * @hide |
| 464 | */ |
| 465 | @ChangeId |
| 466 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 467 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 468 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 469 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 470 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 471 | * operation fails. |
| 472 | */ |
| 473 | @ChangeId |
| 474 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 475 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 476 | |
| 477 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 478 | * A request object to use for transmitting data to an ICC. |
| 479 | */ |
| 480 | private static final class IccAPDUArgument { |
| 481 | public int channel, cla, command, p1, p2, p3; |
| 482 | public String data; |
| 483 | |
| 484 | public IccAPDUArgument(int channel, int cla, int command, |
| 485 | int p1, int p2, int p3, String data) { |
| 486 | this.channel = channel; |
| 487 | this.cla = cla; |
| 488 | this.command = command; |
| 489 | this.p1 = p1; |
| 490 | this.p2 = p2; |
| 491 | this.p3 = p3; |
| 492 | this.data = data; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 497 | * A request object to use for transmitting data to an ICC. |
| 498 | */ |
| 499 | private static final class ManualNetworkSelectionArgument { |
| 500 | public OperatorInfo operatorInfo; |
| 501 | public boolean persistSelection; |
| 502 | |
| 503 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 504 | this.operatorInfo = operatorInfo; |
| 505 | this.persistSelection = persistSelection; |
| 506 | } |
| 507 | } |
| 508 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 509 | private static final class PurchasePremiumCapabilityArgument { |
| 510 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 511 | public @NonNull IIntegerConsumer callback; |
| 512 | |
| 513 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 514 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 515 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 516 | this.callback = callback; |
| 517 | } |
| 518 | } |
| 519 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 520 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 522 | * request after sending. The main thread will notify the request when it is complete. |
| 523 | */ |
| 524 | private static final class MainThreadRequest { |
| 525 | /** The argument to use for the request */ |
| 526 | public Object argument; |
| 527 | /** The result of the request that is run on the main thread */ |
| 528 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 529 | // The subscriber id that this request applies to. Defaults to |
| 530 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 531 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 532 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 533 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 534 | public Phone phone; |
| 535 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 536 | public WorkSource workSource; |
| 537 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 538 | public MainThreadRequest(Object argument) { |
| 539 | this.argument = argument; |
| 540 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 541 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 542 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 543 | this.argument = argument; |
| 544 | if (phone != null) { |
| 545 | this.phone = phone; |
| 546 | } |
| 547 | this.workSource = workSource; |
| 548 | } |
| 549 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 550 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 551 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 552 | if (subId != null) { |
| 553 | this.subId = subId; |
| 554 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 555 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 556 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 559 | private static final class IncomingThirdPartyCallArgs { |
| 560 | public final ComponentName component; |
| 561 | public final String callId; |
| 562 | public final String callerDisplayName; |
| 563 | |
| 564 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 565 | String callerDisplayName) { |
| 566 | this.component = component; |
| 567 | this.callId = callId; |
| 568 | this.callerDisplayName = callerDisplayName; |
| 569 | } |
| 570 | } |
| 571 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 572 | /** |
| 573 | * A handler that processes messages on the main thread in the phone process. Since many |
| 574 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 575 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 576 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 577 | * on, which will be notified when the operation completes and will contain the result of the |
| 578 | * request. |
| 579 | * |
| 580 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 581 | * note that request.result must be set to something non-null for the calling thread to |
| 582 | * unblock. |
| 583 | */ |
| 584 | private final class MainThreadHandler extends Handler { |
| 585 | @Override |
| 586 | public void handleMessage(Message msg) { |
| 587 | MainThreadRequest request; |
| 588 | Message onCompleted; |
| 589 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 590 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 591 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 592 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 593 | |
| 594 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 595 | case CMD_HANDLE_USSD_REQUEST: { |
| 596 | request = (MainThreadRequest) msg.obj; |
| 597 | final Phone phone = getPhoneFromRequest(request); |
| 598 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 599 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 600 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 601 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | if (!isUssdApiAllowed(request.subId)) { |
| 603 | // Carrier does not support use of this API, return failure. |
| 604 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 605 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 606 | Bundle returnData = new Bundle(); |
| 607 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 608 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 609 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | request.result = true; |
| 611 | notifyRequester(request); |
| 612 | return; |
| 613 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 614 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 615 | try { |
| 616 | request.result = phone != null |
| 617 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 618 | } catch (CallStateException cse) { |
| 619 | request.result = false; |
| 620 | } |
| 621 | // Wake up the requesting thread |
| 622 | notifyRequester(request); |
| 623 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 626 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 627 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 628 | final Phone phone = getPhoneFromRequest(request); |
| 629 | request.result = phone != null ? |
| 630 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 631 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 632 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 633 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 634 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 635 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 636 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 638 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 640 | uiccPort = getUiccPortFromRequest(request); |
| 641 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 642 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 643 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 645 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 647 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 648 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 649 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 650 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 651 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 652 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 653 | break; |
| 654 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 655 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 656 | ar = (AsyncResult) msg.obj; |
| 657 | request = (MainThreadRequest) ar.userObj; |
| 658 | if (ar.exception == null && ar.result != null) { |
| 659 | request.result = ar.result; |
| 660 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 661 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | if (ar.result == null) { |
| 663 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 664 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | } else { |
| 668 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 669 | } |
| 670 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | break; |
| 673 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 675 | request = (MainThreadRequest) msg.obj; |
| 676 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 677 | uiccPort = getUiccPortFromRequest(request); |
| 678 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 679 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 680 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 681 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 682 | } else { |
| 683 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 684 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 685 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 686 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 687 | iccArgument.p2, |
| 688 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 689 | } |
| 690 | break; |
| 691 | |
| 692 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 693 | ar = (AsyncResult) msg.obj; |
| 694 | request = (MainThreadRequest) ar.userObj; |
| 695 | if (ar.exception == null && ar.result != null) { |
| 696 | request.result = ar.result; |
| 697 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 698 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 699 | if (ar.result == null) { |
| 700 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 701 | } else if (ar.exception instanceof CommandException) { |
| 702 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 703 | ar.exception); |
| 704 | } else { |
| 705 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 706 | } |
| 707 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 708 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 709 | break; |
| 710 | |
| 711 | case CMD_EXCHANGE_SIM_IO: |
| 712 | request = (MainThreadRequest) msg.obj; |
| 713 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 714 | uiccPort = getUiccPortFromRequest(request); |
| 715 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 716 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 717 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 719 | } else { |
| 720 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 721 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 722 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 723 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 724 | iccArgument.data, onCompleted); |
| 725 | } |
| 726 | break; |
| 727 | |
| 728 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 729 | ar = (AsyncResult) msg.obj; |
| 730 | request = (MainThreadRequest) ar.userObj; |
| 731 | if (ar.exception == null && ar.result != null) { |
| 732 | request.result = ar.result; |
| 733 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 734 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 735 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 736 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 737 | break; |
| 738 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 739 | case CMD_SEND_ENVELOPE: |
| 740 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 741 | uiccPort = getUiccPortFromRequest(request); |
| 742 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 743 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 744 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 745 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 746 | } else { |
| 747 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 748 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 749 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case EVENT_SEND_ENVELOPE_DONE: |
| 753 | ar = (AsyncResult) msg.obj; |
| 754 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 755 | if (ar.exception == null && ar.result != null) { |
| 756 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 757 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 758 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 759 | if (ar.result == null) { |
| 760 | loge("sendEnvelopeWithStatus: Empty response"); |
| 761 | } else if (ar.exception instanceof CommandException) { |
| 762 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 763 | ar.exception); |
| 764 | } else { |
| 765 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 766 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 767 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 768 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 769 | break; |
| 770 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 771 | case CMD_OPEN_CHANNEL: |
| 772 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 773 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 774 | IccLogicalChannelRequest openChannelRequest = |
| 775 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 776 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 777 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 778 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 779 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 780 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 781 | } else { |
| 782 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 783 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 784 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 785 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 786 | break; |
| 787 | |
| 788 | case EVENT_OPEN_CHANNEL_DONE: |
| 789 | ar = (AsyncResult) msg.obj; |
| 790 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 791 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 792 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 793 | int[] result = (int[]) ar.result; |
| 794 | int channelId = result[0]; |
| 795 | byte[] selectResponse = null; |
| 796 | if (result.length > 1) { |
| 797 | selectResponse = new byte[result.length - 1]; |
| 798 | for (int i = 1; i < result.length; ++i) { |
| 799 | selectResponse[i - 1] = (byte) result[i]; |
| 800 | } |
| 801 | } |
| 802 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 803 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 804 | |
| 805 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 806 | if (uiccPort == null) { |
| 807 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 808 | } else { |
| 809 | IccLogicalChannelRequest channelRequest = |
| 810 | (IccLogicalChannelRequest) request.argument; |
| 811 | channelRequest.channel = channelId; |
| 812 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 813 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 814 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 815 | if (ar.result == null) { |
| 816 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 817 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 818 | if (ar.exception != null) { |
| 819 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 820 | } |
| 821 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 822 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 823 | if (ar.exception instanceof CommandException) { |
| 824 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 825 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 826 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 827 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 828 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 829 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 833 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 834 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 835 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 836 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
| 839 | case CMD_CLOSE_CHANNEL: |
| 840 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 841 | uiccPort = getUiccPortFromRequest(request); |
| 842 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 843 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 844 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 845 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 846 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 847 | } else { |
| 848 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 849 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 850 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 851 | break; |
| 852 | |
| 853 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 854 | ar = (AsyncResult) msg.obj; |
| 855 | request = (MainThreadRequest) ar.userObj; |
| 856 | if (ar.exception == null) { |
| 857 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 858 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 859 | if (uiccPort == null) { |
| 860 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 861 | } else { |
| 862 | final int channelId = (Integer) request.argument; |
| 863 | uiccPort.onLogicalChannelClosed(channelId); |
| 864 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 865 | } else { |
| 866 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 867 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 868 | if (ar.exception instanceof CommandException) { |
| 869 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 870 | CommandException.Error error = |
| 871 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 872 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 873 | // should only throw exceptions from the binder threads. |
| 874 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 875 | "iccCloseLogicalChannel: invalid argument "); |
| 876 | } |
| 877 | } else { |
| 878 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 879 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 880 | request.result = (exception != null) ? exception : |
| 881 | new IllegalStateException( |
| 882 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 883 | } |
| 884 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | case CMD_NV_READ_ITEM: |
| 888 | request = (MainThreadRequest) msg.obj; |
| 889 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 890 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 891 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 892 | break; |
| 893 | |
| 894 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 895 | ar = (AsyncResult) msg.obj; |
| 896 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 897 | if (ar.exception == null && ar.result != null) { |
| 898 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 899 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 900 | request.result = ""; |
| 901 | if (ar.result == null) { |
| 902 | loge("nvReadItem: Empty response"); |
| 903 | } else if (ar.exception instanceof CommandException) { |
| 904 | loge("nvReadItem: CommandException: " + |
| 905 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 906 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 907 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 908 | } |
| 909 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 910 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 911 | break; |
| 912 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 913 | case CMD_NV_WRITE_ITEM: |
| 914 | request = (MainThreadRequest) msg.obj; |
| 915 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 916 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 917 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 918 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 919 | break; |
| 920 | |
| 921 | case EVENT_NV_WRITE_ITEM_DONE: |
| 922 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 923 | break; |
| 924 | |
| 925 | case CMD_NV_WRITE_CDMA_PRL: |
| 926 | request = (MainThreadRequest) msg.obj; |
| 927 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 928 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 929 | break; |
| 930 | |
| 931 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 932 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 933 | break; |
| 934 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 935 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 936 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 937 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 938 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 939 | break; |
| 940 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 941 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 942 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 943 | break; |
| 944 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 945 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 946 | request = (MainThreadRequest) msg.obj; |
| 947 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 948 | request); |
| 949 | Phone phone = getPhoneFromRequest(request); |
| 950 | if (phone != null) { |
| 951 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 952 | } else { |
| 953 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 954 | request.result = false; |
| 955 | notifyRequester(request); |
| 956 | } |
| 957 | break; |
| 958 | } |
| 959 | |
| 960 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 961 | ar = (AsyncResult) msg.obj; |
| 962 | request = (MainThreadRequest) ar.userObj; |
| 963 | if (ar.exception == null && ar.result != null) { |
| 964 | request.result = ar.result; |
| 965 | } else { |
| 966 | // request.result must be set to something non-null |
| 967 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 968 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 969 | request.result = ar.result; |
| 970 | } else { |
| 971 | request.result = false; |
| 972 | } |
| 973 | if (ar.result == null) { |
| 974 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 975 | } else if (ar.exception instanceof CommandException) { |
| 976 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 977 | + ar.exception); |
| 978 | } else { |
| 979 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 980 | } |
| 981 | } |
| 982 | notifyRequester(request); |
| 983 | break; |
| 984 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 985 | case CMD_IS_VONR_ENABLED: { |
| 986 | request = (MainThreadRequest) msg.obj; |
| 987 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 988 | request); |
| 989 | Phone phone = getPhoneFromRequest(request); |
| 990 | if (phone != null) { |
| 991 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 992 | } else { |
| 993 | loge("isVoNrEnabled: No phone object"); |
| 994 | request.result = false; |
| 995 | notifyRequester(request); |
| 996 | } |
| 997 | break; |
| 998 | } |
| 999 | |
| 1000 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1001 | ar = (AsyncResult) msg.obj; |
| 1002 | request = (MainThreadRequest) ar.userObj; |
| 1003 | if (ar.exception == null && ar.result != null) { |
| 1004 | request.result = ar.result; |
| 1005 | } else { |
| 1006 | // request.result must be set to something non-null |
| 1007 | // for the calling thread to unblock |
| 1008 | if (ar.result != null) { |
| 1009 | request.result = ar.result; |
| 1010 | } else { |
| 1011 | request.result = false; |
| 1012 | } |
| 1013 | if (ar.result == null) { |
| 1014 | loge("isVoNrEnabled: Empty response"); |
| 1015 | } else if (ar.exception instanceof CommandException) { |
| 1016 | loge("isVoNrEnabled: CommandException: " |
| 1017 | + ar.exception); |
| 1018 | } else { |
| 1019 | loge("isVoNrEnabled: Unknown exception"); |
| 1020 | } |
| 1021 | } |
| 1022 | notifyRequester(request); |
| 1023 | break; |
| 1024 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1025 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1026 | request = (MainThreadRequest) msg.obj; |
| 1027 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1028 | Phone phone = getPhoneFromRequest(request); |
| 1029 | if (phone != null) { |
| 1030 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1031 | request.workSource); |
| 1032 | } else { |
| 1033 | loge("enableNrDualConnectivity: No phone object"); |
| 1034 | request.result = |
| 1035 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1036 | notifyRequester(request); |
| 1037 | } |
| 1038 | break; |
| 1039 | } |
| 1040 | |
| 1041 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1042 | ar = (AsyncResult) msg.obj; |
| 1043 | request = (MainThreadRequest) ar.userObj; |
| 1044 | if (ar.exception == null) { |
| 1045 | request.result = |
| 1046 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1047 | } else { |
| 1048 | request.result = |
| 1049 | TelephonyManager |
| 1050 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1051 | if (ar.exception instanceof CommandException) { |
| 1052 | CommandException.Error error = |
| 1053 | ((CommandException) (ar.exception)).getCommandError(); |
| 1054 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1055 | request.result = |
| 1056 | TelephonyManager |
| 1057 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1058 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1059 | request.result = |
| 1060 | TelephonyManager |
| 1061 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1062 | } |
| 1063 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1064 | + ar.exception); |
| 1065 | } else { |
| 1066 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1067 | } |
| 1068 | } |
| 1069 | notifyRequester(request); |
| 1070 | break; |
| 1071 | } |
| 1072 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1073 | case CMD_ENABLE_VONR: { |
| 1074 | request = (MainThreadRequest) msg.obj; |
| 1075 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1076 | Phone phone = getPhoneFromRequest(request); |
| 1077 | if (phone != null) { |
| 1078 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1079 | request.workSource); |
| 1080 | } else { |
| 1081 | loge("setVoNrEnabled: No phone object"); |
| 1082 | request.result = |
| 1083 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1084 | notifyRequester(request); |
| 1085 | } |
| 1086 | break; |
| 1087 | } |
| 1088 | |
| 1089 | case EVENT_ENABLE_VONR_DONE: { |
| 1090 | ar = (AsyncResult) msg.obj; |
| 1091 | request = (MainThreadRequest) ar.userObj; |
| 1092 | if (ar.exception == null) { |
| 1093 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1094 | } else { |
| 1095 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1096 | if (ar.exception instanceof CommandException) { |
| 1097 | CommandException.Error error = |
| 1098 | ((CommandException) (ar.exception)).getCommandError(); |
| 1099 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1100 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1101 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1102 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1103 | } else { |
| 1104 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1105 | } |
| 1106 | loge("setVoNrEnabled" + ": CommandException: " |
| 1107 | + ar.exception); |
| 1108 | } else { |
| 1109 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1110 | } |
| 1111 | } |
| 1112 | notifyRequester(request); |
| 1113 | break; |
| 1114 | } |
| 1115 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1116 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1117 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1118 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1119 | request); |
| 1120 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1121 | break; |
| 1122 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1123 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1124 | ar = (AsyncResult) msg.obj; |
| 1125 | request = (MainThreadRequest) ar.userObj; |
| 1126 | if (ar.exception == null && ar.result != null) { |
| 1127 | request.result = ar.result; // Integer |
| 1128 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1129 | // request.result must be set to something non-null |
| 1130 | // for the calling thread to unblock |
| 1131 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1132 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1133 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1134 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1135 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1136 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1137 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1138 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1139 | } |
| 1140 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1141 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1142 | break; |
| 1143 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1144 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1145 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1146 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1147 | request); |
| 1148 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1149 | (Pair<Integer, Long>) request.argument; |
| 1150 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1151 | reasonWithNetworkTypes.first, |
| 1152 | reasonWithNetworkTypes.second, |
| 1153 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1154 | break; |
| 1155 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1156 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1157 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1158 | break; |
| 1159 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1160 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1161 | request = (MainThreadRequest) msg.obj; |
| 1162 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1163 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1164 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1165 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1166 | break; |
| 1167 | |
| 1168 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1169 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1170 | break; |
| 1171 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1172 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1173 | request = (MainThreadRequest) msg.obj; |
| 1174 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1175 | request); |
| 1176 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1177 | break; |
| 1178 | |
| 1179 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1180 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1181 | break; |
| 1182 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1183 | case CMD_PERFORM_NETWORK_SCAN: |
| 1184 | request = (MainThreadRequest) msg.obj; |
| 1185 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1186 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1187 | break; |
| 1188 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1189 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1190 | request = (MainThreadRequest) msg.obj; |
| 1191 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1192 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1193 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1194 | request.argument; |
| 1195 | int callForwardingReason = args.first; |
| 1196 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1197 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1198 | } |
| 1199 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1200 | ar = (AsyncResult) msg.obj; |
| 1201 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1202 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1203 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1204 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1208 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1209 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1210 | // any service for voice call. |
| 1211 | if ((callForwardInfo.serviceClass |
| 1212 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1213 | callForwardingInfo = new CallForwardingInfo( |
| 1214 | callForwardInfo.status |
| 1215 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1216 | callForwardInfo.reason, |
| 1217 | callForwardInfo.number, |
| 1218 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1219 | break; |
| 1220 | } |
| 1221 | } |
| 1222 | // Didn't find a call forward info for voice call. |
| 1223 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1225 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | } else { |
| 1229 | if (ar.result == null) { |
| 1230 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1231 | } |
| 1232 | if (ar.exception != null) { |
| 1233 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1234 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1235 | int errorCode = TelephonyManager |
| 1236 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | if (ar.exception instanceof CommandException) { |
| 1238 | CommandException.Error error = |
| 1239 | ((CommandException) (ar.exception)).getCommandError(); |
| 1240 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1241 | errorCode = TelephonyManager |
| 1242 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1243 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1244 | errorCode = TelephonyManager |
| 1245 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | } |
| 1247 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | request = (MainThreadRequest) msg.obj; |
| 1255 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1256 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1259 | request.argument).first; |
| 1260 | request.phone.setCallForwardingOption( |
| 1261 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1262 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | callForwardingInfoToSet.getReason(), |
| 1265 | callForwardingInfoToSet.getNumber(), |
| 1266 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1267 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1269 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1270 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1271 | ar = (AsyncResult) msg.obj; |
| 1272 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1273 | Consumer<Integer> callback = |
| 1274 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1275 | request.argument).second; |
| 1276 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1278 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1279 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | if (ar.exception instanceof CommandException) { |
| 1281 | CommandException.Error error = |
| 1282 | ((CommandException) (ar.exception)).getCommandError(); |
| 1283 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1284 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1285 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1286 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1287 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1288 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | callback.accept(errorCode); |
| 1292 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1293 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1296 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | request = (MainThreadRequest) msg.obj; |
| 1300 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1301 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1302 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1304 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | ar = (AsyncResult) msg.obj; |
| 1307 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1308 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1309 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1311 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | // Service Class is a bit mask per 3gpp 27.007. |
| 1313 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1314 | if (callForwardResults.length > 1 |
| 1315 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1317 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1318 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1319 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1320 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1321 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1322 | } |
| 1323 | } else { |
| 1324 | if (ar.result == null) { |
| 1325 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1326 | } |
| 1327 | if (ar.exception != null) { |
| 1328 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1329 | } |
| 1330 | if (ar.exception instanceof CommandException) { |
| 1331 | CommandException.Error error = |
| 1332 | ((CommandException) (ar.exception)).getCommandError(); |
| 1333 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1334 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1336 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1337 | callWaitingStatus = |
| 1338 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1342 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1345 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1346 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | request = (MainThreadRequest) msg.obj; |
| 1348 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1349 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1350 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1351 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1353 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1354 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1355 | ar = (AsyncResult) msg.obj; |
| 1356 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1357 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1358 | Consumer<Integer> callback = |
| 1359 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1360 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1361 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1362 | if (ar.exception instanceof CommandException) { |
| 1363 | CommandException.Error error = |
| 1364 | ((CommandException) (ar.exception)).getCommandError(); |
| 1365 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1366 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1367 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1368 | callback.accept( |
| 1369 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1370 | } else { |
| 1371 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1372 | } |
| 1373 | } else { |
| 1374 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1375 | } |
| 1376 | } else { |
| 1377 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1378 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1379 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1380 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1381 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1382 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1383 | ar = (AsyncResult) msg.obj; |
| 1384 | request = (MainThreadRequest) ar.userObj; |
| 1385 | CellNetworkScanResult cellScanResult; |
| 1386 | if (ar.exception == null && ar.result != null) { |
| 1387 | cellScanResult = new CellNetworkScanResult( |
| 1388 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1389 | (List<OperatorInfo>) ar.result); |
| 1390 | } else { |
| 1391 | if (ar.result == null) { |
| 1392 | loge("getCellNetworkScanResults: Empty response"); |
| 1393 | } |
| 1394 | if (ar.exception != null) { |
| 1395 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1396 | } |
| 1397 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1398 | if (ar.exception instanceof CommandException) { |
| 1399 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1400 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1401 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1402 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1403 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1404 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1405 | } |
| 1406 | } |
| 1407 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1408 | } |
| 1409 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1410 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1411 | break; |
| 1412 | |
| 1413 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1414 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1415 | ManualNetworkSelectionArgument selArg = |
| 1416 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1417 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1418 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1419 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1420 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1421 | break; |
| 1422 | |
| 1423 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1424 | ar = (AsyncResult) msg.obj; |
| 1425 | request = (MainThreadRequest) ar.userObj; |
| 1426 | if (ar.exception == null) { |
| 1427 | request.result = true; |
| 1428 | } else { |
| 1429 | request.result = false; |
| 1430 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1431 | } |
| 1432 | notifyRequester(request); |
| 1433 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1434 | break; |
| 1435 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1436 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1437 | request = (MainThreadRequest) msg.obj; |
| 1438 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1439 | if (defaultPhone != null) { |
| 1440 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1441 | } else { |
| 1442 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1443 | Bundle bundle = new Bundle(); |
| 1444 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1445 | new ModemActivityInfo(0, 0, 0, |
| 1446 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1447 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1448 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1449 | break; |
| 1450 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1451 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1452 | ar = (AsyncResult) msg.obj; |
| 1453 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1454 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1455 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1456 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1457 | if (mLastModemActivityInfo == null) { |
| 1458 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1459 | mLastModemActivitySpecificInfo[0] = |
| 1460 | new ActivityStatsTechSpecificInfo( |
| 1461 | 0, |
| 1462 | 0, |
| 1463 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1464 | 0); |
| 1465 | mLastModemActivityInfo = |
| 1466 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1467 | } |
| 1468 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1469 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1470 | // Update the last modem activity info and the result of the request. |
| 1471 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1472 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1473 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1474 | } else { |
| 1475 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1476 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1477 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1478 | // We don't want to return mLastModemActivityInfo which is updated |
| 1479 | // inside mergeModemActivityInfo() |
| 1480 | ret = new ModemActivityInfo( |
| 1481 | mLastModemActivityInfo.getTimestampMillis(), |
| 1482 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1483 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1484 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1485 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1486 | } else { |
| 1487 | if (ar.result == null) { |
| 1488 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1489 | error = TelephonyManager.ModemActivityInfoException |
| 1490 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1491 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1492 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1493 | error = TelephonyManager.ModemActivityInfoException |
| 1494 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1495 | } else { |
| 1496 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1497 | error = TelephonyManager.ModemActivityInfoException |
| 1498 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1499 | } |
| 1500 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1501 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1502 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1503 | bundle.putParcelable( |
| 1504 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1505 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1506 | } else { |
| 1507 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1508 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1509 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1510 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1511 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1512 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1513 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1514 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1515 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1516 | CarrierRestrictionRules argument = |
| 1517 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1518 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1519 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1520 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1521 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1522 | |
| 1523 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1524 | ar = (AsyncResult) msg.obj; |
| 1525 | request = (MainThreadRequest) ar.userObj; |
| 1526 | if (ar.exception == null && ar.result != null) { |
| 1527 | request.result = ar.result; |
| 1528 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1529 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1530 | if (ar.exception instanceof CommandException) { |
| 1531 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1532 | CommandException.Error error = |
| 1533 | ((CommandException) (ar.exception)).getCommandError(); |
| 1534 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1535 | request.result = |
| 1536 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1537 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1538 | } else { |
| 1539 | loge("setAllowedCarriers: Unknown exception"); |
| 1540 | } |
| 1541 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1542 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1543 | break; |
| 1544 | |
| 1545 | case CMD_GET_ALLOWED_CARRIERS: |
| 1546 | request = (MainThreadRequest) msg.obj; |
| 1547 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1548 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1549 | break; |
| 1550 | |
| 1551 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1552 | ar = (AsyncResult) msg.obj; |
| 1553 | request = (MainThreadRequest) ar.userObj; |
| 1554 | if (ar.exception == null && ar.result != null) { |
| 1555 | request.result = ar.result; |
| 1556 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1557 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1558 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1559 | if (ar.result == null) { |
| 1560 | loge("getAllowedCarriers: Empty response"); |
| 1561 | } else if (ar.exception instanceof CommandException) { |
| 1562 | loge("getAllowedCarriers: CommandException: " + |
| 1563 | ar.exception); |
| 1564 | } else { |
| 1565 | loge("getAllowedCarriers: Unknown exception"); |
| 1566 | } |
| 1567 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1568 | if (request.argument != null) { |
| 1569 | // This is for the implementation of carrierRestrictionStatus. |
| 1570 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1571 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1572 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1573 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1574 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1575 | CarrierRestrictionRules carrierRestrictionRules = |
| 1576 | (CarrierRestrictionRules) ar.result; |
| 1577 | int carrierId = -1; |
| 1578 | try { |
| 1579 | CarrierIdentifier carrierIdentifier = |
| 1580 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1581 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1582 | carrierIdentifier); |
| 1583 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1584 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1585 | } |
| 1586 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1587 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1588 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1589 | lockStatus = TelephonyManager |
| 1590 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1591 | } |
| 1592 | } else { |
| 1593 | Rlog.e(LOG_TAG, |
| 1594 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1595 | } |
| 1596 | callback.accept(lockStatus); |
| 1597 | } else { |
| 1598 | // This is for the implementation of getAllowedCarriers. |
| 1599 | notifyRequester(request); |
| 1600 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1601 | break; |
| 1602 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1603 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1604 | ar = (AsyncResult) msg.obj; |
| 1605 | request = (MainThreadRequest) ar.userObj; |
| 1606 | if (ar.exception == null && ar.result != null) { |
| 1607 | request.result = ar.result; |
| 1608 | } else { |
| 1609 | request.result = new IllegalArgumentException( |
| 1610 | "Failed to retrieve Forbidden Plmns"); |
| 1611 | if (ar.result == null) { |
| 1612 | loge("getForbiddenPlmns: Empty response"); |
| 1613 | } else { |
| 1614 | loge("getForbiddenPlmns: Unknown exception"); |
| 1615 | } |
| 1616 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1617 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1618 | break; |
| 1619 | |
| 1620 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1621 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1622 | uiccPort = getUiccPortFromRequest(request); |
| 1623 | if (uiccPort == null) { |
| 1624 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1625 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1626 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1627 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1628 | break; |
| 1629 | } |
| 1630 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1631 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1632 | if (uiccApp == null) { |
| 1633 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1634 | + appType); |
| 1635 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1636 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1637 | break; |
| 1638 | } else { |
| 1639 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1640 | + " specified type -- " + appType); |
| 1641 | } |
| 1642 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1643 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1644 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1645 | break; |
| 1646 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1647 | case CMD_SWITCH_SLOTS: |
| 1648 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1649 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1650 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1651 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1652 | break; |
| 1653 | |
| 1654 | case EVENT_SWITCH_SLOTS_DONE: |
| 1655 | ar = (AsyncResult) msg.obj; |
| 1656 | request = (MainThreadRequest) ar.userObj; |
| 1657 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1658 | notifyRequester(request); |
| 1659 | break; |
| 1660 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1661 | request = (MainThreadRequest) msg.obj; |
| 1662 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1663 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1664 | break; |
| 1665 | |
| 1666 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1667 | ar = (AsyncResult) msg.obj; |
| 1668 | request = (MainThreadRequest) ar.userObj; |
| 1669 | if (ar.exception != null) { |
| 1670 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1671 | } else { |
| 1672 | int mode = ((int[]) ar.result)[0]; |
| 1673 | if (mode == 0) { |
| 1674 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1675 | } else { |
| 1676 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1677 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1678 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1679 | notifyRequester(request); |
| 1680 | break; |
| 1681 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1682 | request = (MainThreadRequest) msg.obj; |
| 1683 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1684 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1685 | break; |
| 1686 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1687 | ar = (AsyncResult) msg.obj; |
| 1688 | request = (MainThreadRequest) ar.userObj; |
| 1689 | if (ar.exception != null) { |
| 1690 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1691 | } else { |
| 1692 | request.result = ((int[]) ar.result)[0]; |
| 1693 | } |
| 1694 | notifyRequester(request); |
| 1695 | break; |
| 1696 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1697 | request = (MainThreadRequest) msg.obj; |
| 1698 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1699 | int mode = (int) request.argument; |
| 1700 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1701 | break; |
| 1702 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1703 | ar = (AsyncResult) msg.obj; |
| 1704 | request = (MainThreadRequest) ar.userObj; |
| 1705 | request.result = ar.exception == null; |
| 1706 | notifyRequester(request); |
| 1707 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1708 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1709 | request = (MainThreadRequest) msg.obj; |
| 1710 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1711 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1712 | break; |
| 1713 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1714 | ar = (AsyncResult) msg.obj; |
| 1715 | request = (MainThreadRequest) ar.userObj; |
| 1716 | if (ar.exception != null) { |
| 1717 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1718 | } else { |
| 1719 | request.result = ((int[]) ar.result)[0]; |
| 1720 | } |
| 1721 | notifyRequester(request); |
| 1722 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1723 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1724 | request = (MainThreadRequest) msg.obj; |
| 1725 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1726 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1727 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1728 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1729 | break; |
| 1730 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1731 | ar = (AsyncResult) msg.obj; |
| 1732 | request = (MainThreadRequest) ar.userObj; |
| 1733 | request.result = ar.exception == null; |
| 1734 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1735 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1736 | case CMD_GET_ALL_CELL_INFO: |
| 1737 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1738 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1739 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1740 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1741 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1742 | ar = (AsyncResult) msg.obj; |
| 1743 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1744 | // If a timeout occurs, the response will be null |
| 1745 | request.result = (ar.exception == null && ar.result != null) |
| 1746 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | synchronized (request) { |
| 1748 | request.notifyAll(); |
| 1749 | } |
| 1750 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1751 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1752 | request = (MainThreadRequest) msg.obj; |
| 1753 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1754 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1755 | break; |
| 1756 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1757 | ar = (AsyncResult) msg.obj; |
| 1758 | request = (MainThreadRequest) ar.userObj; |
| 1759 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1760 | try { |
| 1761 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1762 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1763 | cb.onError( |
| 1764 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1765 | ar.exception.getClass().getName(), |
| 1766 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1767 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1768 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1769 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1770 | } else { |
| 1771 | // use the result as returned |
| 1772 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1773 | } |
| 1774 | } catch (RemoteException re) { |
| 1775 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1776 | } |
| 1777 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1778 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1779 | request = (MainThreadRequest) msg.obj; |
| 1780 | WorkSource ws = (WorkSource) request.argument; |
| 1781 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1782 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1783 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1784 | } |
| 1785 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1786 | ar = (AsyncResult) msg.obj; |
| 1787 | request = (MainThreadRequest) ar.userObj; |
| 1788 | if (ar.exception == null) { |
| 1789 | request.result = ar.result; |
| 1790 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1791 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1792 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1793 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | synchronized (request) { |
| 1797 | request.notifyAll(); |
| 1798 | } |
| 1799 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1800 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1801 | case CMD_MODEM_REBOOT: |
| 1802 | request = (MainThreadRequest) msg.obj; |
| 1803 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1804 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1805 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1806 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1807 | handleNullReturnEvent(msg, "rebootModem"); |
| 1808 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1809 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1810 | request = (MainThreadRequest) msg.obj; |
| 1811 | boolean enable = (boolean) request.argument; |
| 1812 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1813 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1814 | PhoneConfigurationManager.getInstance() |
| 1815 | .enablePhone(request.phone, enable, onCompleted); |
| 1816 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1817 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1818 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1819 | ar = (AsyncResult) msg.obj; |
| 1820 | request = (MainThreadRequest) ar.userObj; |
| 1821 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1822 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1823 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1824 | if ((boolean) request.result) { |
| 1825 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1826 | updateModemStateMetrics(); |
| 1827 | } else { |
| 1828 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1829 | + ar.exception); |
| 1830 | } |
| 1831 | notifyRequester(request); |
| 1832 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1833 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1834 | case CMD_GET_MODEM_STATUS: |
| 1835 | request = (MainThreadRequest) msg.obj; |
| 1836 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1837 | PhoneConfigurationManager.getInstance() |
| 1838 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1839 | break; |
| 1840 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1841 | ar = (AsyncResult) msg.obj; |
| 1842 | request = (MainThreadRequest) ar.userObj; |
| 1843 | int id = request.phone.getPhoneId(); |
| 1844 | if (ar.exception == null && ar.result != null) { |
| 1845 | request.result = ar.result; |
| 1846 | //update the cache as modem status has changed |
| 1847 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1848 | (boolean) request.result); |
| 1849 | } else { |
| 1850 | // Return true if modem status cannot be retrieved. For most cases, |
| 1851 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1852 | // and disable modem are not supported. Modem is always on. |
| 1853 | // TODO: this should be fixed in R to support a third |
| 1854 | // status UNKNOWN b/131631629 |
| 1855 | request.result = true; |
| 1856 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1857 | + ar.exception); |
| 1858 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1859 | notifyRequester(request); |
| 1860 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1861 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1862 | request = (MainThreadRequest) msg.obj; |
| 1863 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1864 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1865 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1866 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1867 | break; |
| 1868 | } |
| 1869 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1870 | ar = (AsyncResult) msg.obj; |
| 1871 | request = (MainThreadRequest) ar.userObj; |
| 1872 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1873 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1874 | args.second.accept(ar.exception == null); |
| 1875 | notifyRequester(request); |
| 1876 | break; |
| 1877 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1878 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1879 | request = (MainThreadRequest) msg.obj; |
| 1880 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1881 | Phone phone = getPhoneFromRequest(request); |
| 1882 | if (phone != null) { |
| 1883 | phone.getSystemSelectionChannels(onCompleted); |
| 1884 | } else { |
| 1885 | loge("getSystemSelectionChannels: No phone object"); |
| 1886 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1887 | notifyRequester(request); |
| 1888 | } |
| 1889 | break; |
| 1890 | } |
| 1891 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1892 | ar = (AsyncResult) msg.obj; |
| 1893 | request = (MainThreadRequest) ar.userObj; |
| 1894 | if (ar.exception == null && ar.result != null) { |
| 1895 | request.result = ar.result; |
| 1896 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1897 | request.result = new IllegalStateException( |
| 1898 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1899 | if (ar.result == null) { |
| 1900 | loge("getSystemSelectionChannels: Empty response"); |
| 1901 | } else { |
| 1902 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1903 | } |
| 1904 | } |
| 1905 | notifyRequester(request); |
| 1906 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1907 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1908 | ar = (AsyncResult) msg.obj; |
| 1909 | request = (MainThreadRequest) ar.userObj; |
| 1910 | if (ar.exception == null && ar.result != null) { |
| 1911 | request.result = ar.result; |
| 1912 | } else { |
| 1913 | request.result = -1; |
| 1914 | loge("Failed to set Forbidden Plmns"); |
| 1915 | if (ar.result == null) { |
| 1916 | loge("setForbidenPlmns: Empty response"); |
| 1917 | } else if (ar.exception != null) { |
| 1918 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1919 | request.result = -1; |
| 1920 | } else { |
| 1921 | loge("setForbiddenPlmns: Unknown exception"); |
| 1922 | } |
| 1923 | } |
| 1924 | notifyRequester(request); |
| 1925 | break; |
| 1926 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1927 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1928 | uiccPort = getUiccPortFromRequest(request); |
| 1929 | if (uiccPort == null) { |
| 1930 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1931 | request.result = -1; |
| 1932 | notifyRequester(request); |
| 1933 | break; |
| 1934 | } |
| 1935 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1936 | (Pair<Integer, List<String>>) request.argument; |
| 1937 | appType = setFplmnsArgs.first; |
| 1938 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1939 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1940 | if (uiccApp == null) { |
| 1941 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1942 | request.result = -1; |
| 1943 | loge("Failed to get UICC App"); |
| 1944 | notifyRequester(request); |
| 1945 | } else { |
| 1946 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1947 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1948 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1949 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1950 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1951 | case CMD_ERASE_MODEM_CONFIG: |
| 1952 | request = (MainThreadRequest) msg.obj; |
| 1953 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1954 | defaultPhone.eraseModemConfig(onCompleted); |
| 1955 | break; |
| 1956 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1957 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1958 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1959 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1960 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1961 | request = (MainThreadRequest) msg.obj; |
| 1962 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1963 | notifyRequester(request); |
| 1964 | break; |
| 1965 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1966 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1967 | request = (MainThreadRequest) msg.obj; |
| 1968 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1969 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1970 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1971 | changed.first, changed.second, onCompleted); |
| 1972 | break; |
| 1973 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1974 | ar = (AsyncResult) msg.obj; |
| 1975 | request = (MainThreadRequest) ar.userObj; |
| 1976 | if (ar.exception == null) { |
| 1977 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1978 | // If the operation is successful, update the PIN storage |
| 1979 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1980 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1981 | UiccController.getInstance().getPinStorage() |
| 1982 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1983 | } else { |
| 1984 | request.result = msg.arg1; |
| 1985 | } |
| 1986 | notifyRequester(request); |
| 1987 | break; |
| 1988 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1989 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1990 | request = (MainThreadRequest) msg.obj; |
| 1991 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1992 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1993 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1994 | enabled.first, enabled.second, onCompleted); |
| 1995 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1996 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1997 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1998 | ar = (AsyncResult) msg.obj; |
| 1999 | request = (MainThreadRequest) ar.userObj; |
| 2000 | if (ar.exception == null) { |
| 2001 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2002 | // If the operation is successful, update the PIN storage |
| 2003 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2004 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2005 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2006 | UiccController.getInstance().getPinStorage() |
| 2007 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2008 | } else { |
| 2009 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2010 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2011 | } else { |
| 2012 | request.result = msg.arg1; |
| 2013 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2014 | |
| 2015 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2016 | notifyRequester(request); |
| 2017 | break; |
| 2018 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2019 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2020 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2021 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2022 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2023 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2024 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2025 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2026 | |
| 2027 | case CMD_SET_DATA_THROTTLING: { |
| 2028 | request = (MainThreadRequest) msg.obj; |
| 2029 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2030 | DataThrottlingRequest dataThrottlingRequest = |
| 2031 | (DataThrottlingRequest) request.argument; |
| 2032 | Phone phone = getPhoneFromRequest(request); |
| 2033 | if (phone != null) { |
| 2034 | phone.setDataThrottling(onCompleted, |
| 2035 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2036 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2037 | } else { |
| 2038 | loge("setDataThrottling: No phone object"); |
| 2039 | request.result = |
| 2040 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2041 | notifyRequester(request); |
| 2042 | } |
| 2043 | |
| 2044 | break; |
| 2045 | } |
| 2046 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2047 | ar = (AsyncResult) msg.obj; |
| 2048 | request = (MainThreadRequest) ar.userObj; |
| 2049 | |
| 2050 | if (ar.exception == null) { |
| 2051 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2052 | } else if (ar.exception instanceof CommandException) { |
| 2053 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2054 | CommandException.Error error = |
| 2055 | ((CommandException) (ar.exception)).getCommandError(); |
| 2056 | |
| 2057 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2058 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2059 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2060 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2061 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2062 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2063 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2064 | } else { |
| 2065 | request.result = |
| 2066 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2067 | } |
| 2068 | } else { |
| 2069 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2070 | } |
| 2071 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2072 | notifyRequester(request); |
| 2073 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2074 | |
| 2075 | case CMD_SET_SIM_POWER: { |
| 2076 | request = (MainThreadRequest) msg.obj; |
| 2077 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2078 | request = (MainThreadRequest) msg.obj; |
| 2079 | int stateToSet = |
| 2080 | ((Pair<Integer, IIntegerConsumer>) |
| 2081 | request.argument).first; |
| 2082 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2083 | break; |
| 2084 | } |
| 2085 | case EVENT_SET_SIM_POWER_DONE: { |
| 2086 | ar = (AsyncResult) msg.obj; |
| 2087 | request = (MainThreadRequest) ar.userObj; |
| 2088 | IIntegerConsumer callback = |
| 2089 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2090 | if (ar.exception != null) { |
| 2091 | loge("setSimPower exception: " + ar.exception); |
| 2092 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2093 | .RESULT_ERROR_UNKNOWN; |
| 2094 | if (ar.exception instanceof CommandException) { |
| 2095 | CommandException.Error error = |
| 2096 | ((CommandException) (ar.exception)).getCommandError(); |
| 2097 | if (error == CommandException.Error.SIM_ERR) { |
| 2098 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2099 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2100 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2101 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2102 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2103 | } else { |
| 2104 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2105 | } |
| 2106 | } |
| 2107 | try { |
| 2108 | callback.accept(errorCode); |
| 2109 | } catch (RemoteException e) { |
| 2110 | // Ignore if the remote process is no longer available to call back. |
| 2111 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2112 | } |
| 2113 | } else { |
| 2114 | try { |
| 2115 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2116 | } catch (RemoteException e) { |
| 2117 | // Ignore if the remote process is no longer available to call back. |
| 2118 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2119 | } |
| 2120 | } |
| 2121 | break; |
| 2122 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2123 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2124 | request = (MainThreadRequest) msg.obj; |
| 2125 | |
| 2126 | final Phone phone = getPhoneFromRequest(request); |
| 2127 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2128 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2129 | notifyRequester(request); |
| 2130 | break; |
| 2131 | } |
| 2132 | |
| 2133 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2134 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2135 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2136 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2137 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2138 | request.subId, pair.first /*callingUid*/, |
| 2139 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2140 | break; |
| 2141 | } |
| 2142 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2143 | ar = (AsyncResult) msg.obj; |
| 2144 | request = (MainThreadRequest) ar.userObj; |
| 2145 | // request.result will be the exception of ar if present, true otherwise. |
| 2146 | // Be cautious not to leave result null which will wait() forever |
| 2147 | request.result = ar.exception != null ? ar.exception : true; |
| 2148 | notifyRequester(request); |
| 2149 | break; |
| 2150 | } |
| 2151 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2152 | request = (MainThreadRequest) msg.obj; |
| 2153 | |
| 2154 | Phone phone = getPhoneFromRequest(request); |
| 2155 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2156 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2157 | notifyRequester(request); |
| 2158 | break; |
| 2159 | } |
| 2160 | |
| 2161 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2162 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2163 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2164 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2165 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2166 | request.subId, pair.first /*callingUid*/, |
| 2167 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2168 | break; |
| 2169 | } |
| 2170 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2171 | ar = (AsyncResult) msg.obj; |
| 2172 | request = (MainThreadRequest) ar.userObj; |
| 2173 | request.result = ar.exception != null ? ar.exception : true; |
| 2174 | notifyRequester(request); |
| 2175 | break; |
| 2176 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2177 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2178 | case CMD_GET_SLICING_CONFIG: { |
| 2179 | request = (MainThreadRequest) msg.obj; |
| 2180 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2181 | request.phone.getSlicingConfig(onCompleted); |
| 2182 | break; |
| 2183 | } |
| 2184 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2185 | ar = (AsyncResult) msg.obj; |
| 2186 | request = (MainThreadRequest) ar.userObj; |
| 2187 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2188 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2189 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2190 | Bundle bundle = new Bundle(); |
| 2191 | int resultCode = 0; |
| 2192 | if (ar.exception != null) { |
| 2193 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2194 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2195 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2196 | } else if (ar.result == null) { |
| 2197 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2198 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2199 | } else { |
| 2200 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2201 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2202 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2206 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2207 | } |
| 2208 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2209 | result.send(resultCode, bundle); |
| 2210 | notifyRequester(request); |
| 2211 | break; |
| 2212 | } |
| 2213 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2214 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2215 | request = (MainThreadRequest) msg.obj; |
| 2216 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2217 | PurchasePremiumCapabilityArgument arg = |
| 2218 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2219 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2220 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2221 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2222 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2223 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2224 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2225 | ar = (AsyncResult) msg.obj; |
| 2226 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2227 | PurchasePremiumCapabilityArgument arg = |
| 2228 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2229 | try { |
| 2230 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2231 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2232 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2233 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2234 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2235 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2236 | } catch (RemoteException e) { |
| 2237 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2238 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2239 | + " failed: " + e; |
| 2240 | if (DBG) log(logStr); |
| 2241 | AnomalyReporter.reportAnomaly( |
| 2242 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2243 | } |
| 2244 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2245 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2246 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2247 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2248 | request = (MainThreadRequest) msg.obj; |
| 2249 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2250 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2251 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2252 | notifyRequester(request); |
| 2253 | break; |
| 2254 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | default: |
| 2256 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2257 | break; |
| 2258 | } |
| 2259 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2260 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2261 | private void notifyRequester(MainThreadRequest request) { |
| 2262 | synchronized (request) { |
| 2263 | request.notifyAll(); |
| 2264 | } |
| 2265 | } |
| 2266 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2267 | private void handleNullReturnEvent(Message msg, String command) { |
| 2268 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2269 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2270 | if (ar.exception == null) { |
| 2271 | request.result = true; |
| 2272 | } else { |
| 2273 | request.result = false; |
| 2274 | if (ar.exception instanceof CommandException) { |
| 2275 | loge(command + ": CommandException: " + ar.exception); |
| 2276 | } else { |
| 2277 | loge(command + ": Unknown exception"); |
| 2278 | } |
| 2279 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2280 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2281 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | /** |
| 2285 | * Posts the specified command to be executed on the main thread, |
| 2286 | * waits for the request to complete, and returns the result. |
| 2287 | * @see #sendRequestAsync |
| 2288 | */ |
| 2289 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2290 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2291 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | /** |
| 2295 | * Posts the specified command to be executed on the main thread, |
| 2296 | * waits for the request to complete, and returns the result. |
| 2297 | * @see #sendRequestAsync |
| 2298 | */ |
| 2299 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2300 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2301 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | /** |
| 2305 | * Posts the specified command to be executed on the main thread, |
| 2306 | * waits for the request to complete, and returns the result. |
| 2307 | * @see #sendRequestAsync |
| 2308 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2309 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2310 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2311 | } |
| 2312 | |
| 2313 | /** |
| 2314 | * Posts the specified command to be executed on the main thread, |
| 2315 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2316 | * if not timeout or null otherwise. |
| 2317 | * @see #sendRequestAsync |
| 2318 | */ |
| 2319 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2320 | long timeoutInMs) { |
| 2321 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | /** |
| 2325 | * Posts the specified command to be executed on the main thread, |
| 2326 | * waits for the request to complete, and returns the result. |
| 2327 | * @see #sendRequestAsync |
| 2328 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2329 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2330 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * Posts the specified command to be executed on the main thread, |
| 2335 | * waits for the request to complete, and returns the result. |
| 2336 | * @see #sendRequestAsync |
| 2337 | */ |
| 2338 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2339 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2340 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2344 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2345 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2346 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2347 | * @see #sendRequestAsync |
| 2348 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2349 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2350 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2351 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2352 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2353 | } |
| 2354 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2355 | MainThreadRequest request = null; |
| 2356 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2357 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2358 | } else if (phone != null) { |
| 2359 | request = new MainThreadRequest(argument, phone, workSource); |
| 2360 | } else { |
| 2361 | request = new MainThreadRequest(argument, subId, workSource); |
| 2362 | } |
| 2363 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2364 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2365 | msg.sendToTarget(); |
| 2366 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2367 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2369 | if (timeoutInMs >= 0) { |
| 2370 | // Wait for at least timeoutInMs before returning null request result |
| 2371 | long now = SystemClock.elapsedRealtime(); |
| 2372 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2373 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2374 | try { |
| 2375 | request.wait(deadline - now); |
| 2376 | } catch (InterruptedException e) { |
| 2377 | // Do nothing, go back and check if request is completed or timeout |
| 2378 | } finally { |
| 2379 | now = SystemClock.elapsedRealtime(); |
| 2380 | } |
| 2381 | } |
| 2382 | } else { |
| 2383 | // Wait for the request to complete |
| 2384 | while (request.result == null) { |
| 2385 | try { |
| 2386 | request.wait(); |
| 2387 | } catch (InterruptedException e) { |
| 2388 | // Do nothing, go back and wait until the request is complete |
| 2389 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2393 | if (request.result == null) { |
| 2394 | Log.wtf(LOG_TAG, |
| 2395 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2396 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | return request.result; |
| 2398 | } |
| 2399 | |
| 2400 | /** |
| 2401 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2402 | * Posts the specified command to be executed on the main thread, and |
| 2403 | * returns immediately. |
| 2404 | * @see #sendRequest |
| 2405 | */ |
| 2406 | private void sendRequestAsync(int command) { |
| 2407 | mMainThreadHandler.sendEmptyMessage(command); |
| 2408 | } |
| 2409 | |
| 2410 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2411 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2412 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2413 | */ |
| 2414 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2415 | sendRequestAsync(command, argument, null, null); |
| 2416 | } |
| 2417 | |
| 2418 | /** |
| 2419 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2420 | * @see {@link #sendRequest(int,Object)} |
| 2421 | */ |
| 2422 | private void sendRequestAsync( |
| 2423 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2424 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2425 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2426 | msg.sendToTarget(); |
| 2427 | } |
| 2428 | |
| 2429 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2431 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2432 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2433 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2434 | synchronized (PhoneInterfaceManager.class) { |
| 2435 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2436 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2437 | } else { |
| 2438 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2439 | } |
| 2440 | return sInstance; |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2445 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2446 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2447 | mFeatureFlags = featureFlags; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2449 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2450 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2451 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2452 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2453 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2454 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2455 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2456 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2457 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2458 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2459 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2460 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2461 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2464 | @VisibleForTesting |
| 2465 | public SharedPreferences getSharedPreferences() { |
| 2466 | return mTelephonySharedPreferences; |
| 2467 | } |
| 2468 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2469 | /** |
| 2470 | * Get the default phone for this device. |
| 2471 | */ |
| 2472 | @VisibleForTesting |
| 2473 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2474 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2475 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2476 | } |
| 2477 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | private void publish() { |
| 2479 | if (DBG) log("publish: " + this); |
| 2480 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2481 | TelephonyFrameworkInitializer |
| 2482 | .getTelephonyServiceManager() |
| 2483 | .getTelephonyServiceRegisterer() |
| 2484 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2487 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2488 | if (request.phone != null) { |
| 2489 | return request.phone; |
| 2490 | } else { |
| 2491 | return getPhoneFromSubId(request.subId); |
| 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | private Phone getPhoneFromSubId(int subId) { |
| 2496 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2497 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2498 | } |
| 2499 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2500 | /** |
| 2501 | * Get phone object associated with a subscription. |
| 2502 | * Return default phone if phone object associated with subscription is null |
| 2503 | * @param subId - subscriptionId |
| 2504 | * @return phone object associated with a subscription or default phone if null. |
| 2505 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2506 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2507 | Phone phone = getPhoneFromSubId(subId); |
| 2508 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2509 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2510 | phone = getDefaultPhone(); |
| 2511 | } |
| 2512 | return phone; |
| 2513 | } |
| 2514 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2515 | @Nullable |
| 2516 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2517 | Phone phone = getPhoneFromRequest(request); |
| 2518 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2519 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2520 | } |
| 2521 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2522 | /** |
| 2523 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2524 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2525 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2526 | * @return The Phone associated the sub Id |
| 2527 | */ |
| 2528 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2529 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2530 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2531 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2532 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2533 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2534 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2535 | } |
| 2536 | |
| 2537 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2538 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2539 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2542 | private boolean isImsAvailableOnDevice() { |
| 2543 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2544 | if (pm == null) { |
| 2545 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2546 | // so do not throw error and allow. |
| 2547 | return true; |
| 2548 | } |
| 2549 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2550 | } |
| 2551 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2552 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2553 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2556 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2557 | if (DBG) log("dial: " + number); |
| 2558 | // No permission check needed here: This is just a wrapper around the |
| 2559 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2560 | // the UI before it does anything. |
| 2561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | final long identity = Binder.clearCallingIdentity(); |
| 2563 | try { |
| 2564 | String url = createTelUrl(number); |
| 2565 | if (url == null) { |
| 2566 | return; |
| 2567 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2570 | PhoneConstants.State state = mCM.getState(subId); |
| 2571 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2572 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2573 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2574 | mApp.startActivity(intent); |
| 2575 | } |
| 2576 | } finally { |
| 2577 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2582 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2585 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2586 | if (DBG) log("call: " + number); |
| 2587 | |
| 2588 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2589 | // need to do a permission check since we're calling startActivity() |
| 2590 | // from the context of the phone app. |
| 2591 | enforceCallPermission(); |
| 2592 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2593 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2594 | != AppOpsManager.MODE_ALLOWED) { |
| 2595 | return; |
| 2596 | } |
| 2597 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
| 2600 | String url = createTelUrl(number); |
| 2601 | if (url == null) { |
| 2602 | return; |
| 2603 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2604 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2605 | boolean isValid = false; |
| 2606 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2607 | if (slist != null) { |
| 2608 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2609 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2610 | isValid = true; |
| 2611 | break; |
| 2612 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2613 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2614 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 | if (!isValid) { |
| 2616 | return; |
| 2617 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2620 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2621 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2622 | mApp.startActivity(intent); |
| 2623 | } finally { |
| 2624 | Binder.restoreCallingIdentity(identity); |
| 2625 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2628 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2629 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2630 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2631 | } |
| 2632 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2633 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2634 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2635 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2636 | } |
| 2637 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2638 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2639 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | |
| 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2643 | Phone phone = getPhone(subId); |
| 2644 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2645 | checkSimPin.start(); |
| 2646 | return checkSimPin.unlockSim(null, pin); |
| 2647 | } finally { |
| 2648 | Binder.restoreCallingIdentity(identity); |
| 2649 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2650 | } |
| 2651 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2652 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2653 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | |
| 2655 | final long identity = Binder.clearCallingIdentity(); |
| 2656 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2657 | Phone phone = getPhone(subId); |
| 2658 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | checkSimPuk.start(); |
| 2660 | return checkSimPuk.unlockSim(puk, pin); |
| 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
| 2663 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2667 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | * a synchronous one. |
| 2669 | */ |
| 2670 | private static class UnlockSim extends Thread { |
| 2671 | |
| 2672 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2673 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2674 | |
| 2675 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2676 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2677 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | |
| 2679 | // For replies from SimCard interface |
| 2680 | private Handler mHandler; |
| 2681 | |
| 2682 | // For async handler to identify request type |
| 2683 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2684 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2685 | UnlockSim(int phoneId, IccCard simCard) { |
| 2686 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | mSimCard = simCard; |
| 2688 | } |
| 2689 | |
| 2690 | @Override |
| 2691 | public void run() { |
| 2692 | Looper.prepare(); |
| 2693 | synchronized (UnlockSim.this) { |
| 2694 | mHandler = new Handler() { |
| 2695 | @Override |
| 2696 | public void handleMessage(Message msg) { |
| 2697 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2698 | switch (msg.what) { |
| 2699 | case SUPPLY_PIN_COMPLETE: |
| 2700 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2701 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2702 | mRetryCount = msg.arg1; |
| 2703 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2704 | CommandException.Error error = null; |
| 2705 | if (ar.exception instanceof CommandException) { |
| 2706 | error = ((CommandException) (ar.exception)) |
| 2707 | .getCommandError(); |
| 2708 | } |
| 2709 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2710 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2711 | } else if (error == CommandException.Error.ABORTED) { |
| 2712 | /* When UiccCardApp dispose, handle message and return |
| 2713 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2714 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2715 | } else { |
| 2716 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2717 | } |
| 2718 | } else { |
| 2719 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2720 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2721 | mDone = true; |
| 2722 | UnlockSim.this.notifyAll(); |
| 2723 | } |
| 2724 | break; |
| 2725 | } |
| 2726 | } |
| 2727 | }; |
| 2728 | UnlockSim.this.notifyAll(); |
| 2729 | } |
| 2730 | Looper.loop(); |
| 2731 | } |
| 2732 | |
| 2733 | /* |
| 2734 | * Use PIN or PUK to unlock SIM card |
| 2735 | * |
| 2736 | * If PUK is null, unlock SIM card with PIN |
| 2737 | * |
| 2738 | * 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] | 2739 | * |
| 2740 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2741 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2743 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2744 | |
| 2745 | while (mHandler == null) { |
| 2746 | try { |
| 2747 | wait(); |
| 2748 | } catch (InterruptedException e) { |
| 2749 | Thread.currentThread().interrupt(); |
| 2750 | } |
| 2751 | } |
| 2752 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2753 | |
| 2754 | if (puk == null) { |
| 2755 | mSimCard.supplyPin(pin, callback); |
| 2756 | } else { |
| 2757 | mSimCard.supplyPuk(puk, pin, callback); |
| 2758 | } |
| 2759 | |
| 2760 | while (!mDone) { |
| 2761 | try { |
| 2762 | Log.d(LOG_TAG, "wait for done"); |
| 2763 | wait(); |
| 2764 | } catch (InterruptedException e) { |
| 2765 | // Restore the interrupted status |
| 2766 | Thread.currentThread().interrupt(); |
| 2767 | } |
| 2768 | } |
| 2769 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2770 | int[] resultArray = new int[2]; |
| 2771 | resultArray[0] = mResult; |
| 2772 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2773 | |
| 2774 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2775 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2776 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2777 | // This instance is no longer reused, so quit its thread's looper. |
| 2778 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2779 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2780 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2784 | /** |
| 2785 | * This method has been removed due to privacy and stability concerns. |
| 2786 | */ |
| 2787 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2788 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2789 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2790 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2793 | @Override |
| 2794 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2795 | mApp.getSystemService(AppOpsManager.class) |
| 2796 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2797 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2798 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2799 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2800 | // Callers targeting S have no business invoking this method. |
| 2801 | return; |
| 2802 | } |
| 2803 | |
| 2804 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2805 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2806 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2807 | .setCallingPackage(callingPackage) |
| 2808 | .setCallingFeatureId(null) |
| 2809 | .setCallingPid(Binder.getCallingPid()) |
| 2810 | .setCallingUid(Binder.getCallingUid()) |
| 2811 | .setMethod("updateServiceLocation") |
| 2812 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2813 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2814 | .build()); |
| 2815 | // Apps that lack location permission have no business calling this method; |
| 2816 | // however, because no permission was declared in the public API, denials must |
| 2817 | // all be "soft". |
| 2818 | switch (locationResult) { |
| 2819 | case DENIED_HARD: /* fall through */ |
| 2820 | case DENIED_SOFT: |
| 2821 | return; |
| 2822 | } |
| 2823 | |
| 2824 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2825 | final long identity = Binder.clearCallingIdentity(); |
| 2826 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2827 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2830 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2833 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2834 | @Override |
| 2835 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2836 | return isRadioOnWithFeature(callingPackage, null); |
| 2837 | } |
| 2838 | |
| 2839 | |
| 2840 | @Override |
| 2841 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2842 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2843 | callingFeatureId); |
| 2844 | } |
| 2845 | |
| 2846 | @Deprecated |
| 2847 | @Override |
| 2848 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2849 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2852 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2853 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2854 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2855 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2856 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2857 | return false; |
| 2858 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2859 | |
| 2860 | final long identity = Binder.clearCallingIdentity(); |
| 2861 | try { |
| 2862 | return isRadioOnForSubscriber(subId); |
| 2863 | } finally { |
| 2864 | Binder.restoreCallingIdentity(identity); |
| 2865 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2869 | final long identity = Binder.clearCallingIdentity(); |
| 2870 | try { |
| 2871 | final Phone phone = getPhone(subId); |
| 2872 | if (phone != null) { |
| 2873 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2874 | } else { |
| 2875 | return false; |
| 2876 | } |
| 2877 | } finally { |
| 2878 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2879 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
| 2882 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2883 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2884 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2885 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2886 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2887 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2888 | |
| 2889 | final long identity = Binder.clearCallingIdentity(); |
| 2890 | try { |
| 2891 | final Phone phone = getPhone(subId); |
| 2892 | if (phone != null) { |
| 2893 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2894 | } |
| 2895 | } finally { |
| 2896 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2897 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2901 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2904 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2905 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2906 | |
| 2907 | final long identity = Binder.clearCallingIdentity(); |
| 2908 | try { |
| 2909 | final Phone phone = getPhone(subId); |
| 2910 | if (phone == null) { |
| 2911 | return false; |
| 2912 | } |
| 2913 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2914 | toggleRadioOnOffForSubscriber(subId); |
| 2915 | } |
| 2916 | return true; |
| 2917 | } finally { |
| 2918 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2919 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2921 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2922 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2923 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2924 | /* |
| 2925 | * If any of the Radios are available, it will need to be |
| 2926 | * shutdown. So return true if any Radio is available. |
| 2927 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2928 | final long identity = Binder.clearCallingIdentity(); |
| 2929 | try { |
| 2930 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2931 | Phone phone = PhoneFactory.getPhone(i); |
| 2932 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2933 | } |
| 2934 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2935 | return false; |
| 2936 | } finally { |
| 2937 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2938 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2941 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2942 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2943 | enforceModifyPermission(); |
| 2944 | |
| 2945 | final long identity = Binder.clearCallingIdentity(); |
| 2946 | try { |
| 2947 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2948 | logv("Shutting down Phone " + i); |
| 2949 | shutdownRadioUsingPhoneId(i); |
| 2950 | } |
| 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2957 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2958 | if (phone != null && phone.isRadioAvailable()) { |
| 2959 | phone.shutdownRadio(); |
| 2960 | } |
| 2961 | } |
| 2962 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2963 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2964 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2965 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2966 | if (!turnOn) { |
| 2967 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 2968 | } |
| 2969 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2970 | final long identity = Binder.clearCallingIdentity(); |
| 2971 | try { |
| 2972 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2973 | if (defaultPhone != null) { |
| 2974 | defaultPhone.setRadioPower(turnOn); |
| 2975 | return true; |
| 2976 | } else { |
| 2977 | loge("There's no default phone."); |
| 2978 | return false; |
| 2979 | } |
| 2980 | } finally { |
| 2981 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2982 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2983 | } |
| 2984 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2985 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2986 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2987 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2988 | if (!turnOn) { |
| 2989 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 2990 | + ",callingPackage=" + getCurrentPackageName()); |
| 2991 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | final Phone phone = getPhone(subId); |
| 2995 | if (phone != null) { |
| 2996 | phone.setRadioPower(turnOn); |
| 2997 | return true; |
| 2998 | } else { |
| 2999 | return false; |
| 3000 | } |
| 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3003 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3006 | /** |
| 3007 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3008 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3009 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3010 | * powering it off, and these radio off votes will be cleared. |
| 3011 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3012 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3013 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3014 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3015 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3016 | * check its vote. |
| 3017 | * |
| 3018 | * @param subId The subscription ID. |
| 3019 | * @param reason The reason for powering off radio. |
| 3020 | * @return true on success and false on failure. |
| 3021 | */ |
| 3022 | public boolean requestRadioPowerOffForReason(int subId, |
| 3023 | @TelephonyManager.RadioPowerReason int reason) { |
| 3024 | enforceModifyPermission(); |
| 3025 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3026 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3027 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3028 | final long identity = Binder.clearCallingIdentity(); |
| 3029 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3030 | boolean result = false; |
| 3031 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3032 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3033 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3034 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3035 | if (!result) { |
| 3036 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3037 | } |
| 3038 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3039 | } finally { |
| 3040 | Binder.restoreCallingIdentity(identity); |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | /** |
| 3045 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3046 | * {@link requestRadioPowerOffForReason}. |
| 3047 | * |
| 3048 | * @param subId The subscription ID. |
| 3049 | * @param reason The reason for powering off radio. |
| 3050 | * @return true on success and false on failure. |
| 3051 | */ |
| 3052 | public boolean clearRadioPowerOffForReason(int subId, |
| 3053 | @TelephonyManager.RadioPowerReason int reason) { |
| 3054 | enforceModifyPermission(); |
| 3055 | |
| 3056 | final long identity = Binder.clearCallingIdentity(); |
| 3057 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3058 | boolean result = false; |
| 3059 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3060 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3061 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3062 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3063 | if (!result) { |
| 3064 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3065 | } |
| 3066 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3067 | } finally { |
| 3068 | Binder.restoreCallingIdentity(identity); |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | /** |
| 3073 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3074 | * |
| 3075 | * @param subId The subscription ID. |
| 3076 | * @param callingPackage The package making the call. |
| 3077 | * @param callingFeatureId The feature in the package. |
| 3078 | * @return List of reasons for powering off radio. |
| 3079 | */ |
| 3080 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3081 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3082 | |
| 3083 | final long identity = Binder.clearCallingIdentity(); |
| 3084 | List result = new ArrayList(); |
| 3085 | try { |
| 3086 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3087 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3088 | return result; |
| 3089 | } |
| 3090 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3091 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3092 | if (phone != null) { |
| 3093 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3094 | } else { |
| 3095 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3096 | } |
| 3097 | } finally { |
| 3098 | Binder.restoreCallingIdentity(identity); |
| 3099 | } |
| 3100 | return result; |
| 3101 | } |
| 3102 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3103 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3104 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3105 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3106 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3107 | |
| 3108 | final long identity = Binder.clearCallingIdentity(); |
| 3109 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3110 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3111 | final Phone phone = getPhone(subId); |
| 3112 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3113 | phone.getDataSettingsManager().setDataEnabled( |
| 3114 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3115 | return true; |
| 3116 | } else { |
| 3117 | return false; |
| 3118 | } |
| 3119 | } finally { |
| 3120 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3121 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3124 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3125 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3126 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3127 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3128 | |
| 3129 | final long identity = Binder.clearCallingIdentity(); |
| 3130 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3131 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3132 | final Phone phone = getPhone(subId); |
| 3133 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3134 | phone.getDataSettingsManager().setDataEnabled( |
| 3135 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3136 | return true; |
| 3137 | } else { |
| 3138 | return false; |
| 3139 | } |
| 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3142 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3145 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3146 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3147 | final long identity = Binder.clearCallingIdentity(); |
| 3148 | try { |
| 3149 | final Phone phone = getPhone(subId); |
| 3150 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3151 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3152 | } else { |
| 3153 | return false; |
| 3154 | } |
| 3155 | } finally { |
| 3156 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3157 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3161 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3164 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3165 | enforceCallPermission(); |
| 3166 | |
| 3167 | final long identity = Binder.clearCallingIdentity(); |
| 3168 | try { |
| 3169 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3170 | return; |
| 3171 | } |
| 3172 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3173 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
| 3176 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3177 | }; |
| 3178 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3179 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3180 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3181 | |
| 3182 | final long identity = Binder.clearCallingIdentity(); |
| 3183 | try { |
| 3184 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3185 | return false; |
| 3186 | } |
| 3187 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3188 | } finally { |
| 3189 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3190 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3193 | /** |
| 3194 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3195 | * tag on getCallState Binder call. |
| 3196 | */ |
| 3197 | @Deprecated |
| 3198 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3199 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3200 | if (CompatChanges.isChangeEnabled( |
| 3201 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3202 | Binder.getCallingUid())) { |
| 3203 | // Do not allow this API to be called on API version 31+, it should only be |
| 3204 | // called on old apps using this Binder call directly. |
| 3205 | throw new SecurityException("This method can only be used for applications " |
| 3206 | + "targeting API version 30 or less."); |
| 3207 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3210 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3211 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3212 | } finally { |
| 3213 | Binder.restoreCallingIdentity(identity); |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | @Override |
| 3218 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3219 | if (CompatChanges.isChangeEnabled( |
| 3220 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3221 | Binder.getCallingUid())) { |
| 3222 | // Check READ_PHONE_STATE for API version 31+ |
| 3223 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3224 | featureId, "getCallStateForSubscription")) { |
| 3225 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3226 | + "targeting API level 31+."); |
| 3227 | } |
| 3228 | } |
| 3229 | final long identity = Binder.clearCallingIdentity(); |
| 3230 | try { |
| 3231 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3232 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3233 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
| 3236 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3239 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3240 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3241 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | @Override |
| 3245 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3246 | final long identity = Binder.clearCallingIdentity(); |
| 3247 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3248 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3249 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3250 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | } else { |
| 3252 | return PhoneConstantConversions.convertDataState( |
| 3253 | PhoneConstants.DataState.DISCONNECTED); |
| 3254 | } |
| 3255 | } finally { |
| 3256 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3260 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3261 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3262 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3266 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3267 | final long identity = Binder.clearCallingIdentity(); |
| 3268 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3269 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3270 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3271 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | } else { |
| 3273 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3274 | } |
| 3275 | } finally { |
| 3276 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3277 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3281 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3282 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3283 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3284 | |
| 3285 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3286 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3287 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3288 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3289 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3290 | .setCallingPid(Binder.getCallingPid()) |
| 3291 | .setCallingUid(Binder.getCallingUid()) |
| 3292 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3293 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3294 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3295 | .build()); |
| 3296 | switch (locationResult) { |
| 3297 | case DENIED_HARD: |
| 3298 | throw new SecurityException("Not allowed to access cell location"); |
| 3299 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3300 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3301 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3302 | } |
| 3303 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3304 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3305 | final long identity = Binder.clearCallingIdentity(); |
| 3306 | try { |
| 3307 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3308 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3309 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3310 | } finally { |
| 3311 | Binder.restoreCallingIdentity(identity); |
| 3312 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3313 | } |
| 3314 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3315 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3316 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3317 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3318 | // registered cell info, so return a NULL country instead. |
| 3319 | final long identity = Binder.clearCallingIdentity(); |
| 3320 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3321 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3322 | // Get default phone in this case. |
| 3323 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3324 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3325 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3326 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3327 | if (phone == null) return ""; |
| 3328 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3329 | if (sst == null) return ""; |
| 3330 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3331 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3332 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3333 | } finally { |
| 3334 | Binder.restoreCallingIdentity(identity); |
| 3335 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3336 | } |
| 3337 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3338 | /** |
| 3339 | * This method was removed due to potential issues caused by performing partial |
| 3340 | * updates of service state, and lack of a credible use case. |
| 3341 | * |
| 3342 | * This has the ability to break the telephony implementation by disabling notification of |
| 3343 | * changes in device connectivity. DO NOT USE THIS! |
| 3344 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3345 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3346 | public void enableLocationUpdates() { |
| 3347 | mApp.enforceCallingOrSelfPermission( |
| 3348 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3351 | /** |
| 3352 | * This method was removed due to potential issues caused by performing partial |
| 3353 | * updates of service state, and lack of a credible use case. |
| 3354 | * |
| 3355 | * This has the ability to break the telephony implementation by disabling notification of |
| 3356 | * changes in device connectivity. DO NOT USE THIS! |
| 3357 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3358 | @Override |
| 3359 | public void disableLocationUpdates() { |
| 3360 | mApp.enforceCallingOrSelfPermission( |
| 3361 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | @Override |
| 3365 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3366 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3367 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3368 | try { |
| 3369 | mApp.getSystemService(AppOpsManager.class) |
| 3370 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3371 | } catch (SecurityException e) { |
| 3372 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3373 | throw e; |
| 3374 | } |
| 3375 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3376 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3377 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3378 | throw new SecurityException( |
| 3379 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3380 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3381 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3382 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3383 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3384 | return null; |
| 3385 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3386 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3387 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3388 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3389 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3390 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3391 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3392 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3393 | for (CellInfo ci : info) { |
| 3394 | if (ci instanceof CellInfoGsm) { |
| 3395 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3396 | } else if (ci instanceof CellInfoWcdma) { |
| 3397 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3399 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3400 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3403 | private List<CellInfo> getCachedCellInfo() { |
| 3404 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3405 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3406 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3407 | if (info != null) cellInfos.addAll(info); |
| 3408 | } |
| 3409 | return cellInfos; |
| 3410 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3411 | |
| 3412 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3413 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3414 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3415 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3416 | |
| 3417 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3418 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3419 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3420 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3421 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3422 | .setCallingPid(Binder.getCallingPid()) |
| 3423 | .setCallingUid(Binder.getCallingUid()) |
| 3424 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3425 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3426 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3427 | .build()); |
| 3428 | switch (locationResult) { |
| 3429 | case DENIED_HARD: |
| 3430 | throw new SecurityException("Not allowed to access cell info"); |
| 3431 | case DENIED_SOFT: |
| 3432 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3435 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3436 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3437 | return getCachedCellInfo(); |
| 3438 | } |
| 3439 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3440 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3441 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3442 | final long identity = Binder.clearCallingIdentity(); |
| 3443 | try { |
| 3444 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3445 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3446 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3447 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | if (info != null) cellInfos.addAll(info); |
| 3449 | } |
| 3450 | return cellInfos; |
| 3451 | } finally { |
| 3452 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3453 | } |
| 3454 | } |
| 3455 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3456 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3457 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3458 | String callingFeatureId) { |
| 3459 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3460 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3464 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3465 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3466 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3467 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3468 | } |
| 3469 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3470 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3471 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3472 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3473 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3474 | |
| 3475 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3476 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3477 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3478 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3479 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3480 | .setCallingPid(Binder.getCallingPid()) |
| 3481 | .setCallingUid(Binder.getCallingUid()) |
| 3482 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3483 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3484 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3485 | .build()); |
| 3486 | switch (locationResult) { |
| 3487 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3488 | if (TelephonyPermissions |
| 3489 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3490 | // Safetynet logging for b/154934934 |
| 3491 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3492 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3493 | throw new SecurityException("Not allowed to access cell info"); |
| 3494 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3495 | if (TelephonyPermissions |
| 3496 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3497 | // Safetynet logging for b/154934934 |
| 3498 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3499 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3500 | try { |
| 3501 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3502 | } catch (RemoteException re) { |
| 3503 | // Drop without consequences |
| 3504 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3505 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3508 | |
| 3509 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3510 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3511 | |
| 3512 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3513 | } |
| 3514 | |
| 3515 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3516 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3517 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3518 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3519 | |
| 3520 | final long identity = Binder.clearCallingIdentity(); |
| 3521 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3522 | Phone phone = getPhone(subId); |
| 3523 | if (phone == null) { |
| 3524 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3525 | } else { |
| 3526 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3527 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | } finally { |
| 3529 | Binder.restoreCallingIdentity(identity); |
| 3530 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3533 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3534 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3535 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3536 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3537 | return null; |
| 3538 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3539 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3540 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3541 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3542 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3543 | return null; |
| 3544 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3545 | |
| 3546 | final long identity = Binder.clearCallingIdentity(); |
| 3547 | try { |
| 3548 | return phone.getImei(); |
| 3549 | } finally { |
| 3550 | Binder.restoreCallingIdentity(identity); |
| 3551 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3555 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3556 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3557 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3558 | callingFeatureId, "getPrimaryImei")) { |
| 3559 | throw new SecurityException("Caller does not have permission"); |
| 3560 | } |
| 3561 | final long identity = Binder.clearCallingIdentity(); |
| 3562 | try { |
| 3563 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3564 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3565 | return phone.getImei(); |
| 3566 | } |
| 3567 | } |
| 3568 | throw new UnsupportedOperationException("Operation not supported"); |
| 3569 | } finally { |
| 3570 | Binder.restoreCallingIdentity(identity); |
| 3571 | } |
| 3572 | } |
| 3573 | |
| 3574 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3575 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3576 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3577 | String tac = null; |
| 3578 | if (phone != null) { |
| 3579 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3580 | try { |
| 3581 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3582 | } catch (IndexOutOfBoundsException e) { |
| 3583 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3584 | return null; |
| 3585 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3586 | } |
| 3587 | return tac; |
| 3588 | } |
| 3589 | |
| 3590 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3591 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3592 | try { |
| 3593 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3594 | } catch (SecurityException se) { |
| 3595 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3596 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3597 | + Binder.getCallingUid()); |
| 3598 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3599 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3600 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3601 | return null; |
| 3602 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3603 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3604 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3605 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3606 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3607 | return null; |
| 3608 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3609 | |
| 3610 | final long identity = Binder.clearCallingIdentity(); |
| 3611 | try { |
| 3612 | return phone.getMeid(); |
| 3613 | } finally { |
| 3614 | Binder.restoreCallingIdentity(identity); |
| 3615 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3619 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3620 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3621 | String manufacturerCode = null; |
| 3622 | if (phone != null) { |
| 3623 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3624 | try { |
| 3625 | manufacturerCode = |
| 3626 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3627 | } catch (IndexOutOfBoundsException e) { |
| 3628 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3629 | return null; |
| 3630 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3631 | } |
| 3632 | return manufacturerCode; |
| 3633 | } |
| 3634 | |
| 3635 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3636 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3637 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3638 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3639 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3640 | return null; |
| 3641 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3642 | int subId = phone.getSubId(); |
| 3643 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3644 | mApp, subId, callingPackage, callingFeatureId, |
| 3645 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3646 | return null; |
| 3647 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3648 | |
| 3649 | final long identity = Binder.clearCallingIdentity(); |
| 3650 | try { |
| 3651 | return phone.getDeviceSvn(); |
| 3652 | } finally { |
| 3653 | Binder.restoreCallingIdentity(identity); |
| 3654 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3655 | } |
| 3656 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3657 | @Override |
| 3658 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3659 | final long identity = Binder.clearCallingIdentity(); |
| 3660 | try { |
| 3661 | final Phone phone = getPhone(subId); |
| 3662 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(identity); |
| 3665 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | @Override |
| 3669 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3670 | final long identity = Binder.clearCallingIdentity(); |
| 3671 | try { |
| 3672 | final Phone phone = getPhone(subId); |
| 3673 | return phone == null ? null : phone.getCarrierName(); |
| 3674 | } finally { |
| 3675 | Binder.restoreCallingIdentity(identity); |
| 3676 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3677 | } |
| 3678 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3679 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3680 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3681 | final long identity = Binder.clearCallingIdentity(); |
| 3682 | try { |
| 3683 | final Phone phone = getPhone(subId); |
| 3684 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3685 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3686 | } finally { |
| 3687 | Binder.restoreCallingIdentity(identity); |
| 3688 | } |
| 3689 | } |
| 3690 | |
| 3691 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3692 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3693 | final long identity = Binder.clearCallingIdentity(); |
| 3694 | try { |
| 3695 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3696 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3697 | } finally { |
| 3698 | Binder.restoreCallingIdentity(identity); |
| 3699 | } |
| 3700 | } |
| 3701 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3702 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3703 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3704 | if (!isSubscriptionMccMnc) { |
| 3705 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3706 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3707 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3708 | if (phone == null) { |
| 3709 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3710 | } |
| 3711 | final long identity = Binder.clearCallingIdentity(); |
| 3712 | try { |
| 3713 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3714 | } finally { |
| 3715 | Binder.restoreCallingIdentity(identity); |
| 3716 | } |
| 3717 | } |
| 3718 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3719 | // |
| 3720 | // Internal helper methods. |
| 3721 | // |
| 3722 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3723 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3724 | * Make sure the caller is the calling package itself |
| 3725 | * |
| 3726 | * @throws SecurityException if the caller is not the calling package |
| 3727 | */ |
| 3728 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3729 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3730 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3731 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3732 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3733 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3734 | } catch (PackageManager.NameNotFoundException e) { |
| 3735 | // packageUid is -1 |
| 3736 | } |
| 3737 | if (packageUid != callingUid) { |
| 3738 | throw new SecurityException(message + ": Package " + callingPackage |
| 3739 | + " does not belong to " + callingUid); |
| 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3744 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3745 | * |
| 3746 | * @throws SecurityException if the caller does not have the required permission |
| 3747 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3748 | @VisibleForTesting |
| 3749 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3750 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3751 | } |
| 3752 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3753 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3754 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3755 | * |
| 3756 | * @throws SecurityException if the caller does not have the required permission |
| 3757 | */ |
| 3758 | @VisibleForTesting |
| 3759 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3760 | enforceReadPermission(null); |
| 3761 | } |
| 3762 | |
| 3763 | /** |
| 3764 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3765 | * |
| 3766 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3767 | */ |
| 3768 | @VisibleForTesting |
| 3769 | public void enforceReadPermission(String msg) { |
| 3770 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3773 | private void enforceActiveEmergencySessionPermission() { |
| 3774 | mApp.enforceCallingOrSelfPermission( |
| 3775 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3776 | } |
| 3777 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3778 | /** |
| 3779 | * Make sure the caller has the CALL_PHONE permission. |
| 3780 | * |
| 3781 | * @throws SecurityException if the caller does not have the required permission |
| 3782 | */ |
| 3783 | private void enforceCallPermission() { |
| 3784 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3785 | } |
| 3786 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3787 | private void enforceSettingsPermission() { |
| 3788 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3789 | } |
| 3790 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3791 | private void enforceRebootPermission() { |
| 3792 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3793 | } |
| 3794 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3795 | /** |
| 3796 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3797 | * @param message - log message to print. |
| 3798 | * @throws SecurityException if the caller does not have the required permission |
| 3799 | */ |
| 3800 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3801 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3802 | } |
| 3803 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3804 | private String createTelUrl(String number) { |
| 3805 | if (TextUtils.isEmpty(number)) { |
| 3806 | return null; |
| 3807 | } |
| 3808 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3809 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3812 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3813 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3816 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3817 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3820 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3821 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3822 | } |
| 3823 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3824 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3825 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3826 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3827 | } |
| 3828 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3829 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3830 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | final long identity = Binder.clearCallingIdentity(); |
| 3832 | try { |
| 3833 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3834 | if (phone == null) { |
| 3835 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3836 | } else { |
| 3837 | return phone.getPhoneType(); |
| 3838 | } |
| 3839 | } finally { |
| 3840 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3841 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | /** |
| 3845 | * Returns the CDMA ERI icon index to display |
| 3846 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3847 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3848 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3849 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3850 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3851 | } |
| 3852 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3853 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3854 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3855 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3856 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3857 | mApp, subId, callingPackage, callingFeatureId, |
| 3858 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3859 | return -1; |
| 3860 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3861 | |
| 3862 | final long identity = Binder.clearCallingIdentity(); |
| 3863 | try { |
| 3864 | final Phone phone = getPhone(subId); |
| 3865 | if (phone != null) { |
| 3866 | return phone.getCdmaEriIconIndex(); |
| 3867 | } else { |
| 3868 | return -1; |
| 3869 | } |
| 3870 | } finally { |
| 3871 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3872 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | /** |
| 3876 | * Returns the CDMA ERI icon mode, |
| 3877 | * 0 - ON |
| 3878 | * 1 - FLASHING |
| 3879 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3880 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3881 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3882 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3883 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3884 | } |
| 3885 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3886 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3887 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3888 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3889 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3890 | mApp, subId, callingPackage, callingFeatureId, |
| 3891 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3892 | return -1; |
| 3893 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3894 | |
| 3895 | final long identity = Binder.clearCallingIdentity(); |
| 3896 | try { |
| 3897 | final Phone phone = getPhone(subId); |
| 3898 | if (phone != null) { |
| 3899 | return phone.getCdmaEriIconMode(); |
| 3900 | } else { |
| 3901 | return -1; |
| 3902 | } |
| 3903 | } finally { |
| 3904 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3905 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | /** |
| 3909 | * Returns the CDMA ERI text, |
| 3910 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3911 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3912 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3913 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3914 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3917 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3918 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3919 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3920 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3921 | mApp, subId, callingPackage, callingFeatureId, |
| 3922 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3923 | return null; |
| 3924 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3925 | |
| 3926 | final long identity = Binder.clearCallingIdentity(); |
| 3927 | try { |
| 3928 | final Phone phone = getPhone(subId); |
| 3929 | if (phone != null) { |
| 3930 | return phone.getCdmaEriText(); |
| 3931 | } else { |
| 3932 | return null; |
| 3933 | } |
| 3934 | } finally { |
| 3935 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3936 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3940 | * Returns the CDMA MDN. |
| 3941 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3942 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3943 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3945 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3946 | |
| 3947 | final long identity = Binder.clearCallingIdentity(); |
| 3948 | try { |
| 3949 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3950 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3951 | return phone.getLine1Number(); |
| 3952 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3953 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3954 | return null; |
| 3955 | } |
| 3956 | } finally { |
| 3957 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | /** |
| 3962 | * Returns the CDMA MIN. |
| 3963 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3964 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3965 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3967 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3968 | |
| 3969 | final long identity = Binder.clearCallingIdentity(); |
| 3970 | try { |
| 3971 | final Phone phone = getPhone(subId); |
| 3972 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3973 | return phone.getCdmaMin(); |
| 3974 | } else { |
| 3975 | return null; |
| 3976 | } |
| 3977 | } finally { |
| 3978 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3979 | } |
| 3980 | } |
| 3981 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3982 | @Override |
| 3983 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3984 | INumberVerificationCallback callback, String callingPackage) { |
| 3985 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3986 | != PERMISSION_GRANTED) { |
| 3987 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3988 | } |
| 3989 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3990 | |
| 3991 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3992 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3993 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3994 | + "calling package: " + callingPackage |
| 3995 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | if (range == null) { |
| 3999 | throw new NullPointerException("Range must be non-null"); |
| 4000 | } |
| 4001 | |
| 4002 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4003 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4004 | |
| 4005 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4006 | } |
| 4007 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4008 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4009 | * Returns true if CDMA provisioning needs to run. |
| 4010 | */ |
| 4011 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4012 | final long identity = Binder.clearCallingIdentity(); |
| 4013 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4014 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4015 | } finally { |
| 4016 | Binder.restoreCallingIdentity(identity); |
| 4017 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4021 | * Sets the voice mail number of a given subId. |
| 4022 | */ |
| 4023 | @Override |
| 4024 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4025 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4026 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4027 | |
| 4028 | final long identity = Binder.clearCallingIdentity(); |
| 4029 | try { |
| 4030 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4031 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4032 | return success; |
| 4033 | } finally { |
| 4034 | Binder.restoreCallingIdentity(identity); |
| 4035 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4036 | } |
| 4037 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4038 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4039 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4040 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4041 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4042 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4043 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4044 | throw new SecurityException("caller must be system dialer"); |
| 4045 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4046 | |
| 4047 | final long identity = Binder.clearCallingIdentity(); |
| 4048 | try { |
| 4049 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4050 | if (phoneAccountHandle == null) { |
| 4051 | return null; |
| 4052 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4053 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4054 | } finally { |
| 4055 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4056 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4060 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4061 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4062 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4063 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4064 | mApp, subId, callingPackage, callingFeatureId, |
| 4065 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4066 | return null; |
| 4067 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4069 | final long identity = Binder.clearCallingIdentity(); |
| 4070 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4071 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4072 | } finally { |
| 4073 | Binder.restoreCallingIdentity(identity); |
| 4074 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4078 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4079 | VisualVoicemailSmsFilterSettings settings) { |
| 4080 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4081 | |
| 4082 | final long identity = Binder.clearCallingIdentity(); |
| 4083 | try { |
| 4084 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4085 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4086 | } finally { |
| 4087 | Binder.restoreCallingIdentity(identity); |
| 4088 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4092 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4093 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4094 | |
| 4095 | final long identity = Binder.clearCallingIdentity(); |
| 4096 | try { |
| 4097 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4098 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4099 | } finally { |
| 4100 | Binder.restoreCallingIdentity(identity); |
| 4101 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4105 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4106 | String callingPackage, int subId) { |
| 4107 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4108 | |
| 4109 | final long identity = Binder.clearCallingIdentity(); |
| 4110 | try { |
| 4111 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4112 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
| 4115 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4119 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4120 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4121 | |
| 4122 | final long identity = Binder.clearCallingIdentity(); |
| 4123 | try { |
| 4124 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4125 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4126 | } finally { |
| 4127 | Binder.restoreCallingIdentity(identity); |
| 4128 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4132 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4133 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4134 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4135 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4136 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4137 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4138 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4139 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4140 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4141 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4142 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4143 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4144 | * Sets the voice activation state of a given subId. |
| 4145 | */ |
| 4146 | @Override |
| 4147 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4148 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4149 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4150 | |
| 4151 | final long identity = Binder.clearCallingIdentity(); |
| 4152 | try { |
| 4153 | final Phone phone = getPhone(subId); |
| 4154 | if (phone != null) { |
| 4155 | phone.setVoiceActivationState(activationState); |
| 4156 | } else { |
| 4157 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4158 | } |
| 4159 | } finally { |
| 4160 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | |
| 4164 | /** |
| 4165 | * Sets the data activation state of a given subId. |
| 4166 | */ |
| 4167 | @Override |
| 4168 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4169 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4170 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4171 | |
| 4172 | final long identity = Binder.clearCallingIdentity(); |
| 4173 | try { |
| 4174 | final Phone phone = getPhone(subId); |
| 4175 | if (phone != null) { |
| 4176 | phone.setDataActivationState(activationState); |
| 4177 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4178 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4179 | } |
| 4180 | } finally { |
| 4181 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4182 | } |
| 4183 | } |
| 4184 | |
| 4185 | /** |
| 4186 | * Returns the voice activation state of a given subId. |
| 4187 | */ |
| 4188 | @Override |
| 4189 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4190 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4191 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4192 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4193 | final long identity = Binder.clearCallingIdentity(); |
| 4194 | try { |
| 4195 | if (phone != null) { |
| 4196 | return phone.getVoiceActivationState(); |
| 4197 | } else { |
| 4198 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4199 | } |
| 4200 | } finally { |
| 4201 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4202 | } |
| 4203 | } |
| 4204 | |
| 4205 | /** |
| 4206 | * Returns the data activation state of a given subId. |
| 4207 | */ |
| 4208 | @Override |
| 4209 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4210 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4211 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4212 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | final long identity = Binder.clearCallingIdentity(); |
| 4214 | try { |
| 4215 | if (phone != null) { |
| 4216 | return phone.getDataActivationState(); |
| 4217 | } else { |
| 4218 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4219 | } |
| 4220 | } finally { |
| 4221 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4222 | } |
| 4223 | } |
| 4224 | |
| 4225 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4226 | * Returns the unread count of voicemails for a subId |
| 4227 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4228 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4229 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4230 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4231 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4232 | mApp, subId, callingPackage, callingFeatureId, |
| 4233 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4234 | return 0; |
| 4235 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4236 | final long identity = Binder.clearCallingIdentity(); |
| 4237 | try { |
| 4238 | final Phone phone = getPhone(subId); |
| 4239 | if (phone != null) { |
| 4240 | return phone.getVoiceMessageCount(); |
| 4241 | } else { |
| 4242 | return 0; |
| 4243 | } |
| 4244 | } finally { |
| 4245 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4246 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4250 | * returns true, if the device is in a state where both voice and data |
| 4251 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4252 | */ |
| 4253 | @Override |
| 4254 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4255 | final long identity = Binder.clearCallingIdentity(); |
| 4256 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4257 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4258 | } finally { |
| 4259 | Binder.restoreCallingIdentity(identity); |
| 4260 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4264 | * Send the dialer code if called from the current default dialer or the caller has |
| 4265 | * carrier privilege. |
| 4266 | * @param inputCode The dialer code to send |
| 4267 | */ |
| 4268 | @Override |
| 4269 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4270 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4271 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4272 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4273 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4274 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4275 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4276 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4277 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4278 | |
| 4279 | final long identity = Binder.clearCallingIdentity(); |
| 4280 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4281 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4282 | } finally { |
| 4283 | Binder.restoreCallingIdentity(identity); |
| 4284 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4285 | } |
| 4286 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4287 | @Override |
| 4288 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4289 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4290 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4291 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4292 | final long identity = Binder.clearCallingIdentity(); |
| 4293 | try { |
| 4294 | if (!isActiveSubscription(subId)) { |
| 4295 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4296 | } |
| 4297 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4298 | } finally { |
| 4299 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4300 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4303 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4304 | public boolean isInEmergencySmsMode() { |
| 4305 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4306 | final long identity = Binder.clearCallingIdentity(); |
| 4307 | try { |
| 4308 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4309 | if (phone.isInEmergencySmsMode()) { |
| 4310 | return true; |
| 4311 | } |
| 4312 | } |
| 4313 | } finally { |
| 4314 | Binder.restoreCallingIdentity(identity); |
| 4315 | } |
| 4316 | return false; |
| 4317 | } |
| 4318 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4319 | /** |
| 4320 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4321 | * @param subId The subscription to use to check the configuration. |
| 4322 | * @param c The callback that will be used to send the result. |
| 4323 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4324 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4325 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4326 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4327 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4328 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4329 | |
| 4330 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4331 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4332 | "IMS not available on device."); |
| 4333 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4334 | final long token = Binder.clearCallingIdentity(); |
| 4335 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4336 | int slotId = getSlotIndexOrException(subId); |
| 4337 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4338 | |
| 4339 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4340 | if (controller != null) { |
| 4341 | ImsManager imsManager = controller.getImsManager(subId); |
| 4342 | if (imsManager != null) { |
| 4343 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4344 | } else { |
| 4345 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4346 | } |
| 4347 | } else { |
| 4348 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4349 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4350 | } catch (ImsException e) { |
| 4351 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4352 | } finally { |
| 4353 | Binder.restoreCallingIdentity(token); |
| 4354 | } |
| 4355 | } |
| 4356 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4357 | /** |
| 4358 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4359 | * @param subId The subscription to use to check the configuration. |
| 4360 | * @param c The callback that will be used to send the result. |
| 4361 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4362 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4363 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4364 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4365 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4366 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4367 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4368 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4369 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4370 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4371 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4372 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4373 | if (controller != null) { |
| 4374 | ImsManager imsManager = controller.getImsManager(subId); |
| 4375 | if (imsManager != null) { |
| 4376 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4377 | } else { |
| 4378 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4379 | + "is inactive, ignoring unregister."); |
| 4380 | // If the ImsManager is not valid, just return, since the callback |
| 4381 | // will already have been removed internally. |
| 4382 | } |
| 4383 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4384 | } finally { |
| 4385 | Binder.restoreCallingIdentity(token); |
| 4386 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4387 | } |
| 4388 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4389 | /** |
| 4390 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4391 | */ |
| 4392 | @Override |
| 4393 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4394 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4395 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4396 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4397 | "IMS not available on device."); |
| 4398 | } |
| 4399 | final long token = Binder.clearCallingIdentity(); |
| 4400 | try { |
| 4401 | Phone phone = getPhone(subId); |
| 4402 | if (phone == null) { |
| 4403 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4404 | + subId + "'"); |
| 4405 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4406 | } |
| 4407 | phone.getImsRegistrationState(regState -> { |
| 4408 | try { |
| 4409 | consumer.accept((regState == null) |
| 4410 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4411 | } catch (RemoteException e) { |
| 4412 | // Ignore if the remote process is no longer available to call back. |
| 4413 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4414 | } |
| 4415 | }); |
| 4416 | } finally { |
| 4417 | Binder.restoreCallingIdentity(token); |
| 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | /** |
| 4422 | * Get the transport type for the IMS service registration state. |
| 4423 | */ |
| 4424 | @Override |
| 4425 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4426 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4427 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4428 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4429 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4430 | "IMS not available on device."); |
| 4431 | } |
| 4432 | final long token = Binder.clearCallingIdentity(); |
| 4433 | try { |
| 4434 | Phone phone = getPhone(subId); |
| 4435 | if (phone == null) { |
| 4436 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4437 | + subId + "'"); |
| 4438 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4439 | } |
| 4440 | phone.getImsRegistrationTech(regTech -> { |
| 4441 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4442 | int regTechConverted = (regTech == null) |
| 4443 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4444 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4445 | regTechConverted); |
| 4446 | try { |
| 4447 | consumer.accept(regTechConverted); |
| 4448 | } catch (RemoteException e) { |
| 4449 | // Ignore if the remote process is no longer available to call back. |
| 4450 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4451 | } |
| 4452 | }); |
| 4453 | } finally { |
| 4454 | Binder.restoreCallingIdentity(token); |
| 4455 | } |
| 4456 | } |
| 4457 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4458 | /** |
| 4459 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4460 | * @param subId The subscription to use to check the configuration. |
| 4461 | * @param c The callback that will be used to send the result. |
| 4462 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4463 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4464 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4465 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4466 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4467 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4468 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4469 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4470 | "IMS not available on device."); |
| 4471 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4472 | final long token = Binder.clearCallingIdentity(); |
| 4473 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4474 | int slotId = getSlotIndexOrException(subId); |
| 4475 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4476 | |
| 4477 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4478 | if (controller != null) { |
| 4479 | ImsManager imsManager = controller.getImsManager(subId); |
| 4480 | if (imsManager != null) { |
| 4481 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4482 | } else { |
| 4483 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4484 | } |
| 4485 | } else { |
| 4486 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4487 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4488 | } catch (ImsException e) { |
| 4489 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4490 | } finally { |
| 4491 | Binder.restoreCallingIdentity(token); |
| 4492 | } |
| 4493 | } |
| 4494 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4495 | /** |
| 4496 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4497 | * @param subId The subscription to use to check the configuration. |
| 4498 | * @param c The callback that will be used to send the result. |
| 4499 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4500 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4501 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
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, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4504 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4505 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4506 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4507 | |
| 4508 | final long token = Binder.clearCallingIdentity(); |
| 4509 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4510 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4511 | if (controller != null) { |
| 4512 | ImsManager imsManager = controller.getImsManager(subId); |
| 4513 | if (imsManager != null) { |
| 4514 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4515 | } else { |
| 4516 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4517 | + " is inactive, ignoring unregister."); |
| 4518 | // If the ImsManager is not valid, just return, since the callback |
| 4519 | // will already have been removed internally. |
| 4520 | } |
| 4521 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4522 | } finally { |
| 4523 | Binder.restoreCallingIdentity(token); |
| 4524 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4528 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4529 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4530 | final long token = Binder.clearCallingIdentity(); |
| 4531 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4532 | int slotId = getSlotIndexOrException(subId); |
| 4533 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4534 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4535 | } catch (com.android.ims.ImsException e) { |
| 4536 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4537 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4538 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4539 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4540 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4541 | } finally { |
| 4542 | Binder.restoreCallingIdentity(token); |
| 4543 | } |
| 4544 | } |
| 4545 | |
| 4546 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4547 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4548 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4549 | final long token = Binder.clearCallingIdentity(); |
| 4550 | try { |
| 4551 | Phone phone = getPhone(subId); |
| 4552 | if (phone == null) return false; |
| 4553 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4554 | } catch (com.android.ims.ImsException e) { |
| 4555 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4556 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4557 | } finally { |
| 4558 | Binder.restoreCallingIdentity(token); |
| 4559 | } |
| 4560 | } |
| 4561 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4562 | /** |
| 4563 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4564 | * subscription. |
| 4565 | * @param subId The subscription to use to check the configuration. |
| 4566 | * @param callback The callback that will be used to send the result. |
| 4567 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4568 | * @param transportType The transport type of the MmTelFeature capability. |
| 4569 | */ |
| 4570 | @Override |
| 4571 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4572 | int transportType) { |
| 4573 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4574 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4575 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4576 | "IMS not available on device."); |
| 4577 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4578 | final long token = Binder.clearCallingIdentity(); |
| 4579 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4580 | int slotId = getSlotIndex(subId); |
| 4581 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4582 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4583 | + subId + "'"); |
| 4584 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4585 | } |
| 4586 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4587 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4588 | transportType, aBoolean -> { |
| 4589 | try { |
| 4590 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4591 | } catch (RemoteException e) { |
| 4592 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4593 | + "running. Ignore"); |
| 4594 | } |
| 4595 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4596 | } catch (ImsException e) { |
| 4597 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4598 | } finally { |
| 4599 | Binder.restoreCallingIdentity(token); |
| 4600 | } |
| 4601 | } |
| 4602 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4603 | /** |
| 4604 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4605 | * @param subId The subscription to use to check the configuration. |
| 4606 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4607 | @Override |
| 4608 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4609 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4610 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4611 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4612 | final long token = Binder.clearCallingIdentity(); |
| 4613 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4614 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4615 | // 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] | 4616 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4617 | } catch (ImsException e) { |
| 4618 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4619 | } finally { |
| 4620 | Binder.restoreCallingIdentity(token); |
| 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4625 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4626 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4627 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4628 | final long identity = Binder.clearCallingIdentity(); |
| 4629 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4630 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4631 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4632 | // 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] | 4633 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4634 | } catch (ImsException e) { |
| 4635 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4636 | } finally { |
| 4637 | Binder.restoreCallingIdentity(identity); |
| 4638 | } |
| 4639 | } |
| 4640 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4641 | /** |
| 4642 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4643 | * @param subId The subscription to use to check the configuration. |
| 4644 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4645 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4646 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4647 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4648 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4649 | final long identity = Binder.clearCallingIdentity(); |
| 4650 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4651 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4652 | // 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] | 4653 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4654 | } catch (ImsException e) { |
| 4655 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4656 | } finally { |
| 4657 | Binder.restoreCallingIdentity(identity); |
| 4658 | } |
| 4659 | } |
| 4660 | |
| 4661 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4662 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4664 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4665 | final long identity = Binder.clearCallingIdentity(); |
| 4666 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4667 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4668 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4669 | // 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] | 4670 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4671 | } catch (ImsException e) { |
| 4672 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4673 | } finally { |
| 4674 | Binder.restoreCallingIdentity(identity); |
| 4675 | } |
| 4676 | } |
| 4677 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4678 | /** |
| 4679 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4680 | * @param subId The subscription to use to check the configuration. |
| 4681 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4682 | @Override |
| 4683 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4684 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4685 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4686 | final long identity = Binder.clearCallingIdentity(); |
| 4687 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4688 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4689 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4690 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4691 | } catch (ImsException e) { |
| 4692 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4693 | } finally { |
| 4694 | Binder.restoreCallingIdentity(identity); |
| 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4699 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4701 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4702 | final long identity = Binder.clearCallingIdentity(); |
| 4703 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4704 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4705 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4706 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4707 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4708 | } catch (ImsException e) { |
| 4709 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4710 | } finally { |
| 4711 | Binder.restoreCallingIdentity(identity); |
| 4712 | } |
| 4713 | } |
| 4714 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4715 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4716 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4717 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4718 | * @param subId The subscription to use to check the configuration. |
| 4719 | */ |
| 4720 | @Override |
| 4721 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4722 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4723 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4724 | final long identity = Binder.clearCallingIdentity(); |
| 4725 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4726 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4727 | // 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] | 4728 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4729 | } catch (ImsException e) { |
| 4730 | throw new ServiceSpecificException(e.getCode()); |
| 4731 | } finally { |
| 4732 | Binder.restoreCallingIdentity(identity); |
| 4733 | } |
| 4734 | } |
| 4735 | |
| 4736 | /** |
| 4737 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4738 | * Requires MODIFY_PHONE_STATE permission. |
| 4739 | * @param subId The subscription to use to check the configuration. |
| 4740 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4741 | * false otherwise |
| 4742 | */ |
| 4743 | @Override |
| 4744 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4745 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4746 | "setCrossSimCallingEnabled"); |
| 4747 | final long identity = Binder.clearCallingIdentity(); |
| 4748 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4749 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4750 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4751 | // 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] | 4752 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4753 | } catch (ImsException e) { |
| 4754 | throw new ServiceSpecificException(e.getCode()); |
| 4755 | } finally { |
| 4756 | Binder.restoreCallingIdentity(identity); |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4761 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4762 | * @param subId The subscription to use to check the configuration. |
| 4763 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4764 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4765 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4766 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4767 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4768 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4769 | final long identity = Binder.clearCallingIdentity(); |
| 4770 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4771 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4772 | // 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] | 4773 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4774 | } catch (ImsException e) { |
| 4775 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4776 | } finally { |
| 4777 | Binder.restoreCallingIdentity(identity); |
| 4778 | } |
| 4779 | } |
| 4780 | |
| 4781 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4782 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4784 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4785 | final long identity = Binder.clearCallingIdentity(); |
| 4786 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4787 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4788 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4789 | // 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] | 4790 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4791 | } catch (ImsException e) { |
| 4792 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4793 | } finally { |
| 4794 | Binder.restoreCallingIdentity(identity); |
| 4795 | } |
| 4796 | } |
| 4797 | |
| 4798 | @Override |
| 4799 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4800 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4801 | "setVoWiFiNonPersistent"); |
| 4802 | final long identity = Binder.clearCallingIdentity(); |
| 4803 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4804 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4805 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4806 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4807 | } catch (ImsException e) { |
| 4808 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4809 | } finally { |
| 4810 | Binder.restoreCallingIdentity(identity); |
| 4811 | } |
| 4812 | } |
| 4813 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4814 | /** |
| 4815 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4816 | * @param subId The subscription to use to check the configuration. |
| 4817 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4818 | @Override |
| 4819 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4820 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4821 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4822 | final long identity = Binder.clearCallingIdentity(); |
| 4823 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4824 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4825 | // 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] | 4826 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4827 | } catch (ImsException e) { |
| 4828 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
| 4831 | } |
| 4832 | } |
| 4833 | |
| 4834 | @Override |
| 4835 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4836 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4837 | "setVoWiFiModeSetting"); |
| 4838 | final long identity = Binder.clearCallingIdentity(); |
| 4839 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4840 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4841 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4842 | // 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] | 4843 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4844 | } catch (ImsException e) { |
| 4845 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4846 | } finally { |
| 4847 | Binder.restoreCallingIdentity(identity); |
| 4848 | } |
| 4849 | } |
| 4850 | |
| 4851 | @Override |
| 4852 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4853 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4856 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4857 | // 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] | 4858 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4859 | } catch (ImsException e) { |
| 4860 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4861 | } finally { |
| 4862 | Binder.restoreCallingIdentity(identity); |
| 4863 | } |
| 4864 | } |
| 4865 | |
| 4866 | @Override |
| 4867 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4868 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4869 | "setVoWiFiRoamingModeSetting"); |
| 4870 | final long identity = Binder.clearCallingIdentity(); |
| 4871 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4872 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4873 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4874 | // 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] | 4875 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4876 | } catch (ImsException e) { |
| 4877 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4878 | } finally { |
| 4879 | Binder.restoreCallingIdentity(identity); |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | @Override |
| 4884 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4885 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4886 | "setRttCapabilityEnabled"); |
| 4887 | final long identity = Binder.clearCallingIdentity(); |
| 4888 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4889 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4890 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4891 | // 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] | 4892 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4893 | } catch (ImsException e) { |
| 4894 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4895 | } finally { |
| 4896 | Binder.restoreCallingIdentity(identity); |
| 4897 | } |
| 4898 | } |
| 4899 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4900 | /** |
| 4901 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4902 | * @param subId The subscription to use to check the configuration. |
| 4903 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4904 | @Override |
| 4905 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4906 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4907 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4908 | final long identity = Binder.clearCallingIdentity(); |
| 4909 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4910 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4911 | // 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] | 4912 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4913 | } catch (ImsException e) { |
| 4914 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4915 | } finally { |
| 4916 | Binder.restoreCallingIdentity(identity); |
| 4917 | } |
| 4918 | } |
| 4919 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4920 | @Override |
| 4921 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4922 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4923 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4926 | if (!isImsAvailableOnDevice()) { |
| 4927 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4928 | "IMS not available on device."); |
| 4929 | } |
| 4930 | int slotId = getSlotIndexOrException(subId); |
| 4931 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4932 | |
| 4933 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4934 | if (controller != null) { |
| 4935 | ImsManager imsManager = controller.getImsManager(subId); |
| 4936 | if (imsManager != null) { |
| 4937 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 4938 | } else { |
| 4939 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4940 | } |
| 4941 | } else { |
| 4942 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4943 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4944 | } catch (ImsException e) { |
| 4945 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4946 | } finally { |
| 4947 | Binder.restoreCallingIdentity(identity); |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | @Override |
| 4952 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4953 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4954 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4955 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4956 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4957 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4958 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4959 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4960 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4961 | if (controller != null) { |
| 4962 | ImsManager imsManager = controller.getImsManager(subId); |
| 4963 | if (imsManager != null) { |
| 4964 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 4965 | } else { |
| 4966 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4967 | + " is inactive, ignoring unregister."); |
| 4968 | // If the ImsManager is not valid, just return, since the callback will already |
| 4969 | // have been removed internally. |
| 4970 | } |
| 4971 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
| 4974 | } |
| 4975 | } |
| 4976 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4977 | @Override |
| 4978 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4979 | IFeatureProvisioningCallback callback) { |
| 4980 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4981 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4982 | |
| 4983 | final long identity = Binder.clearCallingIdentity(); |
| 4984 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4985 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4986 | } |
| 4987 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4988 | try { |
| 4989 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4990 | if (controller == null) { |
| 4991 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4992 | "Device does not support IMS"); |
| 4993 | } |
| 4994 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4995 | } finally { |
| 4996 | Binder.restoreCallingIdentity(identity); |
| 4997 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | @Override |
| 5001 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5002 | IFeatureProvisioningCallback callback) { |
| 5003 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5004 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5005 | |
| 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5008 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5009 | } |
| 5010 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5011 | try { |
| 5012 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5013 | if (controller == null) { |
| 5014 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5015 | return; |
| 5016 | } |
| 5017 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5018 | } finally { |
| 5019 | Binder.restoreCallingIdentity(identity); |
| 5020 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5021 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5022 | |
| 5023 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5025 | message); |
| 5026 | } |
| 5027 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5028 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5029 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5030 | boolean isProvisioned) { |
| 5031 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5032 | |
| 5033 | final long identity = Binder.clearCallingIdentity(); |
| 5034 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5035 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5036 | if (controller == null) { |
| 5037 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5038 | return; |
| 5039 | } |
| 5040 | controller.setRcsProvisioningStatusForCapability( |
| 5041 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5042 | } finally { |
| 5043 | Binder.restoreCallingIdentity(identity); |
| 5044 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | |
| 5048 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5049 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5050 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5051 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5052 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5053 | final long identity = Binder.clearCallingIdentity(); |
| 5054 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5055 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5056 | if (controller == null) { |
| 5057 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5058 | |
| 5059 | // device does not support IMS, this method will return true always. |
| 5060 | return true; |
| 5061 | } |
| 5062 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5063 | } finally { |
| 5064 | Binder.restoreCallingIdentity(identity); |
| 5065 | } |
| 5066 | } |
| 5067 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5068 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5069 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5070 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5071 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5072 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5073 | final long identity = Binder.clearCallingIdentity(); |
| 5074 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5075 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5076 | if (controller == null) { |
| 5077 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5078 | return; |
| 5079 | } |
| 5080 | controller.setImsProvisioningStatusForCapability( |
| 5081 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5082 | } finally { |
| 5083 | Binder.restoreCallingIdentity(identity); |
| 5084 | } |
| 5085 | } |
| 5086 | |
| 5087 | @Override |
| 5088 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5089 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5090 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5091 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5092 | final long identity = Binder.clearCallingIdentity(); |
| 5093 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5094 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5095 | if (controller == null) { |
| 5096 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5097 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5098 | // device does not support IMS, this method will return true always. |
| 5099 | return true; |
| 5100 | } |
| 5101 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5102 | } finally { |
| 5103 | Binder.restoreCallingIdentity(identity); |
| 5104 | } |
| 5105 | } |
| 5106 | |
| 5107 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5108 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5109 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5110 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5111 | |
| 5112 | final long identity = Binder.clearCallingIdentity(); |
| 5113 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5114 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5115 | if (controller == null) { |
| 5116 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5117 | |
| 5118 | // device does not support IMS, this method will return false |
| 5119 | return false; |
| 5120 | } |
| 5121 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5122 | } finally { |
| 5123 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5124 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5128 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5129 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5130 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5131 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5132 | final long identity = Binder.clearCallingIdentity(); |
| 5133 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5134 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5135 | if (controller == null) { |
| 5136 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5137 | |
| 5138 | // device does not support IMS, this method will return false |
| 5139 | return false; |
| 5140 | } |
| 5141 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5142 | } finally { |
| 5143 | Binder.restoreCallingIdentity(identity); |
| 5144 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5145 | } |
| 5146 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5147 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5148 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5149 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5150 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5151 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5152 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5153 | mApp, subId, "getImsProvisioningInt"); |
| 5154 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5155 | final long identity = Binder.clearCallingIdentity(); |
| 5156 | try { |
| 5157 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5158 | int slotId = getSlotIndex(subId); |
| 5159 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5160 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5161 | + subId + "' for key:" + key); |
| 5162 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5163 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5164 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5165 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5166 | if (controller == null) { |
| 5167 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5168 | |
| 5169 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5170 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5171 | } |
| 5172 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5173 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5174 | return retVal; |
| 5175 | } |
| 5176 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5177 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5178 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5179 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5180 | + subId + "' for key:" + key); |
| 5181 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5182 | } finally { |
| 5183 | Binder.restoreCallingIdentity(identity); |
| 5184 | } |
| 5185 | } |
| 5186 | |
| 5187 | @Override |
| 5188 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5189 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5190 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5191 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5192 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5193 | mApp, subId, "getImsProvisioningString"); |
| 5194 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5195 | final long identity = Binder.clearCallingIdentity(); |
| 5196 | try { |
| 5197 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5198 | int slotId = getSlotIndex(subId); |
| 5199 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5200 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5201 | + subId + "' for key:" + key); |
| 5202 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5203 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5204 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5205 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5206 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5207 | + subId + "' for key:" + key); |
| 5208 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5209 | } finally { |
| 5210 | Binder.restoreCallingIdentity(identity); |
| 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | @Override |
| 5215 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5216 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5217 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5218 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5219 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5220 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5221 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5222 | final long identity = Binder.clearCallingIdentity(); |
| 5223 | try { |
| 5224 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5225 | int slotId = getSlotIndex(subId); |
| 5226 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5227 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5228 | + subId + "' for key:" + key); |
| 5229 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5230 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5231 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5232 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5233 | if (controller == null) { |
| 5234 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5235 | |
| 5236 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5237 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5238 | } |
| 5239 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5240 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5241 | return retVal; |
| 5242 | } |
| 5243 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5244 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5245 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5246 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5247 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5248 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5249 | } finally { |
| 5250 | Binder.restoreCallingIdentity(identity); |
| 5251 | } |
| 5252 | } |
| 5253 | |
| 5254 | @Override |
| 5255 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5256 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5257 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5258 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5260 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5261 | final long identity = Binder.clearCallingIdentity(); |
| 5262 | try { |
| 5263 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5264 | int slotId = getSlotIndex(subId); |
| 5265 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5266 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5267 | + subId + "' for key:" + key); |
| 5268 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5269 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5270 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5271 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5272 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5273 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5274 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
| 5277 | } |
| 5278 | } |
| 5279 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5280 | /** |
| 5281 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5282 | * for the given slot ID or no ImsResolver instance has been created. |
| 5283 | * @param slotId The slot ID that the IMS service is created for. |
| 5284 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5285 | */ |
| 5286 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5287 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5288 | ImsFeature.FEATURE_MMTEL)) { |
| 5289 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5290 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5291 | } |
| 5292 | } |
| 5293 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5294 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5295 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5296 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5297 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5298 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5299 | } |
| 5300 | return slotId; |
| 5301 | } |
| 5302 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5303 | private int getSlotIndex(int subId) { |
| 5304 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5305 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5306 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5307 | } |
| 5308 | return slotId; |
| 5309 | } |
| 5310 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5311 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5312 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5313 | */ |
| 5314 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5315 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5316 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5317 | try { |
| 5318 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5319 | } catch (SecurityException se) { |
| 5320 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5321 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5322 | + Binder.getCallingUid()); |
| 5323 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5324 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5325 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5326 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5327 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5328 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5329 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5330 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5331 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5332 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | final long identity = Binder.clearCallingIdentity(); |
| 5335 | try { |
| 5336 | final Phone phone = getPhone(subId); |
| 5337 | if (phone != null) { |
| 5338 | return phone.getServiceState().getDataNetworkType(); |
| 5339 | } else { |
| 5340 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5341 | } |
| 5342 | } finally { |
| 5343 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5344 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | /** |
| 5348 | * Returns the data network type |
| 5349 | */ |
| 5350 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5351 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5352 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5353 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | /** |
| 5357 | * Returns the data network type for a subId |
| 5358 | */ |
| 5359 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5360 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5361 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5362 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5363 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5364 | mApp, functionName)) { |
| 5365 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5366 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5367 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5368 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | final long identity = Binder.clearCallingIdentity(); |
| 5372 | try { |
| 5373 | final Phone phone = getPhone(subId); |
| 5374 | if (phone != null) { |
| 5375 | return phone.getServiceState().getDataNetworkType(); |
| 5376 | } else { |
| 5377 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5378 | } |
| 5379 | } finally { |
| 5380 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5381 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5385 | * Returns the Voice network type for a subId |
| 5386 | */ |
| 5387 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5388 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5389 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5390 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5391 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5392 | mApp, functionName)) { |
| 5393 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5394 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5395 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5396 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5397 | } |
| 5398 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | final long identity = Binder.clearCallingIdentity(); |
| 5400 | try { |
| 5401 | final Phone phone = getPhone(subId); |
| 5402 | if (phone != null) { |
| 5403 | return phone.getServiceState().getVoiceNetworkType(); |
| 5404 | } else { |
| 5405 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5406 | } |
| 5407 | } finally { |
| 5408 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5409 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | /** |
| 5413 | * @return true if a ICC card is present |
| 5414 | */ |
| 5415 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5416 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5417 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5418 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5419 | } |
| 5420 | |
| 5421 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5422 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5423 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5424 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5425 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5426 | final long identity = Binder.clearCallingIdentity(); |
| 5427 | try { |
| 5428 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5429 | if (phone != null) { |
| 5430 | return phone.getIccCard().hasIccCard(); |
| 5431 | } else { |
| 5432 | return false; |
| 5433 | } |
| 5434 | } finally { |
| 5435 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5436 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | /** |
| 5440 | * Return if the current radio is LTE on CDMA. This |
| 5441 | * is a tri-state return value as for a period of time |
| 5442 | * the mode may be unknown. |
| 5443 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5444 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5445 | * @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] | 5446 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5447 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5448 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5449 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5450 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5451 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5452 | } |
| 5453 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5454 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5455 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5456 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5457 | try { |
| 5458 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5459 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5460 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5461 | } |
| 5462 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5463 | final long identity = Binder.clearCallingIdentity(); |
| 5464 | try { |
| 5465 | final Phone phone = getPhone(subId); |
| 5466 | if (phone == null) { |
| 5467 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5468 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5469 | return TelephonyProperties.lte_on_cdma_device() |
| 5470 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | } |
| 5472 | } finally { |
| 5473 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5474 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5477 | /** |
| 5478 | * {@hide} |
| 5479 | * Returns Default subId, 0 in the case of single standby. |
| 5480 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5481 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5482 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5483 | } |
| 5484 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5485 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5486 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5487 | } |
| 5488 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5489 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5490 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5491 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5492 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5493 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5494 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5495 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5496 | } |
| 5497 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5498 | /** |
| 5499 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5500 | */ |
| 5501 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5502 | final long identity = Binder.clearCallingIdentity(); |
| 5503 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5504 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5505 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5506 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5507 | } finally { |
| 5508 | Binder.restoreCallingIdentity(identity); |
| 5509 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | /** |
| 5513 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5514 | */ |
| 5515 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5516 | final long identity = Binder.clearCallingIdentity(); |
| 5517 | try { |
| 5518 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5519 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5520 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5521 | } finally { |
| 5522 | Binder.restoreCallingIdentity(identity); |
| 5523 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5524 | } |
| 5525 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5526 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5527 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5528 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5529 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5530 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5531 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5532 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5533 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5534 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5535 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5536 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5537 | } |
| 5538 | return PhoneFactory.getPhone(phoneId); |
| 5539 | } |
| 5540 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5541 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5542 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5543 | @NonNull IccLogicalChannelRequest request) { |
| 5544 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5545 | /*message=*/ "iccOpenLogicalChannel"); |
| 5546 | |
| 5547 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5548 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5549 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5550 | |
| 5551 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5552 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5553 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5554 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5555 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5556 | Phone phone; |
| 5557 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5559 | mApp, request.subId, message); |
| 5560 | phone = getPhoneFromSubId(request.subId); |
| 5561 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5562 | enforceModifyPermission(); |
| 5563 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5564 | } else { |
| 5565 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5566 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5567 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5571 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5572 | final long identity = Binder.clearCallingIdentity(); |
| 5573 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5574 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5575 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5576 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5577 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5578 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5579 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5580 | loge("The calling package is not allowed to access ISD-R."); |
| 5581 | throw new SecurityException( |
| 5582 | "The calling package is not allowed to access ISD-R."); |
| 5583 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5584 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5585 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5587 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5588 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5589 | return response; |
| 5590 | } finally { |
| 5591 | Binder.restoreCallingIdentity(identity); |
| 5592 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5596 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5597 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5598 | /*message=*/"iccCloseLogicalChannel"); |
| 5599 | |
| 5600 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5601 | |
| 5602 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5603 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5604 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5605 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5606 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5607 | // before this feature is enabled, this API should only return false if |
| 5608 | // the operation fails instead of throwing runtime exception for |
| 5609 | // backward-compatibility. |
| 5610 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5611 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5612 | final long identity = Binder.clearCallingIdentity(); |
| 5613 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5614 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5615 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5616 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5617 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5618 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5619 | Boolean success = false; |
| 5620 | if (result instanceof RuntimeException) { |
| 5621 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5622 | if (shouldThrowExceptionOnFailure) { |
| 5623 | throw (RuntimeException) result; |
| 5624 | } else { |
| 5625 | return false; |
| 5626 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5627 | } else if (result instanceof Boolean) { |
| 5628 | success = (Boolean) result; |
| 5629 | } else { |
| 5630 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5631 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5632 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | return success; |
| 5634 | } finally { |
| 5635 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5636 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5640 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5641 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5643 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5644 | if (DBG) { |
| 5645 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5646 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5647 | + p3 + " data=" + data); |
| 5648 | } |
| 5649 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5650 | command, p1, p2, p3, data); |
| 5651 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5652 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5653 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5654 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5655 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5656 | enforceModifyPermission(); |
| 5657 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5658 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5659 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5660 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5661 | } |
| 5662 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5663 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5664 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5668 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5669 | final long identity = Binder.clearCallingIdentity(); |
| 5670 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5671 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5672 | return ""; |
| 5673 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5674 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5675 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5676 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5677 | null /* workSource */); |
| 5678 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5679 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5680 | // Append the returned status code to the end of the response payload. |
| 5681 | String s = Integer.toHexString( |
| 5682 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5683 | if (response.payload != null) { |
| 5684 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5685 | } |
| 5686 | return s; |
| 5687 | } finally { |
| 5688 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5689 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5690 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5691 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5692 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5693 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5694 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5696 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5697 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5698 | if (DBG) { |
| 5699 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5700 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5701 | } |
| 5702 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5703 | cla, command, p1, p2, p3, data); |
| 5704 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5705 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5706 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5707 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5708 | 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] | 5709 | enforceModifyPermission(); |
| 5710 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5711 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5712 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5713 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5714 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5718 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5719 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5723 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5724 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5725 | final long identity = Binder.clearCallingIdentity(); |
| 5726 | try { |
| 5727 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5728 | && TextUtils.equals(ISDR_AID, data)) { |
| 5729 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5730 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5731 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | if (bestComponent == null |
| 5733 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5734 | loge("The calling package is not allowed to select ISD-R."); |
| 5735 | throw new SecurityException( |
| 5736 | "The calling package is not allowed to select ISD-R."); |
| 5737 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5738 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5739 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5740 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5741 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5742 | null /* workSource */); |
| 5743 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5744 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | // Append the returned status code to the end of the response payload. |
| 5746 | String s = Integer.toHexString( |
| 5747 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5748 | if (response.payload != null) { |
| 5749 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5750 | } |
| 5751 | return s; |
| 5752 | } finally { |
| 5753 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5754 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5755 | } |
| 5756 | |
| 5757 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5758 | 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] | 5759 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5760 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5761 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5763 | final long identity = Binder.clearCallingIdentity(); |
| 5764 | try { |
| 5765 | if (DBG) { |
| 5766 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5767 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5768 | } |
| 5769 | |
| 5770 | IccIoResult response = |
| 5771 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5772 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5773 | subId); |
| 5774 | |
| 5775 | if (DBG) { |
| 5776 | log("Exchange SIM_IO [R]" + response); |
| 5777 | } |
| 5778 | |
| 5779 | byte[] result = null; |
| 5780 | int length = 2; |
| 5781 | if (response.payload != null) { |
| 5782 | length = 2 + response.payload.length; |
| 5783 | result = new byte[length]; |
| 5784 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5785 | } else { |
| 5786 | result = new byte[length]; |
| 5787 | } |
| 5788 | |
| 5789 | result[length - 1] = (byte) response.sw2; |
| 5790 | result[length - 2] = (byte) response.sw1; |
| 5791 | return result; |
| 5792 | } finally { |
| 5793 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5794 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5795 | } |
| 5796 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5797 | /** |
| 5798 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5799 | * on a particular subscription |
| 5800 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5801 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5802 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5803 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5804 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5805 | return null; |
| 5806 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5807 | |
| 5808 | final long identity = Binder.clearCallingIdentity(); |
| 5809 | try { |
| 5810 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5811 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5812 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5813 | return null; |
| 5814 | } |
| 5815 | Object response = sendRequest( |
| 5816 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5817 | if (response instanceof String[]) { |
| 5818 | return (String[]) response; |
| 5819 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5820 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5821 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5822 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5823 | } finally { |
| 5824 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5825 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5826 | } |
| 5827 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5828 | /** |
| 5829 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5830 | * subscription. |
| 5831 | * |
| 5832 | * @param subId the id of the subscription. |
| 5833 | * @param appType the uicc app type, must be USIM or SIM. |
| 5834 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5835 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5836 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5837 | * @return number of fplmns that is successfully written to the SIM. |
| 5838 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5839 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5840 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5842 | mApp, subId, "setForbiddenPlmns"); |
| 5843 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5844 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5845 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5846 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5847 | } |
| 5848 | if (fplmns == null) { |
| 5849 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5850 | } |
| 5851 | for (String fplmn : fplmns) { |
| 5852 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5853 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5854 | } |
| 5855 | } |
| 5856 | final long identity = Binder.clearCallingIdentity(); |
| 5857 | try { |
| 5858 | Object response = sendRequest( |
| 5859 | CMD_SET_FORBIDDEN_PLMNS, |
| 5860 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5861 | subId); |
| 5862 | return (int) response; |
| 5863 | } finally { |
| 5864 | Binder.restoreCallingIdentity(identity); |
| 5865 | } |
| 5866 | } |
| 5867 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5868 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5869 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5870 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5871 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5872 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5873 | final long identity = Binder.clearCallingIdentity(); |
| 5874 | try { |
| 5875 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5876 | if (response.payload == null) { |
| 5877 | return ""; |
| 5878 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5879 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5880 | // Append the returned status code to the end of the response payload. |
| 5881 | String s = Integer.toHexString( |
| 5882 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5883 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5884 | return s; |
| 5885 | } finally { |
| 5886 | Binder.restoreCallingIdentity(identity); |
| 5887 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5888 | } |
| 5889 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5890 | /** |
| 5891 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5892 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5893 | * |
| 5894 | * @param itemID the ID of the item to read |
| 5895 | * @return the NV item as a String, or null on error. |
| 5896 | */ |
| 5897 | @Override |
| 5898 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5899 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5900 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5901 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5902 | |
| 5903 | final long identity = Binder.clearCallingIdentity(); |
| 5904 | try { |
| 5905 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5906 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5907 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5908 | return value; |
| 5909 | } finally { |
| 5910 | Binder.restoreCallingIdentity(identity); |
| 5911 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | /** |
| 5915 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5916 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5917 | * |
| 5918 | * @param itemID the ID of the item to read |
| 5919 | * @param itemValue the value to write, as a String |
| 5920 | * @return true on success; false on any failure |
| 5921 | */ |
| 5922 | @Override |
| 5923 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5924 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5925 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5926 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 | |
| 5928 | final long identity = Binder.clearCallingIdentity(); |
| 5929 | try { |
| 5930 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5931 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5932 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5933 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5934 | return success; |
| 5935 | } finally { |
| 5936 | Binder.restoreCallingIdentity(identity); |
| 5937 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5938 | } |
| 5939 | |
| 5940 | /** |
| 5941 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5942 | * Used for device configuration by some CDMA operators. |
| 5943 | * |
| 5944 | * @param preferredRoamingList byte array containing the new PRL |
| 5945 | * @return true on success; false on any failure |
| 5946 | */ |
| 5947 | @Override |
| 5948 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5950 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5951 | |
| 5952 | final long identity = Binder.clearCallingIdentity(); |
| 5953 | try { |
| 5954 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5955 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5956 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5957 | return success; |
| 5958 | } finally { |
| 5959 | Binder.restoreCallingIdentity(identity); |
| 5960 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5961 | } |
| 5962 | |
| 5963 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5964 | * 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] | 5965 | * Used for device configuration by some CDMA operators. |
| 5966 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5967 | * @param slotIndex - device slot. |
| 5968 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5969 | * @return true on success; false on any failure |
| 5970 | */ |
| 5971 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5972 | public boolean resetModemConfig(int slotIndex) { |
| 5973 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5974 | if (phone != null) { |
| 5975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5976 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5977 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5978 | final long identity = Binder.clearCallingIdentity(); |
| 5979 | try { |
| 5980 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5981 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5982 | return success; |
| 5983 | } finally { |
| 5984 | Binder.restoreCallingIdentity(identity); |
| 5985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5986 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5987 | return false; |
| 5988 | } |
| 5989 | |
| 5990 | /** |
| 5991 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5992 | * |
| 5993 | * @param slotIndex - device slot. |
| 5994 | * |
| 5995 | * @return true on success; false on any failure |
| 5996 | */ |
| 5997 | @Override |
| 5998 | public boolean rebootModem(int slotIndex) { |
| 5999 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6000 | if (phone != null) { |
| 6001 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6002 | mApp, phone.getSubId(), "rebootModem"); |
| 6003 | |
| 6004 | final long identity = Binder.clearCallingIdentity(); |
| 6005 | try { |
| 6006 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6007 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6008 | return success; |
| 6009 | } finally { |
| 6010 | Binder.restoreCallingIdentity(identity); |
| 6011 | } |
| 6012 | } |
| 6013 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6014 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6015 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6016 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6017 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6018 | * {@link #disableIms(int)}. |
| 6019 | * @param slotIndex device slot. |
| 6020 | */ |
| 6021 | public void resetIms(int slotIndex) { |
| 6022 | enforceModifyPermission(); |
| 6023 | |
| 6024 | final long identity = Binder.clearCallingIdentity(); |
| 6025 | try { |
| 6026 | if (mImsResolver == null) { |
| 6027 | // may happen if the does not support IMS. |
| 6028 | return; |
| 6029 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6030 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6031 | } finally { |
| 6032 | Binder.restoreCallingIdentity(identity); |
| 6033 | } |
| 6034 | } |
| 6035 | |
| 6036 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6037 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6038 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6039 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6040 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6041 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | |
| 6043 | final long identity = Binder.clearCallingIdentity(); |
| 6044 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6045 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6046 | // may happen if the device does not support IMS. |
| 6047 | return; |
| 6048 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6049 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | } finally { |
| 6051 | Binder.restoreCallingIdentity(identity); |
| 6052 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6056 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6057 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6058 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6059 | public void disableIms(int slotId) { |
| 6060 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6061 | |
| 6062 | final long identity = Binder.clearCallingIdentity(); |
| 6063 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6064 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6065 | // may happen if the device does not support IMS. |
| 6066 | return; |
| 6067 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6068 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6069 | } finally { |
| 6070 | Binder.restoreCallingIdentity(identity); |
| 6071 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6072 | } |
| 6073 | |
| 6074 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6075 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6076 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6077 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6078 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6079 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6080 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | |
| 6082 | final long identity = Binder.clearCallingIdentity(); |
| 6083 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6084 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6085 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6086 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6087 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6088 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | } finally { |
| 6090 | Binder.restoreCallingIdentity(identity); |
| 6091 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6092 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6093 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6094 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6095 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6096 | @Override |
| 6097 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6098 | enforceModifyPermission(); |
| 6099 | |
| 6100 | final long identity = Binder.clearCallingIdentity(); |
| 6101 | try { |
| 6102 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6103 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6104 | } finally { |
| 6105 | Binder.restoreCallingIdentity(identity); |
| 6106 | } |
| 6107 | } |
| 6108 | |
| 6109 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6110 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6111 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6112 | */ |
| 6113 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6114 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | |
| 6116 | final long identity = Binder.clearCallingIdentity(); |
| 6117 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6118 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6119 | // may happen if the device does not support IMS. |
| 6120 | return null; |
| 6121 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6122 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | } finally { |
| 6124 | Binder.restoreCallingIdentity(identity); |
| 6125 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6126 | } |
| 6127 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6128 | /** |
| 6129 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6130 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6131 | */ |
| 6132 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6133 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | |
| 6135 | final long identity = Binder.clearCallingIdentity(); |
| 6136 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6137 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6138 | // may happen if the device does not support IMS. |
| 6139 | return null; |
| 6140 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6141 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6142 | } finally { |
| 6143 | Binder.restoreCallingIdentity(identity); |
| 6144 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6145 | } |
| 6146 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6147 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6148 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6149 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6150 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6151 | * @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] | 6152 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6153 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6154 | * @param packageName The name of the package that the current configuration will be replaced |
| 6155 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6156 | * @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] | 6157 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6158 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6159 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6160 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6162 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6163 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6164 | final long identity = Binder.clearCallingIdentity(); |
| 6165 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6166 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6167 | // may happen if the device does not support IMS. |
| 6168 | return false; |
| 6169 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6170 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6171 | for (int featureType : featureTypes) { |
| 6172 | featureConfig.put(featureType, packageName); |
| 6173 | } |
| 6174 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6175 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6176 | } finally { |
| 6177 | Binder.restoreCallingIdentity(identity); |
| 6178 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6182 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6183 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6184 | * |
| 6185 | * This should only be used for testing. |
| 6186 | * |
| 6187 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6188 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6189 | */ |
| 6190 | @Override |
| 6191 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6192 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6193 | "clearCarrierImsServiceOverride"); |
| 6194 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6195 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6196 | |
| 6197 | final long identity = Binder.clearCallingIdentity(); |
| 6198 | try { |
| 6199 | if (mImsResolver == null) { |
| 6200 | // may happen if the device does not support IMS. |
| 6201 | return false; |
| 6202 | } |
| 6203 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6204 | } finally { |
| 6205 | Binder.restoreCallingIdentity(identity); |
| 6206 | } |
| 6207 | } |
| 6208 | |
| 6209 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6210 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6211 | * |
| 6212 | * @param slotId The slot that the ImsService is associated with. |
| 6213 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6214 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6215 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6216 | * @return the package name of the ImsService configuration. |
| 6217 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6218 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6219 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6220 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6221 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6222 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6223 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | final long identity = Binder.clearCallingIdentity(); |
| 6225 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6226 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6227 | // may happen if the device does not support IMS. |
| 6228 | return ""; |
| 6229 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6230 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6231 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6232 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 | } finally { |
| 6234 | Binder.restoreCallingIdentity(identity); |
| 6235 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6236 | } |
| 6237 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6238 | /** |
| 6239 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6240 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6241 | * @param callback A callback with an integer containing the |
| 6242 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6243 | */ |
| 6244 | @Override |
| 6245 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6246 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6247 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6248 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6249 | "IMS not available on device."); |
| 6250 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6251 | final long token = Binder.clearCallingIdentity(); |
| 6252 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6253 | int slotId = getSlotIndex(subId); |
| 6254 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6255 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6256 | + subId + "'"); |
| 6257 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6258 | } |
| 6259 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6260 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6261 | try { |
| 6262 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6263 | } catch (RemoteException e) { |
| 6264 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6265 | + "Ignore"); |
| 6266 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6267 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6268 | } catch (ImsException e) { |
| 6269 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6270 | } finally { |
| 6271 | Binder.restoreCallingIdentity(token); |
| 6272 | } |
| 6273 | } |
| 6274 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6275 | /** |
| 6276 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6277 | */ |
| 6278 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6279 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6280 | |
| 6281 | final long identity = Binder.clearCallingIdentity(); |
| 6282 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6283 | // NOTE: Before S, this method only set the default phone. |
| 6284 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6285 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6286 | phone.setImsRegistrationState(registered); |
| 6287 | } |
| 6288 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | } finally { |
| 6290 | Binder.restoreCallingIdentity(identity); |
| 6291 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6295 | * Set the network selection mode to automatic. |
| 6296 | * |
| 6297 | */ |
| 6298 | @Override |
| 6299 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6300 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6301 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6302 | |
| 6303 | final long identity = Binder.clearCallingIdentity(); |
| 6304 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6305 | if (!isActiveSubscription(subId)) { |
| 6306 | return; |
| 6307 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6308 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6309 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6310 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | } finally { |
| 6312 | Binder.restoreCallingIdentity(identity); |
| 6313 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6314 | } |
| 6315 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6316 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6317 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6318 | * |
| 6319 | * @param subId the id of the subscription. |
| 6320 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6321 | * the operator to attach to. |
| 6322 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6323 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6324 | * normal network selection next time. |
| 6325 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6326 | */ |
| 6327 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6328 | public boolean setNetworkSelectionModeManual( |
| 6329 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6330 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6331 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6332 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6333 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6334 | if (!isActiveSubscription(subId)) { |
| 6335 | return false; |
| 6336 | } |
| 6337 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6338 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6339 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6340 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6341 | if (DBG) { |
| 6342 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6343 | + " operator: " + operatorInfo); |
| 6344 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6345 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(identity); |
| 6348 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6349 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6350 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6351 | * Get the manual network selection |
| 6352 | * |
| 6353 | * @param subId the id of the subscription. |
| 6354 | * |
| 6355 | * @return the previously saved user selected PLMN |
| 6356 | */ |
| 6357 | @Override |
| 6358 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6359 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6360 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6361 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6362 | |
| 6363 | final long identity = Binder.clearCallingIdentity(); |
| 6364 | try { |
| 6365 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6366 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6367 | } |
| 6368 | |
| 6369 | final Phone phone = getPhone(subId); |
| 6370 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6371 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6372 | } |
| 6373 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6374 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6375 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6376 | } finally { |
| 6377 | Binder.restoreCallingIdentity(identity); |
| 6378 | } |
| 6379 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6380 | |
| 6381 | /** |
| 6382 | * Scans for available networks. |
| 6383 | */ |
| 6384 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6385 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6386 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6387 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6388 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6389 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6390 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6391 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6392 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6393 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6394 | .setCallingPid(Binder.getCallingPid()) |
| 6395 | .setCallingUid(Binder.getCallingUid()) |
| 6396 | .setMethod("getCellNetworkScanResults") |
| 6397 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6398 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6399 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6400 | .build()); |
| 6401 | switch (locationResult) { |
| 6402 | case DENIED_HARD: |
| 6403 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6404 | case DENIED_SOFT: |
| 6405 | return null; |
| 6406 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6407 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6408 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6409 | try { |
| 6410 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6411 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6413 | } finally { |
| 6414 | Binder.restoreCallingIdentity(identity); |
| 6415 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6416 | } |
| 6417 | |
| 6418 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6419 | * Get the call forwarding info, given the call forwarding reason. |
| 6420 | */ |
| 6421 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6422 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6423 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6424 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6425 | long identity = Binder.clearCallingIdentity(); |
| 6426 | try { |
| 6427 | if (DBG) { |
| 6428 | log("getCallForwarding: subId " + subId |
| 6429 | + " callForwardingReason" + callForwardingReason); |
| 6430 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6431 | |
| 6432 | Phone phone = getPhone(subId); |
| 6433 | if (phone == null) { |
| 6434 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6435 | callback.onError( |
| 6436 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6437 | } catch (RemoteException e) { |
| 6438 | // ignore |
| 6439 | } |
| 6440 | return; |
| 6441 | } |
| 6442 | |
| 6443 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6444 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6445 | @Override |
| 6446 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6447 | try { |
| 6448 | callback.onCallForwardingInfoAvailable(info); |
| 6449 | } catch (RemoteException e) { |
| 6450 | // ignore |
| 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | @Override |
| 6455 | public void onError(int error) { |
| 6456 | try { |
| 6457 | callback.onError(error); |
| 6458 | } catch (RemoteException e) { |
| 6459 | // ignore |
| 6460 | } |
| 6461 | } |
| 6462 | }); |
| 6463 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6464 | } finally { |
| 6465 | Binder.restoreCallingIdentity(identity); |
| 6466 | } |
| 6467 | } |
| 6468 | |
| 6469 | /** |
| 6470 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6471 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6472 | */ |
| 6473 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6474 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6475 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6476 | enforceModifyPermission(); |
| 6477 | long identity = Binder.clearCallingIdentity(); |
| 6478 | try { |
| 6479 | if (DBG) { |
| 6480 | log("setCallForwarding: subId " + subId |
| 6481 | + " callForwardingInfo" + callForwardingInfo); |
| 6482 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6483 | |
| 6484 | Phone phone = getPhone(subId); |
| 6485 | if (phone == null) { |
| 6486 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6487 | callback.accept( |
| 6488 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6489 | } catch (RemoteException e) { |
| 6490 | // ignore |
| 6491 | } |
| 6492 | return; |
| 6493 | } |
| 6494 | |
| 6495 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6496 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6497 | |
| 6498 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6499 | } finally { |
| 6500 | Binder.restoreCallingIdentity(identity); |
| 6501 | } |
| 6502 | } |
| 6503 | |
| 6504 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6505 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6506 | */ |
| 6507 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6508 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6509 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6510 | long identity = Binder.clearCallingIdentity(); |
| 6511 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6512 | Phone phone = getPhone(subId); |
| 6513 | if (phone == null) { |
| 6514 | try { |
| 6515 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6516 | } catch (RemoteException e) { |
| 6517 | // ignore |
| 6518 | } |
| 6519 | return; |
| 6520 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6521 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6522 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6523 | boolean requireUssd = c.getBoolean( |
| 6524 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6525 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6526 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6527 | if (requireUssd) { |
| 6528 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6529 | getSubscriptionCarrierId(subId)); |
| 6530 | String newUssdCommand = ""; |
| 6531 | try { |
| 6532 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6533 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6534 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6535 | } catch (NullPointerException e) { |
| 6536 | loge("Failed to generate USSD number" + e); |
| 6537 | } |
| 6538 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6539 | mMainThreadHandler, callback, carrierXmlParser, |
| 6540 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6541 | final String ussdCommand = newUssdCommand; |
| 6542 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6543 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6544 | }); |
| 6545 | } else { |
| 6546 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6547 | callback::accept); |
| 6548 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6549 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6550 | } finally { |
| 6551 | Binder.restoreCallingIdentity(identity); |
| 6552 | } |
| 6553 | } |
| 6554 | |
| 6555 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6556 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6557 | */ |
| 6558 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6559 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6560 | enforceModifyPermission(); |
| 6561 | long identity = Binder.clearCallingIdentity(); |
| 6562 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6563 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6564 | |
| 6565 | Phone phone = getPhone(subId); |
| 6566 | if (phone == null) { |
| 6567 | try { |
| 6568 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6569 | } catch (RemoteException e) { |
| 6570 | // ignore |
| 6571 | } |
| 6572 | return; |
| 6573 | } |
| 6574 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6575 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6576 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6577 | boolean requireUssd = c.getBoolean( |
| 6578 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6579 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6580 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6581 | if (requireUssd) { |
| 6582 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6583 | getSubscriptionCarrierId(subId)); |
| 6584 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6585 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6586 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6587 | String newUssdCommand = ""; |
| 6588 | try { |
| 6589 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6590 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6591 | .makeCommand(ssAction, null); |
| 6592 | } catch (NullPointerException e) { |
| 6593 | loge("Failed to generate USSD number" + e); |
| 6594 | } |
| 6595 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6596 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6597 | final String ussdCommand = newUssdCommand; |
| 6598 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6599 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6600 | }); |
| 6601 | } else { |
| 6602 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6603 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6604 | |
| 6605 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6606 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6607 | } finally { |
| 6608 | Binder.restoreCallingIdentity(identity); |
| 6609 | } |
| 6610 | } |
| 6611 | |
| 6612 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6613 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6614 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6615 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6616 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6617 | * location related information which will be sent if the caller already possess |
| 6618 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6619 | * @param request contains the radio access networks with bands/channels to scan |
| 6620 | * @param messenger callback messenger for scan results or errors |
| 6621 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6622 | * @return the id of the requested scan which can be used to stop the scan. |
| 6623 | */ |
| 6624 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6625 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6626 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6627 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6629 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6630 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6631 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6632 | if (!renounceFineLocationAccess) { |
| 6633 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6634 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6635 | .setCallingPackage(callingPackage) |
| 6636 | .setCallingFeatureId(callingFeatureId) |
| 6637 | .setCallingPid(Binder.getCallingPid()) |
| 6638 | .setCallingUid(Binder.getCallingUid()) |
| 6639 | .setMethod("requestNetworkScan") |
| 6640 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6641 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6642 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6643 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6644 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6645 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6646 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6647 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6648 | if (e != null) { |
| 6649 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6650 | throw e; |
| 6651 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6652 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6653 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6654 | } |
| 6655 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6656 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6657 | int callingUid = Binder.getCallingUid(); |
| 6658 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6659 | final long identity = Binder.clearCallingIdentity(); |
| 6660 | try { |
| 6661 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6662 | renounceFineLocationAccess, request, messenger, binder, |
| 6663 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6664 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6665 | } finally { |
| 6666 | Binder.restoreCallingIdentity(identity); |
| 6667 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6668 | } |
| 6669 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6670 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6671 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6672 | boolean hasCarrierPriv; |
| 6673 | final long identity = Binder.clearCallingIdentity(); |
| 6674 | try { |
| 6675 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6676 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6677 | } finally { |
| 6678 | Binder.restoreCallingIdentity(identity); |
| 6679 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6680 | boolean hasNetworkScanPermission = |
| 6681 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6682 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6683 | |
| 6684 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6685 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6686 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6687 | } |
| 6688 | |
| 6689 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6690 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6691 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6692 | return new SecurityException("Specific channels must not be" |
| 6693 | + " scanned without location access."); |
| 6694 | } |
| 6695 | } |
| 6696 | } |
| 6697 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6698 | return null; |
| 6699 | } |
| 6700 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6701 | /** |
| 6702 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6703 | * |
| 6704 | * @param subId id of the subscription |
| 6705 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6706 | */ |
| 6707 | @Override |
| 6708 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6709 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6710 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6711 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6712 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6713 | final long identity = Binder.clearCallingIdentity(); |
| 6714 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6715 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6716 | } finally { |
| 6717 | Binder.restoreCallingIdentity(identity); |
| 6718 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6722 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6723 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6724 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6725 | */ |
| 6726 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6727 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6728 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6729 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6730 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6731 | |
| 6732 | final long identity = Binder.clearCallingIdentity(); |
| 6733 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6734 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6735 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6736 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6737 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6738 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6739 | } finally { |
| 6740 | Binder.restoreCallingIdentity(identity); |
| 6741 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6742 | } |
| 6743 | |
| 6744 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6745 | * Get the allowed network types for certain reason. |
| 6746 | * |
| 6747 | * @param subId the id of the subscription. |
| 6748 | * @param reason the reason the allowed network type change is taking place |
| 6749 | * @return the allowed network types. |
| 6750 | */ |
| 6751 | @Override |
| 6752 | public long getAllowedNetworkTypesForReason(int subId, |
| 6753 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6754 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6755 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6756 | final long identity = Binder.clearCallingIdentity(); |
| 6757 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6758 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6759 | } finally { |
| 6760 | Binder.restoreCallingIdentity(identity); |
| 6761 | } |
| 6762 | } |
| 6763 | |
| 6764 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6765 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6766 | * @param subId subscription id of the sim card |
| 6767 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6768 | * This can be passed following states |
| 6769 | * <ol> |
| 6770 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6771 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6772 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6773 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6774 | * </ol> |
| 6775 | * @return operation result. |
| 6776 | */ |
| 6777 | @Override |
| 6778 | public int setNrDualConnectivityState(int subId, |
| 6779 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6780 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6781 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6782 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6783 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6784 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6785 | } |
| 6786 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6787 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6788 | final long identity = Binder.clearCallingIdentity(); |
| 6789 | try { |
| 6790 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6791 | nrDualConnectivityState, subId, |
| 6792 | workSource); |
| 6793 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6794 | return result; |
| 6795 | } finally { |
| 6796 | Binder.restoreCallingIdentity(identity); |
| 6797 | } |
| 6798 | } |
| 6799 | |
| 6800 | /** |
| 6801 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6802 | * @return true if dual connectivity is enabled else false |
| 6803 | */ |
| 6804 | @Override |
| 6805 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6806 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6807 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6808 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6809 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6810 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6811 | return false; |
| 6812 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6813 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6814 | final long identity = Binder.clearCallingIdentity(); |
| 6815 | try { |
| 6816 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6817 | null, subId, workSource); |
| 6818 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6819 | return isEnabled; |
| 6820 | } finally { |
| 6821 | Binder.restoreCallingIdentity(identity); |
| 6822 | } |
| 6823 | } |
| 6824 | |
| 6825 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6826 | * Set the allowed network types of the device and |
| 6827 | * provide the reason triggering the allowed network change. |
| 6828 | * |
| 6829 | * @param subId the id of the subscription. |
| 6830 | * @param reason the reason the allowed network type change is taking place |
| 6831 | * @param allowedNetworkTypes the allowed network types. |
| 6832 | * @return true on success; false on any failure. |
| 6833 | */ |
| 6834 | @Override |
| 6835 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6836 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6837 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6839 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6840 | // If the caller only has carrier privileges, then they should not be able to override |
| 6841 | // any network types which were set for security reasons. |
| 6842 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6843 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6844 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6845 | throw new SecurityException( |
| 6846 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6847 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6848 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6849 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6850 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6851 | return false; |
| 6852 | } |
| 6853 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6854 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6855 | return false; |
| 6856 | } |
| 6857 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6858 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6859 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6860 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6861 | Phone phone = getPhone(subId); |
| 6862 | if (phone == null) { |
| 6863 | return false; |
| 6864 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6865 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6866 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6867 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6868 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6869 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6870 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6871 | final long identity = Binder.clearCallingIdentity(); |
| 6872 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6873 | Boolean success = (Boolean) sendRequest( |
| 6874 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6875 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6876 | |
| 6877 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6878 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6879 | } finally { |
| 6880 | Binder.restoreCallingIdentity(identity); |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6885 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6886 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6887 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6888 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6889 | * @hide |
| 6890 | */ |
| 6891 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6892 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6893 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6894 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6895 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6896 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6897 | if (phone != null) { |
| 6898 | return phone.hasMatchedTetherApnSetting(); |
| 6899 | } else { |
| 6900 | return false; |
| 6901 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6902 | } finally { |
| 6903 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6904 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6905 | } |
| 6906 | |
| 6907 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6908 | * Get the user enabled state of Mobile Data. |
| 6909 | * |
| 6910 | * TODO: remove and use isUserDataEnabled. |
| 6911 | * This can't be removed now because some vendor codes |
| 6912 | * calls through ITelephony directly while they should |
| 6913 | * use TelephonyManager. |
| 6914 | * |
| 6915 | * @return true on enabled |
| 6916 | */ |
| 6917 | @Override |
| 6918 | public boolean getDataEnabled(int subId) { |
| 6919 | return isUserDataEnabled(subId); |
| 6920 | } |
| 6921 | |
| 6922 | /** |
| 6923 | * Get whether mobile data is enabled per user setting. |
| 6924 | * |
| 6925 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6926 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6927 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6928 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6929 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6930 | * |
| 6931 | * @return {@code true} if data is enabled else {@code false} |
| 6932 | */ |
| 6933 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6934 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6935 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6936 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6937 | try { |
| 6938 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6939 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6940 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6941 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6942 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6943 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6945 | mApp, subId, functionName); |
| 6946 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6948 | |
| 6949 | final long identity = Binder.clearCallingIdentity(); |
| 6950 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6951 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6952 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6953 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6954 | if (phone != null) { |
| 6955 | boolean retVal = phone.isUserDataEnabled(); |
| 6956 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6957 | return retVal; |
| 6958 | } else { |
| 6959 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6960 | return false; |
| 6961 | } |
| 6962 | } finally { |
| 6963 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6964 | } |
| 6965 | } |
| 6966 | |
| 6967 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6968 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6969 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6970 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6971 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6972 | * @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] | 6973 | */ |
| 6974 | @Override |
| 6975 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6976 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6977 | try { |
| 6978 | try { |
| 6979 | mApp.enforceCallingOrSelfPermission( |
| 6980 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6981 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6982 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6983 | try { |
| 6984 | mApp.enforceCallingOrSelfPermission( |
| 6985 | android.Manifest.permission.READ_PHONE_STATE, |
| 6986 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6987 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6988 | mApp.enforceCallingOrSelfPermission( |
| 6989 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6990 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6991 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6992 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6993 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6994 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | |
| 6996 | final long identity = Binder.clearCallingIdentity(); |
| 6997 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6998 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6999 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7000 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7001 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7002 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | return retVal; |
| 7004 | } else { |
| 7005 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7006 | return false; |
| 7007 | } |
| 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7010 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7011 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7012 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7013 | /** |
| 7014 | * Check if data is enabled for a specific reason |
| 7015 | * @param subId Subscription index |
| 7016 | * @param reason the reason the data enable change is taking place |
| 7017 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7018 | */ |
| 7019 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7020 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7021 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7022 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7023 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7024 | try { |
| 7025 | mApp.enforceCallingOrSelfPermission( |
| 7026 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7027 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7028 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7029 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7030 | functionName); |
| 7031 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7032 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7033 | try { |
| 7034 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7035 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7036 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7038 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7039 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7040 | } |
| 7041 | |
| 7042 | |
| 7043 | final long identity = Binder.clearCallingIdentity(); |
| 7044 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7045 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7046 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7047 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7048 | + " reason=" + reason); |
| 7049 | } |
| 7050 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7051 | if (phone != null) { |
| 7052 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7053 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7054 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7055 | return retVal; |
| 7056 | } else { |
| 7057 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7058 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7059 | + subId + " retVal=false"); |
| 7060 | } |
| 7061 | return false; |
| 7062 | } |
| 7063 | } finally { |
| 7064 | Binder.restoreCallingIdentity(identity); |
| 7065 | } |
| 7066 | } |
| 7067 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7068 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7069 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7070 | // No permission needed; this only lets the caller inspect their own status. |
| 7071 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7072 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7073 | |
| 7074 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7075 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7076 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7077 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7078 | } |
| 7079 | |
| 7080 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7081 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7082 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7083 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7084 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7085 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7086 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7087 | if (cpt == null) { |
| 7088 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7089 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7090 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7091 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7092 | } |
| 7093 | |
| 7094 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7095 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7096 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7097 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7098 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7099 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7100 | Phone phone = getPhone(subId); |
| 7101 | if (phone == null) { |
| 7102 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7103 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7104 | } |
| 7105 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7106 | if (cpt == null) { |
| 7107 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7108 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7109 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7110 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7111 | } |
| 7112 | |
| 7113 | @Override |
| 7114 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7115 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7116 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7117 | } |
| 7118 | |
| 7119 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7120 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7121 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7122 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7123 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7124 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7125 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7126 | if (phone == null) { |
| 7127 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7128 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7129 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7130 | if (cpt == null) { |
| 7131 | continue; |
| 7132 | } |
| 7133 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7134 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7135 | break; |
| 7136 | } |
| 7137 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7138 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7139 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7140 | |
| 7141 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7142 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7143 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7144 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7145 | if (phone == null) { |
| 7146 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7147 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7148 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7149 | if (cpt == null) { |
| 7150 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7151 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7152 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7153 | } |
| 7154 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7155 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7156 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7157 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7158 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7159 | if (phone == null) { |
| 7160 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7161 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7162 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7163 | if (cpt == null) { |
| 7164 | return Collections.emptyList(); |
| 7165 | } |
| 7166 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7167 | } |
| 7168 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7169 | @Override |
| 7170 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7171 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7172 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7173 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7174 | try { |
| 7175 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7176 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7177 | } |
| 7178 | } finally { |
| 7179 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7180 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7181 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7182 | } |
| 7183 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7184 | @Override |
| 7185 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7186 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7187 | |
| 7188 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7189 | if (phone == null) { |
| 7190 | return null; |
| 7191 | } |
| 7192 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7193 | if (cpt == null) { |
| 7194 | return null; |
| 7195 | } |
| 7196 | return cpt.getCarrierServicePackageName(); |
| 7197 | } |
| 7198 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7199 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7200 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7201 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7202 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7203 | return null; |
| 7204 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7205 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7206 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7207 | return null; |
| 7208 | } |
| 7209 | return iccId; |
| 7210 | } |
| 7211 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7212 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7213 | public void setCallComposerStatus(int subId, int status) { |
| 7214 | enforceModifyPermission(); |
| 7215 | |
| 7216 | final long identity = Binder.clearCallingIdentity(); |
| 7217 | try { |
| 7218 | Phone phone = getPhone(subId); |
| 7219 | if (phone != null) { |
| 7220 | Phone defaultPhone = phone.getImsPhone(); |
| 7221 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7222 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7223 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7224 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7225 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7226 | } |
| 7227 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7228 | } catch (ImsException e) { |
| 7229 | throw new ServiceSpecificException(e.getCode()); |
| 7230 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7231 | Binder.restoreCallingIdentity(identity); |
| 7232 | } |
| 7233 | } |
| 7234 | |
| 7235 | @Override |
| 7236 | public int getCallComposerStatus(int subId) { |
| 7237 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7238 | |
| 7239 | final long identity = Binder.clearCallingIdentity(); |
| 7240 | try { |
| 7241 | Phone phone = getPhone(subId); |
| 7242 | if (phone != null) { |
| 7243 | Phone defaultPhone = phone.getImsPhone(); |
| 7244 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7245 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7246 | return imsPhone.getCallComposerStatus(); |
| 7247 | } |
| 7248 | } |
| 7249 | } finally { |
| 7250 | Binder.restoreCallingIdentity(identity); |
| 7251 | } |
| 7252 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7253 | } |
| 7254 | |
| 7255 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7256 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7257 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7258 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7259 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7260 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7261 | final long identity = Binder.clearCallingIdentity(); |
| 7262 | try { |
| 7263 | final String iccId = getIccId(subId); |
| 7264 | final Phone phone = getPhone(subId); |
| 7265 | if (phone == null) { |
| 7266 | return false; |
| 7267 | } |
| 7268 | final String subscriberId = phone.getSubscriberId(); |
| 7269 | |
| 7270 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7271 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7272 | + subscriberId + " to " + number); |
| 7273 | } |
| 7274 | |
| 7275 | if (TextUtils.isEmpty(iccId)) { |
| 7276 | return false; |
| 7277 | } |
| 7278 | |
| 7279 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7280 | |
| 7281 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7282 | if (alphaTag == null) { |
| 7283 | editor.remove(alphaTagPrefKey); |
| 7284 | } else { |
| 7285 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7286 | } |
| 7287 | |
| 7288 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7289 | // track all merged IMSIs based on line number |
| 7290 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7291 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7292 | if (number == null) { |
| 7293 | editor.remove(numberPrefKey); |
| 7294 | editor.remove(subscriberPrefKey); |
| 7295 | } else { |
| 7296 | editor.putString(numberPrefKey, number); |
| 7297 | editor.putString(subscriberPrefKey, subscriberId); |
| 7298 | } |
| 7299 | |
| 7300 | editor.commit(); |
| 7301 | return true; |
| 7302 | } finally { |
| 7303 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7304 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7305 | } |
| 7306 | |
| 7307 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7308 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7309 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7310 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7311 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7312 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7313 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7314 | return null; |
| 7315 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7316 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7317 | final long identity = Binder.clearCallingIdentity(); |
| 7318 | try { |
| 7319 | String iccId = getIccId(subId); |
| 7320 | if (iccId != null) { |
| 7321 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7322 | if (DBG_MERGE) { |
| 7323 | log("getLine1NumberForDisplay returning " |
| 7324 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7325 | } |
| 7326 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7327 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7328 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7329 | return null; |
| 7330 | } finally { |
| 7331 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7332 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7336 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7337 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7338 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7339 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7340 | return null; |
| 7341 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7342 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7343 | final long identity = Binder.clearCallingIdentity(); |
| 7344 | try { |
| 7345 | String iccId = getIccId(subId); |
| 7346 | if (iccId != null) { |
| 7347 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7348 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7349 | } |
| 7350 | return null; |
| 7351 | } finally { |
| 7352 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7353 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7354 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7355 | |
| 7356 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7357 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7358 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7359 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7360 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7361 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7362 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7363 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7364 | return null; |
| 7365 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7366 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7367 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7368 | // the process, where TelephonyManager was instantiated. |
| 7369 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7370 | final long identity = Binder.clearCallingIdentity(); |
| 7371 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7372 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7373 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7374 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7375 | |
| 7376 | // Figure out what subscribers are currently active |
| 7377 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7378 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7379 | // Only consider subs which match the current subId |
| 7380 | // This logic can be simplified. See b/131189269 for progress. |
| 7381 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7382 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7383 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7384 | |
| 7385 | // First pass, find a number override for an active subscriber |
| 7386 | String mergeNumber = null; |
| 7387 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7388 | for (String key : prefs.keySet()) { |
| 7389 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7390 | final String subscriberId = (String) prefs.get(key); |
| 7391 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7392 | final String iccId = key.substring( |
| 7393 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7394 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7395 | mergeNumber = (String) prefs.get(numberKey); |
| 7396 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7397 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7398 | + " for active subscriber " + subscriberId); |
| 7399 | } |
| 7400 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7401 | break; |
| 7402 | } |
| 7403 | } |
| 7404 | } |
| 7405 | } |
| 7406 | |
| 7407 | // Shortcut when no active merged subscribers |
| 7408 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7409 | return null; |
| 7410 | } |
| 7411 | |
| 7412 | // Second pass, find all subscribers under that line override |
| 7413 | final ArraySet<String> result = new ArraySet<>(); |
| 7414 | for (String key : prefs.keySet()) { |
| 7415 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7416 | final String number = (String) prefs.get(key); |
| 7417 | if (mergeNumber.equals(number)) { |
| 7418 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7419 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7420 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7421 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7422 | result.add(subscriberId); |
| 7423 | } |
| 7424 | } |
| 7425 | } |
| 7426 | } |
| 7427 | |
| 7428 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7429 | Arrays.sort(resultArray); |
| 7430 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7431 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7432 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7433 | } |
| 7434 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7435 | } finally { |
| 7436 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7437 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7438 | } |
| 7439 | |
| 7440 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7441 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7442 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7443 | |
| 7444 | final long identity = Binder.clearCallingIdentity(); |
| 7445 | try { |
| 7446 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7447 | TelephonyManager.class); |
| 7448 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7449 | if (subscriberId == null) { |
| 7450 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7451 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7452 | + subId); |
| 7453 | } |
| 7454 | return null; |
| 7455 | } |
| 7456 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7457 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7458 | .getSubscriptionInfo(subId); |
| 7459 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7460 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7461 | if (groupUuid == null) { |
| 7462 | return new String[]{subscriberId}; |
| 7463 | } |
| 7464 | |
| 7465 | // Get all subscriberIds from the group. |
| 7466 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7467 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7468 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7469 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7470 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7471 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7472 | if (subscriberId != null) { |
| 7473 | mergedSubscriberIds.add(subscriberId); |
| 7474 | } |
| 7475 | } |
| 7476 | |
| 7477 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7478 | } finally { |
| 7479 | Binder.restoreCallingIdentity(identity); |
| 7480 | |
| 7481 | } |
| 7482 | } |
| 7483 | |
| 7484 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7485 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7486 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7487 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7488 | |
| 7489 | final long identity = Binder.clearCallingIdentity(); |
| 7490 | try { |
| 7491 | final Phone phone = getPhone(subId); |
| 7492 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7493 | } finally { |
| 7494 | Binder.restoreCallingIdentity(identity); |
| 7495 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7496 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7497 | |
| 7498 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7499 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7500 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7501 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7502 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7503 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | |
| 7505 | final long identity = Binder.clearCallingIdentity(); |
| 7506 | try { |
| 7507 | final Phone phone = getPhone(subId); |
| 7508 | if (phone == null) { |
| 7509 | return false; |
| 7510 | } |
| 7511 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7512 | cdmaNonRoamingList); |
| 7513 | } finally { |
| 7514 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7515 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7516 | } |
| 7517 | |
| 7518 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7519 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7520 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7521 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7522 | if (phone == null) { |
| 7523 | return raf; |
| 7524 | } |
| 7525 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7526 | try { |
| 7527 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7528 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7529 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7530 | } catch (SecurityException e) { |
| 7531 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7532 | throw e; |
| 7533 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7534 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7535 | final long identity = Binder.clearCallingIdentity(); |
| 7536 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7537 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | } finally { |
| 7539 | Binder.restoreCallingIdentity(identity); |
| 7540 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7541 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7542 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7543 | |
| 7544 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7545 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7546 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7547 | try { |
| 7548 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7549 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7550 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7551 | } |
| 7552 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7553 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7554 | } |
| 7555 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7556 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7557 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7558 | throw new SecurityException("App must be the dialer role holder to" |
| 7559 | + " upload a call composer pic"); |
| 7560 | } |
| 7561 | |
| 7562 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7563 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7564 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7565 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7566 | boolean readUntilEnd = false; |
| 7567 | int totalBytesRead = 0; |
| 7568 | byte[] buffer = new byte[16 * 1024]; |
| 7569 | while (true) { |
| 7570 | int numRead; |
| 7571 | try { |
| 7572 | numRead = input.read(buffer); |
| 7573 | } catch (IOException e) { |
| 7574 | try { |
| 7575 | fd.checkError(); |
| 7576 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7577 | null); |
| 7578 | } catch (IOException e1) { |
| 7579 | // This means that the other side closed explicitly with an error. If this |
| 7580 | // happens, log and ignore. |
| 7581 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7582 | } |
| 7583 | break; |
| 7584 | } |
| 7585 | if (numRead == -1) { |
| 7586 | readUntilEnd = true; |
| 7587 | break; |
| 7588 | } |
| 7589 | totalBytesRead += numRead; |
| 7590 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7591 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7592 | try { |
| 7593 | input.close(); |
| 7594 | } catch (IOException e) { |
| 7595 | // ignore |
| 7596 | } |
| 7597 | break; |
| 7598 | } |
| 7599 | output.write(buffer, 0, numRead); |
| 7600 | } |
| 7601 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7602 | // close is above, where the picture size is too big. |
| 7603 | |
| 7604 | try { |
| 7605 | fd.checkError(); |
| 7606 | } catch (IOException e) { |
| 7607 | loge("Remote end for call composer closed with an error: " + e); |
| 7608 | return; |
| 7609 | } |
| 7610 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7611 | if (!readUntilEnd) { |
| 7612 | loge("Did not finish reading entire image; aborting"); |
| 7613 | return; |
| 7614 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7615 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7616 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7617 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7618 | new CallComposerPictureTransfer.Factory() {}, |
| 7619 | imageData, |
| 7620 | (result) -> { |
| 7621 | if (result.first != null) { |
| 7622 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7623 | Bundle outputResult = new Bundle(); |
| 7624 | outputResult.putParcelable( |
| 7625 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7626 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7627 | outputResult); |
| 7628 | } else { |
| 7629 | callback.send(result.second, null); |
| 7630 | } |
| 7631 | } |
| 7632 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7633 | }); |
| 7634 | } |
| 7635 | |
| 7636 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7637 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7638 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7639 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7640 | |
| 7641 | final long identity = Binder.clearCallingIdentity(); |
| 7642 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7643 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7644 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7645 | } finally { |
| 7646 | Binder.restoreCallingIdentity(identity); |
| 7647 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7648 | } |
| 7649 | |
| 7650 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7651 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7652 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7653 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7654 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7655 | return false; |
| 7656 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7658 | final long identity = Binder.clearCallingIdentity(); |
| 7659 | try { |
| 7660 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7661 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7662 | // In the long run, we may instead need to check if there exists a connection service |
| 7663 | // which can support video calling. |
| 7664 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7665 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 | return imsManager.isVtEnabledByPlatform() |
| 7667 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7668 | && imsManager.isVtEnabledByUser(); |
| 7669 | } finally { |
| 7670 | Binder.restoreCallingIdentity(identity); |
| 7671 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7672 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7673 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7674 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7675 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7676 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7677 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7678 | mApp, subId, callingPackage, callingFeatureId, |
| 7679 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | return false; |
| 7681 | } |
| 7682 | |
| 7683 | final long identity = Binder.clearCallingIdentity(); |
| 7684 | try { |
| 7685 | CarrierConfigManager configManager = |
| 7686 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7687 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7688 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7689 | } finally { |
| 7690 | Binder.restoreCallingIdentity(identity); |
| 7691 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7692 | } |
| 7693 | |
| 7694 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7695 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7696 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7697 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7698 | return false; |
| 7699 | } |
| 7700 | |
| 7701 | final long identity = Binder.clearCallingIdentity(); |
| 7702 | try { |
| 7703 | CarrierConfigManager configManager = |
| 7704 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7705 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7706 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7707 | } finally { |
| 7708 | Binder.restoreCallingIdentity(identity); |
| 7709 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7710 | } |
| 7711 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7712 | @Override |
| 7713 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7714 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7715 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7716 | } |
| 7717 | |
| 7718 | @Override |
| 7719 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7720 | final long identity = Binder.clearCallingIdentity(); |
| 7721 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7722 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7723 | } finally { |
| 7724 | Binder.restoreCallingIdentity(identity); |
| 7725 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7726 | } |
| 7727 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7728 | /** |
| 7729 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7730 | * support for the feature and device firmware support. |
| 7731 | * |
| 7732 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7733 | */ |
| 7734 | @Override |
| 7735 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7736 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7737 | final Phone phone = getPhone(subscriptionId); |
| 7738 | if (phone == null) { |
| 7739 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7740 | return false; |
| 7741 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7743 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7744 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7745 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7746 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7747 | return isCarrierSupported && isDeviceSupported; |
| 7748 | } finally { |
| 7749 | Binder.restoreCallingIdentity(identity); |
| 7750 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7751 | } |
| 7752 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7753 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7754 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7755 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7756 | * 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] | 7757 | */ |
| 7758 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7759 | final long identity = Binder.clearCallingIdentity(); |
| 7760 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7761 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7762 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7763 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7764 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7765 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7766 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7767 | } finally { |
| 7768 | Binder.restoreCallingIdentity(identity); |
| 7769 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7770 | } |
| 7771 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7772 | @Deprecated |
| 7773 | @Override |
| 7774 | public String getDeviceId(String callingPackage) { |
| 7775 | return getDeviceIdWithFeature(callingPackage, null); |
| 7776 | } |
| 7777 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7778 | /** |
| 7779 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7780 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7781 | * |
| 7782 | * <p>Requires Permission: |
| 7783 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7784 | */ |
| 7785 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7786 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7787 | try { |
| 7788 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7789 | } catch (SecurityException se) { |
| 7790 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7791 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7792 | + Binder.getCallingUid()); |
| 7793 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7794 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7795 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7796 | return null; |
| 7797 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7798 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7799 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7800 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7801 | return null; |
| 7802 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7803 | |
| 7804 | final long identity = Binder.clearCallingIdentity(); |
| 7805 | try { |
| 7806 | return phone.getDeviceId(); |
| 7807 | } finally { |
| 7808 | Binder.restoreCallingIdentity(identity); |
| 7809 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7810 | } |
| 7811 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7812 | /** |
| 7813 | * {@hide} |
| 7814 | * Returns the IMS Registration Status on a particular subid |
| 7815 | * |
| 7816 | * @param subId |
| 7817 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7818 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7819 | Phone phone = getPhone(subId); |
| 7820 | if (phone != null) { |
| 7821 | return phone.isImsRegistered(); |
| 7822 | } else { |
| 7823 | return false; |
| 7824 | } |
| 7825 | } |
| 7826 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7827 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7828 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7829 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7830 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7831 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7832 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7833 | } |
| 7834 | final long identity = Binder.clearCallingIdentity(); |
| 7835 | try { |
| 7836 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7837 | } finally { |
| 7838 | Binder.restoreCallingIdentity(identity); |
| 7839 | } |
| 7840 | } |
| 7841 | |
| 7842 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7843 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7844 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7845 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7846 | mApp, |
| 7847 | subscriptionId, |
| 7848 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7849 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7850 | final long identity = Binder.clearCallingIdentity(); |
| 7851 | try { |
| 7852 | Phone phone = getPhone(subscriptionId); |
| 7853 | if (phone == null) { |
| 7854 | return null; |
| 7855 | } |
| 7856 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7857 | } finally { |
| 7858 | Binder.restoreCallingIdentity(identity); |
| 7859 | } |
| 7860 | } |
| 7861 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7862 | /** |
| 7863 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7864 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7865 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7866 | final long identity = Binder.clearCallingIdentity(); |
| 7867 | try { |
| 7868 | Phone phone = getPhone(subId); |
| 7869 | if (phone != null) { |
| 7870 | return phone.isWifiCallingEnabled(); |
| 7871 | } else { |
| 7872 | return false; |
| 7873 | } |
| 7874 | } finally { |
| 7875 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7876 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7877 | } |
| 7878 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7879 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7880 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7881 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7882 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7883 | final long identity = Binder.clearCallingIdentity(); |
| 7884 | try { |
| 7885 | Phone phone = getPhone(subId); |
| 7886 | if (phone != null) { |
| 7887 | return phone.isVideoEnabled(); |
| 7888 | } else { |
| 7889 | return false; |
| 7890 | } |
| 7891 | } finally { |
| 7892 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7893 | } |
| 7894 | } |
| 7895 | |
| 7896 | /** |
| 7897 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7898 | * defined in {@link ImsRegistrationImplBase}. |
| 7899 | */ |
| 7900 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7901 | final long identity = Binder.clearCallingIdentity(); |
| 7902 | try { |
| 7903 | Phone phone = getPhone(subId); |
| 7904 | if (phone != null) { |
| 7905 | return phone.getImsRegistrationTech(); |
| 7906 | } else { |
| 7907 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7908 | } |
| 7909 | } finally { |
| 7910 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7911 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7912 | } |
| 7913 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7914 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7915 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7916 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7917 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7918 | return; |
| 7919 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7920 | Phone defaultPhone = getDefaultPhone(); |
| 7921 | if (defaultPhone != null) { |
| 7922 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7923 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7924 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7925 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7926 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7927 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7928 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7929 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7930 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7931 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7932 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7933 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7934 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7935 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7936 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7937 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7938 | // There has been issues when Sms raw table somehow stores orphan |
| 7939 | // fragments. They lead to garbled message when new fragments come |
| 7940 | // in and combined with those stale ones. In case this happens again, |
| 7941 | // user can reset all network settings which will clean up this table. |
| 7942 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7943 | // Clean up IMS settings as well here. |
| 7944 | int slotId = getSlotIndex(subId); |
| 7945 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7946 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7947 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7948 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7949 | if (defaultPhone == null) { |
| 7950 | return; |
| 7951 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7952 | // Erase modem config if erase modem on network setting is enabled. |
| 7953 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7954 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7955 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7956 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7957 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7958 | |
| 7959 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7960 | } finally { |
| 7961 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7962 | } |
| 7963 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7964 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7965 | @VisibleForTesting |
| 7966 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7967 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7968 | return; |
| 7969 | } |
| 7970 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7971 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7972 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7973 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7974 | "user=" + defaultNetworkType); |
| 7975 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7976 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7977 | defaultNetworkType, null); |
| 7978 | } |
| 7979 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7980 | private void cleanUpSmsRawTable(Context context) { |
| 7981 | ContentResolver resolver = context.getContentResolver(); |
| 7982 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7983 | resolver.delete(uri, null, null); |
| 7984 | } |
| 7985 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7986 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7987 | public String getSimLocaleForSubscriber(int subId) { |
| 7988 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7989 | final Phone phone = getPhone(subId); |
| 7990 | if (phone == null) { |
| 7991 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7992 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7993 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7994 | final long identity = Binder.clearCallingIdentity(); |
| 7995 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7996 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 7997 | phone.getContext().getOpPackageName(), |
| 7998 | phone.getContext().getAttributionTag()); |
| 7999 | if (info == null) { |
| 8000 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8001 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8002 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8003 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8004 | // preferences (EF-PL and EF-LI)... |
| 8005 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8006 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8007 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8008 | if (localeFromDefaultSim != null) { |
| 8009 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8010 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8011 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8012 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8013 | } else { |
| 8014 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8015 | } |
| 8016 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8019 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8020 | // the SIM and carrier preferences does not include a country we add the country |
| 8021 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8022 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8023 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8024 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8025 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8026 | } |
| 8027 | |
| 8028 | if (DBG) log("No locale found - returning null"); |
| 8029 | return null; |
| 8030 | } finally { |
| 8031 | Binder.restoreCallingIdentity(identity); |
| 8032 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8033 | } |
| 8034 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8035 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8036 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8037 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8038 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8039 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8040 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8041 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8042 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8043 | return localeTag; |
| 8044 | } |
| 8045 | } |
| 8046 | return inputLocale.toLanguageTag(); |
| 8047 | } |
| 8048 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8049 | /** |
| 8050 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8051 | */ |
| 8052 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8053 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8054 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8055 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8056 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8057 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8058 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8059 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8060 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8061 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8062 | * representing the state of the modem. |
| 8063 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8064 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8065 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8066 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8067 | */ |
| 8068 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8069 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8070 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8071 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8072 | |
| 8073 | final long identity = Binder.clearCallingIdentity(); |
| 8074 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8075 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8076 | } finally { |
| 8077 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8078 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8079 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8080 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8081 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8082 | // less than total activity duration. |
| 8083 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8084 | if (info == null) { |
| 8085 | return false; |
| 8086 | } |
| 8087 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8088 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8089 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8090 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8091 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8092 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8093 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8094 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8095 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8096 | } |
| 8097 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8098 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8099 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8100 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8101 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8102 | |
| 8103 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8104 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8105 | } |
| 8106 | |
| 8107 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8108 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8109 | rat, |
| 8110 | freq, |
| 8111 | info.getReceiveTimeMillis(rat, freq) |
| 8112 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8113 | } |
| 8114 | |
| 8115 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8116 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8117 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8118 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8119 | |
| 8120 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8121 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8122 | } |
| 8123 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8124 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8125 | rat, |
| 8126 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8127 | } |
| 8128 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8129 | /** |
| 8130 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8131 | * @param info recent ModemActivityInfo |
| 8132 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8133 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8134 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8135 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8136 | boolean matched; |
| 8137 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8138 | matched = false; |
| 8139 | int rat = info.getSpecificInfoRat(i); |
| 8140 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8141 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8142 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8143 | //if it already exists |
| 8144 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8145 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8146 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8147 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8148 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8149 | updateLastModemActivityInfo(info, rat, freq); |
| 8150 | matched = true; |
| 8151 | } |
| 8152 | } else { |
| 8153 | updateLastModemActivityInfo(info, rat); |
| 8154 | matched = true; |
| 8155 | } |
| 8156 | } |
| 8157 | } |
| 8158 | |
| 8159 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8160 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8161 | new ActivityStatsTechSpecificInfo( |
| 8162 | rat, |
| 8163 | freq, |
| 8164 | info.getTransmitTimeMillis(rat, freq), |
| 8165 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8166 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8167 | } |
| 8168 | } |
| 8169 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8170 | mLastModemActivitySpecificInfo = |
| 8171 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8172 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8173 | |
| 8174 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8175 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8176 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8177 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8178 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8179 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8180 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8181 | |
| 8182 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8183 | new ModemActivityInfo( |
| 8184 | mLastModemActivityInfo.getTimestampMillis(), |
| 8185 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8186 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8187 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8188 | } |
| 8189 | |
| 8190 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8191 | ActivityStatsTechSpecificInfo[] info) { |
| 8192 | int infoSize = info.length; |
| 8193 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8194 | for (int i = 0; i < infoSize; i++) { |
| 8195 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8196 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8197 | info[i].getTransmitTimeMillis(), |
| 8198 | (int) info[i].getReceiveTimeMillis()); |
| 8199 | } |
| 8200 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8201 | } |
| 8202 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8203 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8204 | * Returns the service state information on specified subscription. |
| 8205 | */ |
| 8206 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8207 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8208 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8209 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8210 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8211 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8212 | return null; |
| 8213 | } |
| 8214 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8215 | boolean hasFinePermission = false; |
| 8216 | boolean hasCoarsePermission = false; |
| 8217 | if (!renounceFineLocationAccess) { |
| 8218 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8219 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8220 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8221 | .setCallingPackage(callingPackage) |
| 8222 | .setCallingFeatureId(callingFeatureId) |
| 8223 | .setCallingPid(Binder.getCallingPid()) |
| 8224 | .setCallingUid(Binder.getCallingUid()) |
| 8225 | .setMethod("getServiceStateForSubscriber") |
| 8226 | .setLogAsInfo(true) |
| 8227 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8228 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8229 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8230 | .build()); |
| 8231 | hasFinePermission = |
| 8232 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8233 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8234 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8235 | if (!renounceCoarseLocationAccess) { |
| 8236 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8237 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8238 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8239 | .setCallingPackage(callingPackage) |
| 8240 | .setCallingFeatureId(callingFeatureId) |
| 8241 | .setCallingPid(Binder.getCallingPid()) |
| 8242 | .setCallingUid(Binder.getCallingUid()) |
| 8243 | .setMethod("getServiceStateForSubscriber") |
| 8244 | .setLogAsInfo(true) |
| 8245 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8246 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8247 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8248 | .build()); |
| 8249 | hasCoarsePermission = |
| 8250 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8251 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8252 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8253 | final Phone phone = getPhone(subId); |
| 8254 | if (phone == null) { |
| 8255 | return null; |
| 8256 | } |
| 8257 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8258 | final long identity = Binder.clearCallingIdentity(); |
| 8259 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8260 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8261 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8262 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8263 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8264 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8265 | .getSubscriptionInfoInternal(subId); |
| 8266 | if (subInfo == null || !subInfo.isActive()) { |
| 8267 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8268 | + "subId=" + subId); |
| 8269 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8270 | } |
| 8271 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8272 | ServiceState ss = phone.getServiceState(); |
| 8273 | |
| 8274 | // Scrub out the location info in ServiceState depending on what level of access |
| 8275 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8276 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8277 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8278 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8279 | } finally { |
| 8280 | Binder.restoreCallingIdentity(identity); |
| 8281 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8282 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8283 | |
| 8284 | /** |
| 8285 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8286 | * |
| 8287 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8288 | * voicemail ringtone. |
| 8289 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8290 | * PhoneAccount. |
| 8291 | */ |
| 8292 | @Override |
| 8293 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8294 | final long identity = Binder.clearCallingIdentity(); |
| 8295 | try { |
| 8296 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8297 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8298 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8299 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8300 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8302 | } finally { |
| 8303 | Binder.restoreCallingIdentity(identity); |
| 8304 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8305 | } |
| 8306 | |
| 8307 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8308 | * Sets the per-account voicemail ringtone. |
| 8309 | * |
| 8310 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8311 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8312 | * |
| 8313 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8314 | * voicemail ringtone. |
| 8315 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8316 | * PhoneAccount. |
| 8317 | */ |
| 8318 | @Override |
| 8319 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8320 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8321 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8322 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8323 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8324 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8325 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8326 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8327 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8328 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8329 | |
| 8330 | final long identity = Binder.clearCallingIdentity(); |
| 8331 | try { |
| 8332 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8333 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8334 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8335 | } |
| 8336 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8337 | } finally { |
| 8338 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8339 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8340 | } |
| 8341 | |
| 8342 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8343 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8344 | * |
| 8345 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8346 | * voicemail vibration setting. |
| 8347 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8348 | */ |
| 8349 | @Override |
| 8350 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8351 | final long identity = Binder.clearCallingIdentity(); |
| 8352 | try { |
| 8353 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8354 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8355 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8356 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8357 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8358 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8359 | } finally { |
| 8360 | Binder.restoreCallingIdentity(identity); |
| 8361 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8362 | } |
| 8363 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8364 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8365 | * Sets the per-account voicemail vibration. |
| 8366 | * |
| 8367 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8368 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8369 | * |
| 8370 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8371 | * voicemail vibration setting. |
| 8372 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8373 | * specific PhoneAccount. |
| 8374 | */ |
| 8375 | @Override |
| 8376 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8377 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8378 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8379 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8380 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8381 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8382 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8383 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8384 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8385 | } |
| 8386 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8387 | final long identity = Binder.clearCallingIdentity(); |
| 8388 | try { |
| 8389 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8390 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8391 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8392 | } |
| 8393 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8394 | } finally { |
| 8395 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8396 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8397 | } |
| 8398 | |
| 8399 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8400 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8401 | * |
| 8402 | * @throws SecurityException if the caller does not have the required permission |
| 8403 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8404 | @VisibleForTesting |
| 8405 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8406 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8407 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8408 | } |
| 8409 | |
| 8410 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8411 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8412 | * permission. |
| 8413 | * |
| 8414 | * @throws SecurityException if the caller does not have the required permission |
| 8415 | */ |
| 8416 | private void enforceSendSmsPermission() { |
| 8417 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8418 | } |
| 8419 | |
| 8420 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8421 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8422 | * users permission. |
| 8423 | * |
| 8424 | * @throws SecurityException if the caller does not have the required permission |
| 8425 | */ |
| 8426 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8427 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8428 | } |
| 8429 | |
| 8430 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8431 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8432 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8433 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8434 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8435 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8436 | final long identity = Binder.clearCallingIdentity(); |
| 8437 | try { |
| 8438 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8439 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8440 | if (componentName == null) { |
| 8441 | throw new SecurityException( |
| 8442 | "Caller not current active visual voicemail package[null]"); |
| 8443 | } |
| 8444 | String vvmPackage = componentName.getPackageName(); |
| 8445 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8446 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8447 | } |
| 8448 | } finally { |
| 8449 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8450 | } |
| 8451 | } |
| 8452 | |
| 8453 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8454 | * Return the application ID for the app type. |
| 8455 | * |
| 8456 | * @param subId the subscription ID that this request applies to. |
| 8457 | * @param appType the uicc app type. |
| 8458 | * @return Application ID for specificied app type, or null if no uicc. |
| 8459 | */ |
| 8460 | @Override |
| 8461 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8462 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8463 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8464 | |
| 8465 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8466 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8467 | if (phone == null) { |
| 8468 | return null; |
| 8469 | } |
| 8470 | String aid = null; |
| 8471 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8472 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8473 | .getApplicationByType(appType).getAid(); |
| 8474 | } catch (Exception e) { |
| 8475 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8476 | } |
| 8477 | return aid; |
| 8478 | } finally { |
| 8479 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8480 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8481 | } |
| 8482 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8483 | /** |
| 8484 | * Return the Electronic Serial Number. |
| 8485 | * |
| 8486 | * @param subId the subscription ID that this request applies to. |
| 8487 | * @return ESN or null if error. |
| 8488 | */ |
| 8489 | @Override |
| 8490 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8491 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8492 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8493 | |
| 8494 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8495 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8496 | if (phone == null) { |
| 8497 | return null; |
| 8498 | } |
| 8499 | String esn = null; |
| 8500 | try { |
| 8501 | esn = phone.getEsn(); |
| 8502 | } catch (Exception e) { |
| 8503 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8504 | } |
| 8505 | return esn; |
| 8506 | } finally { |
| 8507 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8508 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8509 | } |
| 8510 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8511 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8512 | * Return the Preferred Roaming List Version. |
| 8513 | * |
| 8514 | * @param subId the subscription ID that this request applies to. |
| 8515 | * @return PRLVersion or null if error. |
| 8516 | */ |
| 8517 | @Override |
| 8518 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8519 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8520 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8521 | |
| 8522 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8523 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8524 | if (phone == null) { |
| 8525 | return null; |
| 8526 | } |
| 8527 | String cdmaPrlVersion = null; |
| 8528 | try { |
| 8529 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8530 | } catch (Exception e) { |
| 8531 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8532 | } |
| 8533 | return cdmaPrlVersion; |
| 8534 | } finally { |
| 8535 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8536 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8537 | } |
| 8538 | |
| 8539 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8540 | * Get snapshot of Telephony histograms |
| 8541 | * @return List of Telephony histograms |
| 8542 | * @hide |
| 8543 | */ |
| 8544 | @Override |
| 8545 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8547 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8548 | |
| 8549 | final long identity = Binder.clearCallingIdentity(); |
| 8550 | try { |
| 8551 | return RIL.getTelephonyRILTimingHistograms(); |
| 8552 | } finally { |
| 8553 | Binder.restoreCallingIdentity(identity); |
| 8554 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8555 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8556 | |
| 8557 | /** |
| 8558 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8559 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8560 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8561 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8562 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8563 | * @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] | 8564 | */ |
| 8565 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8566 | @TelephonyManager.SetCarrierRestrictionResult |
| 8567 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8568 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8569 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8570 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8571 | if (carrierRestrictionRules == null) { |
| 8572 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8573 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8574 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8575 | final long identity = Binder.clearCallingIdentity(); |
| 8576 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8577 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8578 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8579 | } finally { |
| 8580 | Binder.restoreCallingIdentity(identity); |
| 8581 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8582 | } |
| 8583 | |
| 8584 | /** |
| 8585 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8586 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8587 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8588 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8589 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8590 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8591 | */ |
| 8592 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8593 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8594 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8595 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8596 | |
| 8597 | final long identity = Binder.clearCallingIdentity(); |
| 8598 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8599 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8600 | if (response instanceof CarrierRestrictionRules) { |
| 8601 | return (CarrierRestrictionRules) response; |
| 8602 | } |
| 8603 | // Response is an Exception of some kind, |
| 8604 | // which is signalled to the user as a NULL retval |
| 8605 | return null; |
| 8606 | } catch (Exception e) { |
| 8607 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8608 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8609 | } finally { |
| 8610 | Binder.restoreCallingIdentity(identity); |
| 8611 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8612 | } |
| 8613 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8614 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8615 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8616 | * through the callback. |
| 8617 | * |
| 8618 | * @param callback The callback that will be used to send the result. |
| 8619 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8620 | * the caller is not allowlisted. |
| 8621 | */ |
| 8622 | @Override |
| 8623 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8624 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8625 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8626 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8627 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8628 | throw new SecurityException("Not an authorized caller"); |
| 8629 | } |
| 8630 | final long identity = Binder.clearCallingIdentity(); |
| 8631 | try { |
| 8632 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8633 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8634 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8635 | } finally { |
| 8636 | Binder.restoreCallingIdentity(identity); |
| 8637 | } |
| 8638 | } |
| 8639 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 8640 | @Override |
| 8641 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 8642 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 8643 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8644 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 8645 | } |
| 8646 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8647 | @VisibleForTesting |
| 8648 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8649 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8650 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8651 | } |
| 8652 | |
| 8653 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8654 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8655 | * @param subId the subscription ID that this action applies to. |
| 8656 | * @param enabled control enable or disable radio. |
| 8657 | * {@hide} |
| 8658 | */ |
| 8659 | @Override |
| 8660 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8661 | enforceModifyPermission(); |
| 8662 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8663 | |
| 8664 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8665 | if (phone == null) { |
| 8666 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8667 | return; |
| 8668 | } |
| 8669 | try { |
| 8670 | phone.carrierActionSetRadioEnabled(enabled); |
| 8671 | } catch (Exception e) { |
| 8672 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8673 | } finally { |
| 8674 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8675 | } |
| 8676 | } |
| 8677 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8678 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8679 | * Enable or disable Voice over NR (VoNR) |
| 8680 | * @param subId the subscription ID that this action applies to. |
| 8681 | * @param enabled enable or disable VoNR. |
| 8682 | * @return operation result. |
| 8683 | */ |
| 8684 | @Override |
| 8685 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8686 | enforceModifyPermission(); |
| 8687 | final Phone phone = getPhone(subId); |
| 8688 | |
| 8689 | final long identity = Binder.clearCallingIdentity(); |
| 8690 | if (phone == null) { |
| 8691 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8692 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8693 | } |
| 8694 | |
| 8695 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8696 | try { |
| 8697 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8698 | workSource); |
| 8699 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8700 | |
| 8701 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8702 | if (DBG) { |
| 8703 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8704 | } |
| 8705 | SubscriptionManager.setSubscriptionProperty( |
| 8706 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8707 | (enabled ? "1" : "0")); |
| 8708 | } |
| 8709 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8710 | return result; |
| 8711 | } finally { |
| 8712 | Binder.restoreCallingIdentity(identity); |
| 8713 | } |
| 8714 | } |
| 8715 | |
| 8716 | /** |
| 8717 | * Is voice over NR enabled |
| 8718 | * @return true if VoNR is enabled else false |
| 8719 | */ |
| 8720 | @Override |
| 8721 | public boolean isVoNrEnabled(int subId) { |
| 8722 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8723 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8724 | final long identity = Binder.clearCallingIdentity(); |
| 8725 | try { |
| 8726 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8727 | null, subId, workSource); |
| 8728 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8729 | return isEnabled; |
| 8730 | } finally { |
| 8731 | Binder.restoreCallingIdentity(identity); |
| 8732 | } |
| 8733 | } |
| 8734 | |
| 8735 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8736 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8737 | * network status based on which carrier apps could apply actions accordingly, |
| 8738 | * enable/disable default url handler for example. |
| 8739 | * |
| 8740 | * @param subId the subscription ID that this action applies to. |
| 8741 | * @param report control start/stop reporting the default network status. |
| 8742 | * {@hide} |
| 8743 | */ |
| 8744 | @Override |
| 8745 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8746 | enforceModifyPermission(); |
| 8747 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8748 | |
| 8749 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8750 | if (phone == null) { |
| 8751 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8752 | return; |
| 8753 | } |
| 8754 | try { |
| 8755 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8756 | } catch (Exception e) { |
| 8757 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8758 | } finally { |
| 8759 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8760 | } |
| 8761 | } |
| 8762 | |
| 8763 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8764 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8765 | * @param subId the subscription ID that this action applies to. |
| 8766 | * {@hide} |
| 8767 | */ |
| 8768 | @Override |
| 8769 | public void carrierActionResetAll(int subId) { |
| 8770 | enforceModifyPermission(); |
| 8771 | final Phone phone = getPhone(subId); |
| 8772 | if (phone == null) { |
| 8773 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8774 | return; |
| 8775 | } |
| 8776 | try { |
| 8777 | phone.carrierActionResetAll(); |
| 8778 | } catch (Exception e) { |
| 8779 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8780 | } |
| 8781 | } |
| 8782 | |
| 8783 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8784 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8785 | * bug report is being generated. |
| 8786 | */ |
| 8787 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8788 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8789 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8790 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8791 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8792 | + Binder.getCallingPid() |
| 8793 | + ", uid=" + Binder.getCallingUid() |
| 8794 | + "without permission " |
| 8795 | + android.Manifest.permission.DUMP); |
| 8796 | return; |
| 8797 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8798 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8799 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8800 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8801 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8802 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8803 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8804 | @NonNull String[] args) { |
| 8805 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8806 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8807 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8808 | } |
| 8809 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8810 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8811 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8812 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8813 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8814 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8815 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8816 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8817 | */ |
| 8818 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8819 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8820 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8821 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8822 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8823 | try { |
| 8824 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8825 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8826 | } catch (SecurityException se) { |
| 8827 | enforceModifyPermission(); |
| 8828 | } |
| 8829 | } else { |
| 8830 | enforceModifyPermission(); |
| 8831 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8832 | |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 8833 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 8834 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 8835 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(), |
| 8836 | callingPackage, null, null); |
| 8837 | } |
| 8838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8839 | final long identity = Binder.clearCallingIdentity(); |
| 8840 | try { |
| 8841 | Phone phone = getPhone(subId); |
| 8842 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8843 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8844 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8845 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8846 | phone.getDataSettingsManager().setDataEnabled( |
| 8847 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8848 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8849 | } |
| 8850 | } finally { |
| 8851 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8852 | } |
| 8853 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8854 | |
| 8855 | /** |
| 8856 | * Get Client request stats |
| 8857 | * @return List of Client Request Stats |
| 8858 | * @hide |
| 8859 | */ |
| 8860 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8861 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8862 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8863 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8864 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8865 | return null; |
| 8866 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8867 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8868 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8869 | final long identity = Binder.clearCallingIdentity(); |
| 8870 | try { |
| 8871 | if (phone != null) { |
| 8872 | return phone.getClientRequestStats(); |
| 8873 | } |
| 8874 | |
| 8875 | return null; |
| 8876 | } finally { |
| 8877 | Binder.restoreCallingIdentity(identity); |
| 8878 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8879 | } |
| 8880 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8881 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8882 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8883 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8884 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8885 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8886 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8887 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8888 | // commands that plumb through the RIL as root, like so: |
| 8889 | // $ adb root |
| 8890 | // $ adb shell cmd phone ... |
| 8891 | packageName = "root"; |
| 8892 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8893 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8894 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8895 | |
| 8896 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8897 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8898 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8899 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8900 | * @param state State of SIM (power down, power up, pass through) |
| 8901 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8902 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8903 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8904 | * |
| 8905 | **/ |
| 8906 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8907 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8908 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8909 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8910 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8911 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8912 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8913 | final long identity = Binder.clearCallingIdentity(); |
| 8914 | try { |
| 8915 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8916 | phone.setSimPowerState(state, null, workSource); |
| 8917 | } |
| 8918 | } finally { |
| 8919 | Binder.restoreCallingIdentity(identity); |
| 8920 | } |
| 8921 | } |
| 8922 | |
| 8923 | /** |
| 8924 | * Set SIM card power state. |
| 8925 | * |
| 8926 | * @param slotIndex SIM slot id. |
| 8927 | * @param state State of SIM (power down, power up, pass through) |
| 8928 | * @param callback callback to trigger after success or failure |
| 8929 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8930 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8931 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8932 | * |
| 8933 | **/ |
| 8934 | @Override |
| 8935 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8936 | IIntegerConsumer callback) { |
| 8937 | enforceModifyPermission(); |
| 8938 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8939 | |
| 8940 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8941 | |
| 8942 | final long identity = Binder.clearCallingIdentity(); |
| 8943 | try { |
| 8944 | if (phone != null) { |
| 8945 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8946 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8947 | } |
| 8948 | } finally { |
| 8949 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8950 | } |
| 8951 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8952 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8953 | private boolean isUssdApiAllowed(int subId) { |
| 8954 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8955 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8956 | if (configManager == null) { |
| 8957 | return false; |
| 8958 | } |
| 8959 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8960 | if (pb == null) { |
| 8961 | return false; |
| 8962 | } |
| 8963 | return pb.getBoolean( |
| 8964 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8965 | } |
| 8966 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8967 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8968 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8969 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8970 | * @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] | 8971 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8972 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8973 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8974 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8975 | final long identity = Binder.clearCallingIdentity(); |
| 8976 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8977 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8978 | } finally { |
| 8979 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8980 | } |
| 8981 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8982 | |
| 8983 | /** |
| 8984 | * Get the current signal strength information for the given subscription. |
| 8985 | * Because this information is not updated when the device is in a low power state |
| 8986 | * it should not be relied-upon to be current. |
| 8987 | * @param subId Subscription index |
| 8988 | * @return the most recent cached signal strength info from the modem |
| 8989 | */ |
| 8990 | @Override |
| 8991 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8992 | final long identity = Binder.clearCallingIdentity(); |
| 8993 | try { |
| 8994 | Phone p = getPhone(subId); |
| 8995 | if (p == null) { |
| 8996 | return null; |
| 8997 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8998 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8999 | return p.getSignalStrength(); |
| 9000 | } finally { |
| 9001 | Binder.restoreCallingIdentity(identity); |
| 9002 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9003 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9004 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9005 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9006 | * Get the current modem radio state for the given slot. |
| 9007 | * @param slotIndex slot index. |
| 9008 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9009 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9010 | * @return the current radio power state from the modem |
| 9011 | */ |
| 9012 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9013 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9014 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9015 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9017 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9018 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9019 | } |
| 9020 | |
| 9021 | final long identity = Binder.clearCallingIdentity(); |
| 9022 | try { |
| 9023 | return phone.getRadioPowerState(); |
| 9024 | } finally { |
| 9025 | Binder.restoreCallingIdentity(identity); |
| 9026 | } |
| 9027 | } |
| 9028 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9029 | } |
| 9030 | |
| 9031 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9032 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9033 | * |
| 9034 | * <p>Requires one of the following permissions: |
| 9035 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9036 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9037 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9038 | * privileges. |
| 9039 | * |
| 9040 | * @param subId subscription id |
| 9041 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9042 | * {@code false}. |
| 9043 | */ |
| 9044 | @Override |
| 9045 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9046 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9047 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9048 | try { |
| 9049 | mApp.enforceCallingOrSelfPermission( |
| 9050 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9051 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9052 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9053 | mApp.enforceCallingOrSelfPermission( |
| 9054 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9055 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9056 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9057 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9058 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9059 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9060 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9061 | boolean isEnabled = false; |
| 9062 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9063 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9064 | Phone phone = getPhone(subId); |
| 9065 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9066 | } finally { |
| 9067 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9068 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9069 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9070 | } |
| 9071 | |
| 9072 | |
| 9073 | /** |
| 9074 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9075 | * |
| 9076 | * <p> Requires permission: |
| 9077 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9078 | * privileges. |
| 9079 | * |
| 9080 | * @param subId subscription id |
| 9081 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9082 | */ |
| 9083 | @Override |
| 9084 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9085 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9086 | mApp, subId, "setDataRoamingEnabled"); |
| 9087 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9088 | final long identity = Binder.clearCallingIdentity(); |
| 9089 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9090 | Phone phone = getPhone(subId); |
| 9091 | if (phone != null) { |
| 9092 | phone.setDataRoamingEnabled(isEnabled); |
| 9093 | } |
| 9094 | } finally { |
| 9095 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9096 | } |
| 9097 | } |
| 9098 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9099 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9100 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9101 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9102 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9103 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9104 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9105 | boolean isAllowed = true; |
| 9106 | final long identity = Binder.clearCallingIdentity(); |
| 9107 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9108 | Phone phone = getPhone(subId); |
| 9109 | if (phone != null) { |
| 9110 | isAllowed = phone.isCspPlmnEnabled(); |
| 9111 | } |
| 9112 | } finally { |
| 9113 | Binder.restoreCallingIdentity(identity); |
| 9114 | } |
| 9115 | return isAllowed; |
| 9116 | } |
| 9117 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9118 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9119 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9120 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9121 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9122 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9123 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9124 | if (phone == null) { |
| 9125 | return false; |
| 9126 | } |
| 9127 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9128 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9129 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9130 | } |
| 9131 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9132 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9133 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9134 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9135 | mApp.getSystemService(AppOpsManager.class) |
| 9136 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9137 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9138 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9139 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9140 | try { |
| 9141 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9142 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9143 | } catch (SecurityException e) { |
| 9144 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9145 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9146 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9147 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9148 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9149 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9150 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9151 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9152 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9153 | Binder.getCallingUid())) { |
| 9154 | isIccIdAccessRestricted = true; |
| 9155 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9156 | final long identity = Binder.clearCallingIdentity(); |
| 9157 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9158 | UiccController uiccController = UiccController.getInstance(); |
| 9159 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9160 | if (hasReadPermission) { |
| 9161 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9162 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9163 | |
| 9164 | // Remove private info if the caller doesn't have access |
| 9165 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9166 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9167 | //setting the value after compatibility check |
| 9168 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9169 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9170 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9171 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9172 | if (card == null) { |
| 9173 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9174 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9175 | continue; |
| 9176 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9177 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9178 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9179 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9180 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9181 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9182 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9183 | for (UiccPortInfo portInfo : portInfos) { |
| 9184 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9185 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9186 | if (port == null) { |
| 9187 | // assume no access if port is null |
| 9188 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9189 | continue; |
| 9190 | } |
| 9191 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9192 | uiccPortInfos.add(portInfo); |
| 9193 | } else { |
| 9194 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9195 | } |
| 9196 | } |
| 9197 | filteredInfos.add(new UiccCardInfo( |
| 9198 | cardInfo.isEuicc(), |
| 9199 | cardInfo.getCardId(), |
| 9200 | null, |
| 9201 | cardInfo.getPhysicalSlotIndex(), |
| 9202 | cardInfo.isRemovable(), |
| 9203 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9204 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9205 | } |
| 9206 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9207 | } finally { |
| 9208 | Binder.restoreCallingIdentity(identity); |
| 9209 | } |
| 9210 | } |
| 9211 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9212 | /** |
| 9213 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9214 | * generally private and require carrier privileges to view. |
| 9215 | * |
| 9216 | * @hide |
| 9217 | */ |
| 9218 | @NonNull |
| 9219 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9220 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9221 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9222 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9223 | } |
| 9224 | return new UiccCardInfo( |
| 9225 | cardInfo.isEuicc(), |
| 9226 | cardInfo.getCardId(), |
| 9227 | null, |
| 9228 | cardInfo.getPhysicalSlotIndex(), |
| 9229 | cardInfo.isRemovable(), |
| 9230 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9231 | portinfo |
| 9232 | ); |
| 9233 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9234 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9235 | /** |
| 9236 | * @hide |
| 9237 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9238 | * These values are generally private and require carrier privileges to view. |
| 9239 | */ |
| 9240 | @NonNull |
| 9241 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9242 | return new UiccPortInfo( |
| 9243 | UiccPortInfo.ICCID_REDACTED, |
| 9244 | portInfo.getPortIndex(), |
| 9245 | portInfo.getLogicalSlotIndex(), |
| 9246 | portInfo.isActive() |
| 9247 | ); |
| 9248 | } |
| 9249 | @Override |
| 9250 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9251 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9252 | mApp.getSystemService(AppOpsManager.class) |
| 9253 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9254 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9255 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9256 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9257 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9258 | // we are reading iccId which is PII data. |
| 9259 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9260 | |
| 9261 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9262 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9263 | Binder.getCallingUid())) { |
| 9264 | isLogicalSlotAccessRestricted = true; |
| 9265 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9266 | final long identity = Binder.clearCallingIdentity(); |
| 9267 | try { |
| 9268 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9269 | if (slots == null || slots.length == 0) { |
| 9270 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9271 | return null; |
| 9272 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9273 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9274 | for (int i = 0; i < slots.length; i++) { |
| 9275 | UiccSlot slot = slots[i]; |
| 9276 | if (slot == null) { |
| 9277 | continue; |
| 9278 | } |
| 9279 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9280 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9281 | UiccCard card = slot.getUiccCard(); |
| 9282 | if (card != null) { |
| 9283 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9284 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9285 | cardId = slot.getEid(); |
| 9286 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9287 | // If cardId is null, use iccId of default port as cardId. |
| 9288 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9290 | } |
| 9291 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9292 | if (cardId != null) { |
| 9293 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9294 | // if cardId is an EID, it's all digits so this is fine |
| 9295 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9296 | } |
| 9297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9298 | int cardState = 0; |
| 9299 | switch (slot.getCardState()) { |
| 9300 | case CARDSTATE_ABSENT: |
| 9301 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9302 | break; |
| 9303 | case CARDSTATE_PRESENT: |
| 9304 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9305 | break; |
| 9306 | case CARDSTATE_ERROR: |
| 9307 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9308 | break; |
| 9309 | case CARDSTATE_RESTRICTED: |
| 9310 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9311 | break; |
| 9312 | default: |
| 9313 | break; |
| 9314 | |
| 9315 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9316 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9317 | int[] portIndexes = slot.getPortList(); |
| 9318 | for (int portIdx : portIndexes) { |
| 9319 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9320 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9321 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9322 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9323 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9324 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9325 | slot.isEuicc(), |
| 9326 | cardId, |
| 9327 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9328 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9329 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9330 | //setting the value after compatibility check |
| 9331 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9332 | } |
| 9333 | return infos; |
| 9334 | } finally { |
| 9335 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9336 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9337 | } |
| 9338 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9339 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9340 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9341 | boolean hasReadPermission) { |
| 9342 | String iccId = slot.getIccId(portIndex); |
| 9343 | if (hasReadPermission) { // if has read permission |
| 9344 | return iccId; |
| 9345 | } else { |
| 9346 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9347 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9348 | // if no read permission, checking carrier privilege access |
| 9349 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9350 | return iccId; |
| 9351 | } |
| 9352 | } |
| 9353 | } |
| 9354 | // No read permission or carrier privilege access. |
| 9355 | return UiccPortInfo.ICCID_REDACTED; |
| 9356 | } |
| 9357 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9358 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9359 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9360 | public boolean switchSlots(int[] physicalSlots) { |
| 9361 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9362 | |
| 9363 | final long identity = Binder.clearCallingIdentity(); |
| 9364 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9365 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9366 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9367 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9368 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9369 | physicalSlots[i], i)); |
| 9370 | } |
| 9371 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9372 | } finally { |
| 9373 | Binder.restoreCallingIdentity(identity); |
| 9374 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9375 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9376 | |
| 9377 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9378 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9379 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9380 | enforceModifyPermission(); |
| 9381 | |
| 9382 | final long identity = Binder.clearCallingIdentity(); |
| 9383 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9384 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9385 | } finally { |
| 9386 | Binder.restoreCallingIdentity(identity); |
| 9387 | } |
| 9388 | } |
| 9389 | |
| 9390 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9391 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9392 | final long identity = Binder.clearCallingIdentity(); |
| 9393 | try { |
| 9394 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9395 | } finally { |
| 9396 | Binder.restoreCallingIdentity(identity); |
| 9397 | } |
| 9398 | } |
| 9399 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9400 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9401 | * A test API to reload the UICC profile. |
| 9402 | * |
| 9403 | * <p>Requires that the calling app has permission |
| 9404 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9405 | * @hide |
| 9406 | */ |
| 9407 | @Override |
| 9408 | public void refreshUiccProfile(int subId) { |
| 9409 | enforceModifyPermission(); |
| 9410 | |
| 9411 | final long identity = Binder.clearCallingIdentity(); |
| 9412 | try { |
| 9413 | Phone phone = getPhone(subId); |
| 9414 | if (phone == null) { |
| 9415 | return; |
| 9416 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9417 | UiccPort uiccPort = phone.getUiccPort(); |
| 9418 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9419 | return; |
| 9420 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9421 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9422 | if (uiccProfile == null) { |
| 9423 | return; |
| 9424 | } |
| 9425 | uiccProfile.refresh(); |
| 9426 | } finally { |
| 9427 | Binder.restoreCallingIdentity(identity); |
| 9428 | } |
| 9429 | } |
| 9430 | |
| 9431 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9432 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9433 | */ |
| 9434 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9435 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9436 | } |
| 9437 | |
| 9438 | /** |
| 9439 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9440 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9441 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9442 | */ |
| 9443 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9444 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9445 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9446 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9447 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9448 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9449 | return isDataRoamingEnabled; |
| 9450 | } |
| 9451 | |
| 9452 | /** |
| 9453 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9454 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9455 | */ |
| 9456 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9457 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9458 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9459 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9460 | return list.get(phoneId); |
| 9461 | } |
| 9462 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9463 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9464 | |
| 9465 | @Override |
| 9466 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9467 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9468 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9469 | |
| 9470 | final long identity = Binder.clearCallingIdentity(); |
| 9471 | try { |
| 9472 | final Phone phone = getPhone(subId); |
| 9473 | if (phone == null) { |
| 9474 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9475 | return; |
| 9476 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9477 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9478 | if (cpt != null) { |
| 9479 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9480 | } |
| 9481 | // 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] | 9482 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9483 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9484 | if (carrierPrivilegeRules == null) { |
| 9485 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9486 | } else { |
| 9487 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9488 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9489 | } finally { |
| 9490 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9491 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9492 | } |
| 9493 | |
| 9494 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9495 | public void setCarrierServicePackageOverride( |
| 9496 | int subId, String carrierServicePackage, String callingPackage) { |
| 9497 | TelephonyPermissions.enforceShellOnly( |
| 9498 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9499 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9500 | final long identity = Binder.clearCallingIdentity(); |
| 9501 | try { |
| 9502 | final Phone phone = getPhone(subId); |
| 9503 | if (phone == null || phone.getSubId() != subId) { |
| 9504 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9505 | throw new IllegalArgumentException("No phone for subid"); |
| 9506 | } |
| 9507 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9508 | if (cpt == null) { |
| 9509 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9510 | throw new IllegalStateException("No CPT for phone"); |
| 9511 | } |
| 9512 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9513 | } finally { |
| 9514 | Binder.restoreCallingIdentity(identity); |
| 9515 | } |
| 9516 | } |
| 9517 | |
| 9518 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9519 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9520 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9521 | |
| 9522 | final long identity = Binder.clearCallingIdentity(); |
| 9523 | try { |
| 9524 | final Phone phone = getPhone(subId); |
| 9525 | if (phone == null) { |
| 9526 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9527 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9528 | } |
| 9529 | return phone.getCarrierIdListVersion(); |
| 9530 | } finally { |
| 9531 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9532 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9533 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9534 | |
| 9535 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9536 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9537 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9538 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9539 | mApp, subId, callingPackage, callingFeatureId, |
| 9540 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9541 | return -1; |
| 9542 | } |
| 9543 | |
| 9544 | final long identity = Binder.clearCallingIdentity(); |
| 9545 | try { |
| 9546 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9547 | } finally { |
| 9548 | Binder.restoreCallingIdentity(identity); |
| 9549 | } |
| 9550 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9551 | |
| 9552 | @Override |
| 9553 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9554 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9555 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9556 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9557 | |
| 9558 | final long identity = Binder.clearCallingIdentity(); |
| 9559 | try { |
| 9560 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9561 | } finally { |
| 9562 | Binder.restoreCallingIdentity(identity); |
| 9563 | } |
| 9564 | } |
| 9565 | |
| 9566 | @Override |
| 9567 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9569 | mApp, subId, "setCdmaRoamingMode"); |
| 9570 | |
| 9571 | final long identity = Binder.clearCallingIdentity(); |
| 9572 | try { |
| 9573 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9574 | } finally { |
| 9575 | Binder.restoreCallingIdentity(identity); |
| 9576 | } |
| 9577 | } |
| 9578 | |
| 9579 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9580 | public int getCdmaSubscriptionMode(int subId) { |
| 9581 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9582 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9583 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9584 | |
| 9585 | final long identity = Binder.clearCallingIdentity(); |
| 9586 | try { |
| 9587 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9588 | } finally { |
| 9589 | Binder.restoreCallingIdentity(identity); |
| 9590 | } |
| 9591 | } |
| 9592 | |
| 9593 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9594 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9596 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9597 | |
| 9598 | final long identity = Binder.clearCallingIdentity(); |
| 9599 | try { |
| 9600 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9601 | } finally { |
| 9602 | Binder.restoreCallingIdentity(identity); |
| 9603 | } |
| 9604 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9605 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9606 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9607 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9608 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9609 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9610 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9611 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9612 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9613 | } |
| 9614 | final long identity = Binder.clearCallingIdentity(); |
| 9615 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9616 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9617 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9618 | if (phone.getEmergencyNumberTracker() != null |
| 9619 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9620 | emergencyNumberListInternal.put( |
| 9621 | phone.getSubId(), |
| 9622 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9623 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9624 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9625 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9626 | } finally { |
| 9627 | Binder.restoreCallingIdentity(identity); |
| 9628 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9629 | } |
| 9630 | |
| 9631 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9632 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9633 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9634 | if (!exactMatch) { |
| 9635 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9636 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9637 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9638 | } |
| 9639 | final long identity = Binder.clearCallingIdentity(); |
| 9640 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9641 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9642 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9643 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9644 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9645 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9646 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9647 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9648 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9649 | } |
| 9650 | return false; |
| 9651 | } finally { |
| 9652 | Binder.restoreCallingIdentity(identity); |
| 9653 | } |
| 9654 | } |
| 9655 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9656 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9657 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9658 | */ |
| 9659 | @Override |
| 9660 | public void startEmergencyCallbackMode() { |
| 9661 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9662 | "startEmergencyCallbackMode"); |
| 9663 | enforceModifyPermission(); |
| 9664 | final long identity = Binder.clearCallingIdentity(); |
| 9665 | try { |
| 9666 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9667 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9668 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9669 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9670 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9671 | gsmCdmaPhone.obtainMessage( |
| 9672 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9673 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9674 | } |
| 9675 | } |
| 9676 | } finally { |
| 9677 | Binder.restoreCallingIdentity(identity); |
| 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9682 | * Update emergency number list for test mode. |
| 9683 | */ |
| 9684 | @Override |
| 9685 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9686 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9687 | "updateEmergencyNumberListTestMode"); |
| 9688 | |
| 9689 | final long identity = Binder.clearCallingIdentity(); |
| 9690 | try { |
| 9691 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9692 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9693 | if (tracker != null) { |
| 9694 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9695 | } |
| 9696 | } |
| 9697 | } finally { |
| 9698 | Binder.restoreCallingIdentity(identity); |
| 9699 | } |
| 9700 | } |
| 9701 | |
| 9702 | /** |
| 9703 | * Get the full emergency number list for test mode. |
| 9704 | */ |
| 9705 | @Override |
| 9706 | public List<String> getEmergencyNumberListTestMode() { |
| 9707 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9708 | "getEmergencyNumberListTestMode"); |
| 9709 | |
| 9710 | final long identity = Binder.clearCallingIdentity(); |
| 9711 | try { |
| 9712 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9713 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9714 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9715 | if (tracker != null) { |
| 9716 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9717 | emergencyNumbers.add(num.getNumber()); |
| 9718 | } |
| 9719 | } |
| 9720 | } |
| 9721 | return new ArrayList<>(emergencyNumbers); |
| 9722 | } finally { |
| 9723 | Binder.restoreCallingIdentity(identity); |
| 9724 | } |
| 9725 | } |
| 9726 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9727 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9728 | public int getEmergencyNumberDbVersion(int subId) { |
| 9729 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9730 | |
| 9731 | final long identity = Binder.clearCallingIdentity(); |
| 9732 | try { |
| 9733 | final Phone phone = getPhone(subId); |
| 9734 | if (phone == null) { |
| 9735 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9736 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9737 | } |
| 9738 | return phone.getEmergencyNumberDbVersion(); |
| 9739 | } finally { |
| 9740 | Binder.restoreCallingIdentity(identity); |
| 9741 | } |
| 9742 | } |
| 9743 | |
| 9744 | @Override |
| 9745 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9746 | enforceModifyPermission(); |
| 9747 | |
| 9748 | final long identity = Binder.clearCallingIdentity(); |
| 9749 | try { |
| 9750 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9751 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9752 | if (tracker != null) { |
| 9753 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9754 | } |
| 9755 | } |
| 9756 | } finally { |
| 9757 | Binder.restoreCallingIdentity(identity); |
| 9758 | } |
| 9759 | } |
| 9760 | |
| 9761 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9762 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9763 | enforceActiveEmergencySessionPermission(); |
| 9764 | |
| 9765 | final long identity = Binder.clearCallingIdentity(); |
| 9766 | try { |
| 9767 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9768 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9769 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9770 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9771 | } |
| 9772 | } |
| 9773 | } finally { |
| 9774 | Binder.restoreCallingIdentity(identity); |
| 9775 | } |
| 9776 | } |
| 9777 | |
| 9778 | @Override |
| 9779 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9780 | enforceActiveEmergencySessionPermission(); |
| 9781 | |
| 9782 | final long identity = Binder.clearCallingIdentity(); |
| 9783 | try { |
| 9784 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9785 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9786 | if (tracker != null) { |
| 9787 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9788 | } |
| 9789 | } |
| 9790 | } finally { |
| 9791 | Binder.restoreCallingIdentity(identity); |
| 9792 | } |
| 9793 | } |
| 9794 | |
| 9795 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9796 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9797 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9798 | Phone phone = getPhone(subId); |
| 9799 | if (phone == null) { |
| 9800 | return null; |
| 9801 | } |
| 9802 | final long identity = Binder.clearCallingIdentity(); |
| 9803 | try { |
| 9804 | UiccProfile profile = UiccController.getInstance() |
| 9805 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9806 | if (profile != null) { |
| 9807 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9808 | } |
| 9809 | } finally { |
| 9810 | Binder.restoreCallingIdentity(identity); |
| 9811 | } |
| 9812 | return null; |
| 9813 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9814 | |
| 9815 | /** |
| 9816 | * Enable or disable a modem stack. |
| 9817 | */ |
| 9818 | @Override |
| 9819 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9820 | enforceModifyPermission(); |
| 9821 | |
| 9822 | final long identity = Binder.clearCallingIdentity(); |
| 9823 | try { |
| 9824 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9825 | if (phone == null) { |
| 9826 | return false; |
| 9827 | } else { |
| 9828 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9829 | } |
| 9830 | } finally { |
| 9831 | Binder.restoreCallingIdentity(identity); |
| 9832 | } |
| 9833 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9834 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9835 | /** |
| 9836 | * Whether a modem stack is enabled or not. |
| 9837 | */ |
| 9838 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9839 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9840 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9841 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9842 | if (phone == null) return false; |
| 9843 | |
| 9844 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9845 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9846 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9847 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9848 | } |
| 9849 | |
| 9850 | final long identity = Binder.clearCallingIdentity(); |
| 9851 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9852 | try { |
| 9853 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9854 | } catch (NoSuchElementException ex) { |
| 9855 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9856 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9857 | } finally { |
| 9858 | Binder.restoreCallingIdentity(identity); |
| 9859 | } |
| 9860 | } |
| 9861 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9862 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9863 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9864 | enforceModifyPermission(); |
| 9865 | |
| 9866 | final long identity = Binder.clearCallingIdentity(); |
| 9867 | try { |
| 9868 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9869 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9870 | .commit(); |
| 9871 | } finally { |
| 9872 | Binder.restoreCallingIdentity(identity); |
| 9873 | } |
| 9874 | } |
| 9875 | |
| 9876 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9877 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9878 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9879 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9880 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9881 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9882 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9883 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9884 | |
| 9885 | final long identity = Binder.clearCallingIdentity(); |
| 9886 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9887 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9888 | } finally { |
| 9889 | Binder.restoreCallingIdentity(identity); |
| 9890 | } |
| 9891 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9892 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9893 | @TelephonyManager.IsMultiSimSupportedResult |
| 9894 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9895 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9896 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9897 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9898 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9899 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9900 | } |
| 9901 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9902 | // supported by the modem, indicate that it is restricted. |
| 9903 | PhoneCapability staticCapability = |
| 9904 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9905 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9906 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9907 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9908 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9909 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9910 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9911 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9912 | } |
| 9913 | // Check if support of multiple SIMs is restricted by carrier |
| 9914 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9915 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9916 | } |
| 9917 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9918 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9919 | } |
| 9920 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9921 | /** |
| 9922 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9923 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9924 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9925 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9926 | * @param numOfSims number of active sims we want to switch to |
| 9927 | */ |
| 9928 | @Override |
| 9929 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9930 | if (numOfSims == 1) { |
| 9931 | enforceModifyPermission(); |
| 9932 | } else { |
| 9933 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9934 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9935 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9936 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9937 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9938 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9939 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9940 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9941 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9942 | return; |
| 9943 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9944 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9945 | } finally { |
| 9946 | Binder.restoreCallingIdentity(identity); |
| 9947 | } |
| 9948 | } |
| 9949 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9950 | @Override |
| 9951 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9952 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9953 | Phone phone = getPhone(subId); |
| 9954 | if (phone == null) { |
| 9955 | return false; |
| 9956 | } |
| 9957 | final long identity = Binder.clearCallingIdentity(); |
| 9958 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9959 | UiccPort uiccPort = phone.getUiccPort(); |
| 9960 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9961 | return false; |
| 9962 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9963 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9964 | if (uiccProfile == null) { |
| 9965 | return false; |
| 9966 | } |
| 9967 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9968 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9969 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9970 | } |
| 9971 | return false; |
| 9972 | } finally { |
| 9973 | Binder.restoreCallingIdentity(identity); |
| 9974 | } |
| 9975 | } |
| 9976 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9977 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9978 | * Get whether making changes to modem configurations will trigger reboot. |
| 9979 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9980 | */ |
| 9981 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9982 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9983 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9984 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9985 | mApp, subId, callingPackage, callingFeatureId, |
| 9986 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9987 | return false; |
| 9988 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9989 | final long identity = Binder.clearCallingIdentity(); |
| 9990 | try { |
| 9991 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9992 | } finally { |
| 9993 | Binder.restoreCallingIdentity(identity); |
| 9994 | } |
| 9995 | } |
| 9996 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9997 | private void updateModemStateMetrics() { |
| 9998 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9999 | // TODO: check the state for each modem if the api is ready. |
| 10000 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10001 | } |
| 10002 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10003 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10004 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10005 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10006 | // Verify that the callingPackage belongs to the calling UID |
| 10007 | mApp.getSystemService(AppOpsManager.class) |
| 10008 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10009 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10010 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10011 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10012 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10013 | if (slotInfos != null) { |
| 10014 | for (int i = 0; i < slotInfos.length; i++) { |
| 10015 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10016 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10017 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10018 | portInfo.getLogicalSlotIndex())); |
| 10019 | } |
| 10020 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10021 | } |
| 10022 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10023 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10024 | } finally { |
| 10025 | Binder.restoreCallingIdentity(identity); |
| 10026 | } |
| 10027 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10028 | |
| 10029 | /** |
| 10030 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10031 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10032 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10033 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10034 | @Override |
| 10035 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10036 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10037 | } |
| 10038 | |
| 10039 | /** |
| 10040 | * Get the HAL Version of a specific service |
| 10041 | */ |
| 10042 | @Override |
| 10043 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10044 | Phone phone = getDefaultPhone(); |
| 10045 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10046 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10047 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10048 | return hv.major * 100 + hv.minor; |
| 10049 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10050 | |
| 10051 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10052 | * Get the current calling package name. |
| 10053 | * @return the current calling package name |
| 10054 | */ |
| 10055 | @Override |
| 10056 | public String getCurrentPackageName() { |
| 10057 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10058 | } |
| 10059 | |
| 10060 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10061 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10062 | * corresponding network requests on a subId. |
| 10063 | * |
| 10064 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10065 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10066 | * 2) APN is un-metered for this subscription, or |
| 10067 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10068 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10069 | * |
| 10070 | * @return whether data is allowed for a apn type. |
| 10071 | * |
| 10072 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10073 | */ |
| 10074 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10075 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10076 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10077 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10078 | |
| 10079 | // Now that all security checks passes, perform the operation as ourselves. |
| 10080 | final long identity = Binder.clearCallingIdentity(); |
| 10081 | try { |
| 10082 | Phone phone = getPhone(subId); |
| 10083 | if (phone == null) return false; |
| 10084 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10085 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10086 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10087 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10088 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10089 | phone.getServiceState().getDataRoaming()); |
| 10090 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10091 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10092 | } finally { |
| 10093 | Binder.restoreCallingIdentity(identity); |
| 10094 | } |
| 10095 | } |
| 10096 | |
| 10097 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10098 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10099 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10100 | |
| 10101 | // Now that all security checks passes, perform the operation as ourselves. |
| 10102 | final long identity = Binder.clearCallingIdentity(); |
| 10103 | try { |
| 10104 | Phone phone = getPhone(subId); |
| 10105 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10106 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10107 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10108 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10109 | } finally { |
| 10110 | Binder.restoreCallingIdentity(identity); |
| 10111 | } |
| 10112 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10113 | |
| 10114 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10115 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10116 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10117 | enforceModifyPermission(); |
| 10118 | long token = Binder.clearCallingIdentity(); |
| 10119 | try { |
| 10120 | Phone phone = getPhone(subscriptionId); |
| 10121 | if (phone == null) { |
| 10122 | try { |
| 10123 | if (resultCallback != null) { |
| 10124 | resultCallback.accept(false); |
| 10125 | } |
| 10126 | } catch (RemoteException e) { |
| 10127 | // ignore |
| 10128 | } |
| 10129 | return; |
| 10130 | } |
| 10131 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10132 | Pair.create(specifiers, (x) -> { |
| 10133 | try { |
| 10134 | if (resultCallback != null) { |
| 10135 | resultCallback.accept(x); |
| 10136 | } |
| 10137 | } catch (RemoteException e) { |
| 10138 | // ignore |
| 10139 | } |
| 10140 | }); |
| 10141 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10142 | } finally { |
| 10143 | Binder.restoreCallingIdentity(token); |
| 10144 | } |
| 10145 | } |
| 10146 | |
| 10147 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10148 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10149 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10150 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10151 | mApp, subId, "getSystemSelectionChannels"); |
| 10152 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10153 | final long identity = Binder.clearCallingIdentity(); |
| 10154 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10155 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10156 | if (result instanceof IllegalStateException) { |
| 10157 | throw (IllegalStateException) result; |
| 10158 | } |
| 10159 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10160 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10161 | return specifiers; |
| 10162 | } finally { |
| 10163 | Binder.restoreCallingIdentity(identity); |
| 10164 | } |
| 10165 | } |
| 10166 | |
| 10167 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10168 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10169 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10170 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10171 | } |
| 10172 | |
| 10173 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10174 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10175 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10176 | if (callingPackage == null) { |
| 10177 | callingPackage = getCurrentPackageName(); |
| 10178 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10179 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10180 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10181 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10182 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10183 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10184 | } |
| 10185 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10186 | Intent intent = new Intent(); |
| 10187 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10188 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10189 | // Bring up choose default SMS subscription dialog right now |
| 10190 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10191 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10192 | mApp.startActivity(intent); |
| 10193 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10194 | |
| 10195 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10196 | public void showSwitchToManagedProfileDialog() { |
| 10197 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10198 | try { |
| 10199 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10200 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10201 | // for work telephony. |
| 10202 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10203 | intent.setData(Uri.parse("smsto:")); |
| 10204 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10205 | mApp.startActivity(intent); |
| 10206 | } catch (ActivityNotFoundException e) { |
| 10207 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10208 | Intent intent = new Intent(); |
| 10209 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10210 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10211 | mApp.startActivity(intent); |
| 10212 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10213 | } |
| 10214 | |
| 10215 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10216 | public String getMmsUAProfUrl(int subId) { |
| 10217 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10218 | final long identity = Binder.clearCallingIdentity(); |
| 10219 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10220 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10221 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10222 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10223 | return carrierUAProfUrl; |
| 10224 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10225 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10226 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10227 | } finally { |
| 10228 | Binder.restoreCallingIdentity(identity); |
| 10229 | } |
| 10230 | } |
| 10231 | |
| 10232 | @Override |
| 10233 | public String getMmsUserAgent(int subId) { |
| 10234 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10235 | final long identity = Binder.clearCallingIdentity(); |
| 10236 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10237 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10238 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10239 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10240 | return carrierUserAgent; |
| 10241 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10242 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10243 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10244 | } finally { |
| 10245 | Binder.restoreCallingIdentity(identity); |
| 10246 | } |
| 10247 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10248 | |
| 10249 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10250 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10251 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10252 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10253 | final long identity = Binder.clearCallingIdentity(); |
| 10254 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10255 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10256 | if (phone == null) return false; |
| 10257 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10258 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10259 | } finally { |
| 10260 | Binder.restoreCallingIdentity(identity); |
| 10261 | } |
| 10262 | } |
| 10263 | |
| 10264 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10265 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10266 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10267 | enforceModifyPermission(); |
| 10268 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10269 | final long identity = Binder.clearCallingIdentity(); |
| 10270 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10271 | Phone phone = getPhone(subscriptionId); |
| 10272 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10273 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10274 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10275 | } finally { |
| 10276 | Binder.restoreCallingIdentity(identity); |
| 10277 | } |
| 10278 | } |
| 10279 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10280 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10281 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10282 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10283 | * otherwise. |
| 10284 | */ |
| 10285 | @Override |
| 10286 | public void setCepEnabled(boolean isCepEnabled) { |
| 10287 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10288 | |
| 10289 | final long identity = Binder.clearCallingIdentity(); |
| 10290 | try { |
| 10291 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10292 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10293 | Phone defaultPhone = phone.getImsPhone(); |
| 10294 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10295 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10296 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10297 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10298 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10299 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10300 | + imsPhone.getMsisdn()); |
| 10301 | } |
| 10302 | } |
| 10303 | } finally { |
| 10304 | Binder.restoreCallingIdentity(identity); |
| 10305 | } |
| 10306 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10307 | |
| 10308 | /** |
| 10309 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10310 | * |
| 10311 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10312 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10313 | * before being read. |
| 10314 | */ |
| 10315 | @Override |
| 10316 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10317 | isCompressed) { |
| 10318 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10319 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10320 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10321 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10322 | } |
| 10323 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10324 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10325 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10326 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10327 | } |
| 10328 | |
| 10329 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10330 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10331 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10332 | } finally { |
| 10333 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10334 | } |
| 10335 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10336 | |
| 10337 | @Override |
| 10338 | public boolean isIccLockEnabled(int subId) { |
| 10339 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10340 | |
| 10341 | // Now that all security checks passes, perform the operation as ourselves. |
| 10342 | final long identity = Binder.clearCallingIdentity(); |
| 10343 | try { |
| 10344 | Phone phone = getPhone(subId); |
| 10345 | if (phone != null && phone.getIccCard() != null) { |
| 10346 | return phone.getIccCard().getIccLockEnabled(); |
| 10347 | } else { |
| 10348 | return false; |
| 10349 | } |
| 10350 | } finally { |
| 10351 | Binder.restoreCallingIdentity(identity); |
| 10352 | } |
| 10353 | } |
| 10354 | |
| 10355 | /** |
| 10356 | * Set the ICC pin lock enabled or disabled. |
| 10357 | * |
| 10358 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10359 | * three cases: |
| 10360 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10361 | * successfully. |
| 10362 | * - Positive number and zero for remaining password attempts. |
| 10363 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10364 | * |
| 10365 | */ |
| 10366 | @Override |
| 10367 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10368 | enforceModifyPermission(); |
| 10369 | |
| 10370 | Phone phone = getPhone(subId); |
| 10371 | if (phone == null) { |
| 10372 | return 0; |
| 10373 | } |
| 10374 | // Now that all security checks passes, perform the operation as ourselves. |
| 10375 | final long identity = Binder.clearCallingIdentity(); |
| 10376 | try { |
| 10377 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10378 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10379 | return attemptsRemaining; |
| 10380 | |
| 10381 | } catch (Exception e) { |
| 10382 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10383 | } finally { |
| 10384 | Binder.restoreCallingIdentity(identity); |
| 10385 | } |
| 10386 | return 0; |
| 10387 | } |
| 10388 | |
| 10389 | /** |
| 10390 | * Change the ICC password used in ICC pin lock. |
| 10391 | * |
| 10392 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10393 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10394 | * - Positive number and zero for remaining password attempts. |
| 10395 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10396 | * |
| 10397 | */ |
| 10398 | @Override |
| 10399 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10400 | enforceModifyPermission(); |
| 10401 | |
| 10402 | Phone phone = getPhone(subId); |
| 10403 | if (phone == null) { |
| 10404 | return 0; |
| 10405 | } |
| 10406 | // Now that all security checks passes, perform the operation as ourselves. |
| 10407 | final long identity = Binder.clearCallingIdentity(); |
| 10408 | try { |
| 10409 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10410 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10411 | return attemptsRemaining; |
| 10412 | |
| 10413 | } catch (Exception e) { |
| 10414 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10415 | } finally { |
| 10416 | Binder.restoreCallingIdentity(identity); |
| 10417 | } |
| 10418 | return 0; |
| 10419 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10420 | |
| 10421 | /** |
| 10422 | * Request for receiving user activity notification |
| 10423 | */ |
| 10424 | @Override |
| 10425 | public void requestUserActivityNotification() { |
| 10426 | if (!mNotifyUserActivity.get() |
| 10427 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10428 | mNotifyUserActivity.set(true); |
| 10429 | } |
| 10430 | } |
| 10431 | |
| 10432 | /** |
| 10433 | * Called when userActivity is signalled in the power manager. |
| 10434 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10435 | */ |
| 10436 | @Override |
| 10437 | public void userActivity() { |
| 10438 | // *************************************** |
| 10439 | // * Inherited from PhoneWindowManager * |
| 10440 | // *************************************** |
| 10441 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10442 | // WITH ITS LOCKS HELD. |
| 10443 | // |
| 10444 | // This code must be VERY careful about the locks |
| 10445 | // it acquires. |
| 10446 | // In fact, the current code acquires way too many, |
| 10447 | // and probably has lurking deadlocks. |
| 10448 | |
| 10449 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10450 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10451 | } |
| 10452 | |
| 10453 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10454 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10455 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10456 | } |
| 10457 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10458 | |
| 10459 | @Override |
| 10460 | public boolean canConnectTo5GInDsdsMode() { |
| 10461 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10462 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10463 | |
| 10464 | @Override |
| 10465 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10466 | String callingFeatureId) { |
| 10467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10468 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10469 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10470 | } |
| 10471 | |
| 10472 | Phone phone = getPhone(subId); |
| 10473 | if (phone == null) { |
| 10474 | throw new RuntimeException("phone is not available"); |
| 10475 | } |
| 10476 | // Now that all security checks passes, perform the operation as ourselves. |
| 10477 | final long identity = Binder.clearCallingIdentity(); |
| 10478 | try { |
| 10479 | return phone.getEquivalentHomePlmns(); |
| 10480 | } finally { |
| 10481 | Binder.restoreCallingIdentity(identity); |
| 10482 | } |
| 10483 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10484 | |
| 10485 | @Override |
| 10486 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10487 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10488 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10489 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10490 | if (radioInterfaceCapabilities == null) { |
| 10491 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10492 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10493 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10494 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10495 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10496 | @Override |
| 10497 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10498 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10499 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10500 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10501 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10502 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10503 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10504 | if (DBG) { |
| 10505 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10506 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10507 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10508 | } |
| 10509 | |
| 10510 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10511 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10512 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10513 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10514 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10515 | if (callback != null) { |
| 10516 | try { |
| 10517 | callback.onAuthenticationFailure( |
| 10518 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10519 | } catch (RemoteException exception) { |
| 10520 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10521 | } |
| 10522 | return; |
| 10523 | } |
| 10524 | } |
| 10525 | |
| 10526 | final long token = Binder.clearCallingIdentity(); |
| 10527 | try { |
| 10528 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10529 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10530 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10531 | } finally { |
| 10532 | Binder.restoreCallingIdentity(token); |
| 10533 | } |
| 10534 | } |
| 10535 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10536 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10537 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10538 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10539 | * requested radio power state will actually be set. See {@link |
| 10540 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10541 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10542 | * @param enable {@code true} if trying to turn radio on. |
| 10543 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10544 | * false}. |
| 10545 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10546 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10547 | boolean isPhoneAvailable = false; |
| 10548 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10549 | Phone phone = PhoneFactory.getPhone(i); |
| 10550 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10551 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10552 | isPhoneAvailable = true; |
| 10553 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10554 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10555 | |
| 10556 | // return true if successfully informed the phone object about the thermal radio power |
| 10557 | // request. |
| 10558 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10559 | } |
| 10560 | |
| 10561 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10562 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10563 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10564 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10565 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10566 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10567 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10568 | } |
| 10569 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10570 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10571 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10572 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10573 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10574 | } |
| 10575 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10576 | setDataEnabledForReason( |
| 10577 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10578 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10579 | if (isDataThrottlingSupported) { |
| 10580 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10581 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10582 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10583 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10584 | } else if (thermalMitigationResult |
| 10585 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10586 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10587 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10588 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10589 | } |
| 10590 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10591 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10592 | |
| 10593 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10594 | } |
| 10595 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10596 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10597 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10598 | for (String pckg : context.getResources() |
| 10599 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10600 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10601 | } |
| 10602 | } |
| 10603 | |
| 10604 | return sThermalMitigationAllowlistedPackages; |
| 10605 | } |
| 10606 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10607 | private boolean isAnyPhoneInEmergencyState() { |
| 10608 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10609 | if (tm.isInEmergencyCall()) { |
| 10610 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10611 | return true; |
| 10612 | } |
| 10613 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10614 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10615 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10616 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10617 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10618 | return true; |
| 10619 | } |
| 10620 | } |
| 10621 | |
| 10622 | return false; |
| 10623 | } |
| 10624 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10625 | /** |
| 10626 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10627 | * @param packageName name of package to be allowlisted |
| 10628 | * @param context |
| 10629 | */ |
| 10630 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10631 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10632 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10633 | } |
| 10634 | |
| 10635 | /** |
| 10636 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10637 | * @param packageName name of package to remove from allowlist |
| 10638 | * @param context |
| 10639 | */ |
| 10640 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10641 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10642 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10643 | } |
| 10644 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10645 | /** |
| 10646 | * Thermal mitigation request to control functionalities at modem. |
| 10647 | * |
| 10648 | * @param subId the id of the subscription. |
| 10649 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10650 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10651 | * |
| 10652 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10653 | */ |
| 10654 | @Override |
| 10655 | @ThermalMitigationResult |
| 10656 | public int sendThermalMitigationRequest( |
| 10657 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10658 | ThermalMitigationRequest thermalMitigationRequest, |
| 10659 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10660 | enforceModifyPermission(); |
| 10661 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10662 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10663 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10664 | .contains(callingPackage)) { |
| 10665 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10666 | + "calling package: " + callingPackage); |
| 10667 | } |
| 10668 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10669 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10670 | final long identity = Binder.clearCallingIdentity(); |
| 10671 | |
| 10672 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10673 | try { |
| 10674 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10675 | switch (thermalMitigationAction) { |
| 10676 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10677 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10678 | handleDataThrottlingRequest(subId, |
| 10679 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10680 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10681 | break; |
| 10682 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10683 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10684 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10685 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10686 | } |
| 10687 | |
| 10688 | // Ensure that radio is on. If not able to power on due to phone being |
| 10689 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10690 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10691 | thermalMitigationResult = |
| 10692 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10693 | break; |
| 10694 | } |
| 10695 | |
| 10696 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10697 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10698 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10699 | break; |
| 10700 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10701 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10702 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10703 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10704 | } |
| 10705 | |
| 10706 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10707 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10708 | Phone phone = getPhone(subId); |
| 10709 | if (phone == null) { |
| 10710 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10711 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10712 | break; |
| 10713 | } |
| 10714 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10715 | TelephonyConnectionService service = |
| 10716 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10717 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10718 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10719 | thermalMitigationResult = |
| 10720 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10721 | break; |
| 10722 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10723 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10724 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10725 | break; |
| 10726 | } |
| 10727 | } else { |
| 10728 | thermalMitigationResult = |
| 10729 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10730 | break; |
| 10731 | } |
| 10732 | |
| 10733 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10734 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10735 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10736 | thermalMitigationResult = |
| 10737 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10738 | break; |
| 10739 | } |
| 10740 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10741 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10742 | break; |
| 10743 | default: |
| 10744 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10745 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10746 | } |
| 10747 | } catch (IllegalArgumentException e) { |
| 10748 | throw e; |
| 10749 | } catch (Exception e) { |
| 10750 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10751 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10752 | } finally { |
| 10753 | Binder.restoreCallingIdentity(identity); |
| 10754 | } |
| 10755 | |
| 10756 | if (DBG) { |
| 10757 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10758 | + thermalMitigationResult); |
| 10759 | } |
| 10760 | |
| 10761 | return thermalMitigationResult; |
| 10762 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10763 | |
| 10764 | /** |
| 10765 | * Set the GbaService Package Name that Telephony will bind to. |
| 10766 | * |
| 10767 | * @param subId The sim that the GbaService is associated with. |
| 10768 | * @param packageName The name of the package to be replaced with. |
| 10769 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10770 | */ |
| 10771 | @Override |
| 10772 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10773 | enforceModifyPermission(); |
| 10774 | |
| 10775 | final long identity = Binder.clearCallingIdentity(); |
| 10776 | try { |
| 10777 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10778 | } finally { |
| 10779 | Binder.restoreCallingIdentity(identity); |
| 10780 | } |
| 10781 | } |
| 10782 | |
| 10783 | /** |
| 10784 | * Return the package name of the currently bound GbaService. |
| 10785 | * |
| 10786 | * @param subId The sim that the GbaService is associated with. |
| 10787 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10788 | */ |
| 10789 | @Override |
| 10790 | public String getBoundGbaService(int subId) { |
| 10791 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10792 | |
| 10793 | final long identity = Binder.clearCallingIdentity(); |
| 10794 | try { |
| 10795 | return getGbaManager(subId).getServicePackage(); |
| 10796 | } finally { |
| 10797 | Binder.restoreCallingIdentity(identity); |
| 10798 | } |
| 10799 | } |
| 10800 | |
| 10801 | /** |
| 10802 | * Set the release time for telephony to unbind GbaService. |
| 10803 | * |
| 10804 | * @param subId The sim that the GbaService is associated with. |
| 10805 | * @param interval The release time to unbind GbaService by millisecond. |
| 10806 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10807 | */ |
| 10808 | @Override |
| 10809 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10810 | enforceModifyPermission(); |
| 10811 | |
| 10812 | final long identity = Binder.clearCallingIdentity(); |
| 10813 | try { |
| 10814 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10815 | } finally { |
| 10816 | Binder.restoreCallingIdentity(identity); |
| 10817 | } |
| 10818 | } |
| 10819 | |
| 10820 | /** |
| 10821 | * Return the release time for telephony to unbind GbaService. |
| 10822 | * |
| 10823 | * @param subId The sim that the GbaService is associated with. |
| 10824 | * @return The release time to unbind GbaService by millisecond. |
| 10825 | */ |
| 10826 | @Override |
| 10827 | public int getGbaReleaseTime(int subId) { |
| 10828 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10829 | |
| 10830 | final long identity = Binder.clearCallingIdentity(); |
| 10831 | try { |
| 10832 | return getGbaManager(subId).getReleaseTime(); |
| 10833 | } finally { |
| 10834 | Binder.restoreCallingIdentity(identity); |
| 10835 | } |
| 10836 | } |
| 10837 | |
| 10838 | private GbaManager getGbaManager(int subId) { |
| 10839 | GbaManager instance = GbaManager.getInstance(subId); |
| 10840 | if (instance == null) { |
| 10841 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10842 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10843 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10844 | } |
| 10845 | return instance; |
| 10846 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10847 | |
| 10848 | /** |
| 10849 | * indicate whether the device and the carrier can support |
| 10850 | * RCS VoLTE single registration. |
| 10851 | */ |
| 10852 | @Override |
| 10853 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10854 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10855 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10856 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10857 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10858 | |
| 10859 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10860 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10861 | } |
| 10862 | |
| 10863 | final long identity = Binder.clearCallingIdentity(); |
| 10864 | try { |
| 10865 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10866 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10867 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10868 | if (isCapable != null) { |
| 10869 | return isCapable; |
| 10870 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10871 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10872 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10873 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10874 | } finally { |
| 10875 | Binder.restoreCallingIdentity(identity); |
| 10876 | } |
| 10877 | } |
| 10878 | |
| 10879 | /** |
| 10880 | * Register RCS provisioning callback. |
| 10881 | */ |
| 10882 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10883 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10884 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10885 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10886 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10887 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10888 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10889 | |
| 10890 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10891 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10892 | } |
| 10893 | if (!isImsAvailableOnDevice()) { |
| 10894 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10895 | "IMS not available on device."); |
| 10896 | } |
| 10897 | |
| 10898 | final long identity = Binder.clearCallingIdentity(); |
| 10899 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10900 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10901 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10902 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10903 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10904 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10905 | } finally { |
| 10906 | Binder.restoreCallingIdentity(identity); |
| 10907 | } |
| 10908 | } |
| 10909 | |
| 10910 | /** |
| 10911 | * Unregister RCS provisioning callback. |
| 10912 | */ |
| 10913 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10914 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10915 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10916 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10917 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10918 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10919 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10920 | |
| 10921 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10922 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10923 | } |
| 10924 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10925 | // operation failed silently |
| 10926 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10927 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10928 | } |
| 10929 | |
| 10930 | final long identity = Binder.clearCallingIdentity(); |
| 10931 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10932 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10933 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10934 | } finally { |
| 10935 | Binder.restoreCallingIdentity(identity); |
| 10936 | } |
| 10937 | } |
| 10938 | |
| 10939 | /** |
| 10940 | * trigger RCS reconfiguration. |
| 10941 | */ |
| 10942 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10943 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10944 | "triggerRcsReconfiguration", |
| 10945 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10946 | |
| 10947 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10948 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10949 | } |
| 10950 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10951 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10952 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10953 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10954 | } |
| 10955 | |
| 10956 | final long identity = Binder.clearCallingIdentity(); |
| 10957 | try { |
| 10958 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10959 | } finally { |
| 10960 | Binder.restoreCallingIdentity(identity); |
| 10961 | } |
| 10962 | } |
| 10963 | |
| 10964 | /** |
| 10965 | * Provide the client configuration parameters of the RCS application. |
| 10966 | */ |
| 10967 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10968 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10969 | "setRcsClientConfiguration", |
| 10970 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10971 | |
| 10972 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10973 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10974 | } |
| 10975 | if (!isImsAvailableOnDevice()) { |
| 10976 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10977 | "IMS not available on device."); |
| 10978 | } |
| 10979 | |
| 10980 | final long identity = Binder.clearCallingIdentity(); |
| 10981 | |
| 10982 | try { |
| 10983 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10984 | if (configBinder == null) { |
| 10985 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10986 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10987 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10988 | } else { |
| 10989 | configBinder.setRcsClientConfiguration(rcc); |
| 10990 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10991 | |
| 10992 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10993 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10994 | } catch (RemoteException e) { |
| 10995 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10996 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10997 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10998 | } finally { |
| 10999 | Binder.restoreCallingIdentity(identity); |
| 11000 | } |
| 11001 | } |
| 11002 | |
| 11003 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11004 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11005 | */ |
| 11006 | @Override |
| 11007 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11008 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11009 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11010 | |
| 11011 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11012 | } |
| 11013 | |
| 11014 | /** |
| 11015 | * Gets the test mode for RCS VoLTE single registration. |
| 11016 | */ |
| 11017 | @Override |
| 11018 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11019 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11020 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11021 | |
| 11022 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11023 | } |
| 11024 | |
| 11025 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11026 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11027 | */ |
| 11028 | @Override |
| 11029 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11031 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11032 | enforceModifyPermission(); |
| 11033 | |
| 11034 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11035 | : Boolean.parseBoolean(enabledStr); |
| 11036 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11037 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11038 | } |
| 11039 | |
| 11040 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11041 | * Sends a device to device communication message. Only usable via shell. |
| 11042 | * @param message message to send. |
| 11043 | * @param value message value. |
| 11044 | */ |
| 11045 | @Override |
| 11046 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11047 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11048 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11049 | enforceModifyPermission(); |
| 11050 | |
| 11051 | final long identity = Binder.clearCallingIdentity(); |
| 11052 | try { |
| 11053 | TelephonyConnectionService service = |
| 11054 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11055 | if (service == null) { |
| 11056 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11057 | return; |
| 11058 | } |
| 11059 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11060 | } finally { |
| 11061 | Binder.restoreCallingIdentity(identity); |
| 11062 | } |
| 11063 | } |
| 11064 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11065 | /** |
| 11066 | * Sets the specified device to device transport active. |
| 11067 | * @param transport The transport to set active. |
| 11068 | */ |
| 11069 | @Override |
| 11070 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11071 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11072 | "setActiveDeviceToDeviceTransport"); |
| 11073 | enforceModifyPermission(); |
| 11074 | |
| 11075 | final long identity = Binder.clearCallingIdentity(); |
| 11076 | try { |
| 11077 | TelephonyConnectionService service = |
| 11078 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11079 | if (service == null) { |
| 11080 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11081 | return; |
| 11082 | } |
| 11083 | service.setActiveDeviceToDeviceTransport(transport); |
| 11084 | } finally { |
| 11085 | Binder.restoreCallingIdentity(identity); |
| 11086 | } |
| 11087 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11088 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11089 | @Override |
| 11090 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11091 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11092 | "setDeviceToDeviceForceEnabled"); |
| 11093 | |
| 11094 | final long identity = Binder.clearCallingIdentity(); |
| 11095 | try { |
| 11096 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11097 | p -> { |
| 11098 | Phone thePhone = p.getImsPhone(); |
| 11099 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11100 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11101 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11102 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11103 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11104 | (ImsPhoneCallTracker) tracker; |
| 11105 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11106 | } |
| 11107 | } |
| 11108 | } |
| 11109 | ); |
| 11110 | } finally { |
| 11111 | Binder.restoreCallingIdentity(identity); |
| 11112 | } |
| 11113 | } |
| 11114 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11115 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11116 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11117 | */ |
| 11118 | @Override |
| 11119 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11120 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11121 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11122 | } |
| 11123 | |
| 11124 | /** |
| 11125 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11126 | */ |
| 11127 | @Override |
| 11128 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11129 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11130 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11131 | enforceModifyPermission(); |
| 11132 | |
| 11133 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11134 | : Boolean.parseBoolean(enabledStr); |
| 11135 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11136 | subId, enabled); |
| 11137 | } |
| 11138 | |
| 11139 | /** |
| 11140 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11141 | */ |
| 11142 | @Override |
| 11143 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11144 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11145 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11146 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11147 | |
| 11148 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11149 | * Overrides the ims feature validation result |
| 11150 | */ |
| 11151 | @Override |
| 11152 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11153 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11154 | "setImsFeatureValidationOverride"); |
| 11155 | |
| 11156 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11157 | : Boolean.parseBoolean(enabledStr); |
| 11158 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11159 | subId, enabled); |
| 11160 | } |
| 11161 | |
| 11162 | /** |
| 11163 | * Gets the ims feature validation override value |
| 11164 | */ |
| 11165 | @Override |
| 11166 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11167 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11168 | "getImsFeatureValidationOverride"); |
| 11169 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11170 | } |
| 11171 | |
| 11172 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11173 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11174 | * their mobile plan. |
| 11175 | */ |
| 11176 | @Override |
| 11177 | public String getMobileProvisioningUrl() { |
| 11178 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11179 | final long identity = Binder.clearCallingIdentity(); |
| 11180 | try { |
| 11181 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11182 | } finally { |
| 11183 | Binder.restoreCallingIdentity(identity); |
| 11184 | } |
| 11185 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11186 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11187 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11188 | * Get the EAB contact from the EAB database. |
| 11189 | */ |
| 11190 | @Override |
| 11191 | public String getContactFromEab(String contact) { |
| 11192 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11193 | enforceModifyPermission(); |
| 11194 | final long identity = Binder.clearCallingIdentity(); |
| 11195 | try { |
| 11196 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11197 | } finally { |
| 11198 | Binder.restoreCallingIdentity(identity); |
| 11199 | } |
| 11200 | } |
| 11201 | |
| 11202 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11203 | * Get the EAB capability from the EAB database. |
| 11204 | */ |
| 11205 | @Override |
| 11206 | public String getCapabilityFromEab(String contact) { |
| 11207 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11208 | enforceModifyPermission(); |
| 11209 | final long identity = Binder.clearCallingIdentity(); |
| 11210 | try { |
| 11211 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11212 | } finally { |
| 11213 | Binder.restoreCallingIdentity(identity); |
| 11214 | } |
| 11215 | } |
| 11216 | |
| 11217 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11218 | * Remove the EAB contacts from the EAB database. |
| 11219 | */ |
| 11220 | @Override |
| 11221 | public int removeContactFromEab(int subId, String contacts) { |
| 11222 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11223 | enforceModifyPermission(); |
| 11224 | final long identity = Binder.clearCallingIdentity(); |
| 11225 | try { |
| 11226 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11227 | } finally { |
| 11228 | Binder.restoreCallingIdentity(identity); |
| 11229 | } |
| 11230 | } |
| 11231 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11232 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11233 | public boolean getDeviceUceEnabled() { |
| 11234 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11235 | final long identity = Binder.clearCallingIdentity(); |
| 11236 | try { |
| 11237 | return mApp.getDeviceUceEnabled(); |
| 11238 | } finally { |
| 11239 | Binder.restoreCallingIdentity(identity); |
| 11240 | } |
| 11241 | } |
| 11242 | |
| 11243 | @Override |
| 11244 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11245 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11246 | final long identity = Binder.clearCallingIdentity(); |
| 11247 | try { |
| 11248 | mApp.setDeviceUceEnabled(isEnabled); |
| 11249 | } finally { |
| 11250 | Binder.restoreCallingIdentity(identity); |
| 11251 | } |
| 11252 | } |
| 11253 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11254 | /** |
| 11255 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11256 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11257 | */ |
| 11258 | // Used for SHELL command only right now. |
| 11259 | @Override |
| 11260 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11261 | List<String> featureTags) { |
| 11262 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11263 | "addUceRegistrationOverrideShell"); |
| 11264 | final long identity = Binder.clearCallingIdentity(); |
| 11265 | try { |
| 11266 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11267 | new ArraySet<>(featureTags)); |
| 11268 | } catch (ImsException e) { |
| 11269 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11270 | } finally { |
| 11271 | Binder.restoreCallingIdentity(identity); |
| 11272 | } |
| 11273 | } |
| 11274 | |
| 11275 | /** |
| 11276 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11277 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11278 | */ |
| 11279 | // Used for SHELL command only right now. |
| 11280 | @Override |
| 11281 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11282 | List<String> featureTags) { |
| 11283 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11284 | "removeUceRegistrationOverrideShell"); |
| 11285 | final long identity = Binder.clearCallingIdentity(); |
| 11286 | try { |
| 11287 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11288 | new ArraySet<>(featureTags)); |
| 11289 | } catch (ImsException e) { |
| 11290 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11291 | } finally { |
| 11292 | Binder.restoreCallingIdentity(identity); |
| 11293 | } |
| 11294 | } |
| 11295 | |
| 11296 | /** |
| 11297 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11298 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11299 | */ |
| 11300 | // Used for SHELL command only right now. |
| 11301 | @Override |
| 11302 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11303 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11304 | "clearUceRegistrationOverrideShell"); |
| 11305 | final long identity = Binder.clearCallingIdentity(); |
| 11306 | try { |
| 11307 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11308 | } catch (ImsException e) { |
| 11309 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11310 | } finally { |
| 11311 | Binder.restoreCallingIdentity(identity); |
| 11312 | } |
| 11313 | } |
| 11314 | |
| 11315 | /** |
| 11316 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11317 | */ |
| 11318 | // Used for SHELL command only right now. |
| 11319 | @Override |
| 11320 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11321 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11322 | "getLatestRcsContactUceCapabilityShell"); |
| 11323 | final long identity = Binder.clearCallingIdentity(); |
| 11324 | try { |
| 11325 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11326 | } catch (ImsException e) { |
| 11327 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11328 | } finally { |
| 11329 | Binder.restoreCallingIdentity(identity); |
| 11330 | } |
| 11331 | } |
| 11332 | |
| 11333 | /** |
| 11334 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11335 | * device does not have an active PUBLISH. |
| 11336 | */ |
| 11337 | // Used for SHELL command only right now. |
| 11338 | @Override |
| 11339 | public String getLastUcePidfXmlShell(int subId) { |
| 11340 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11341 | final long identity = Binder.clearCallingIdentity(); |
| 11342 | try { |
| 11343 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11344 | } catch (ImsException e) { |
| 11345 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11346 | } finally { |
| 11347 | Binder.restoreCallingIdentity(identity); |
| 11348 | } |
| 11349 | } |
| 11350 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11351 | /** |
| 11352 | * Remove UCE requests cannot be sent to the network status. |
| 11353 | */ |
| 11354 | // Used for SHELL command only right now. |
| 11355 | @Override |
| 11356 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11357 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11358 | final long identity = Binder.clearCallingIdentity(); |
| 11359 | try { |
| 11360 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11361 | } catch (ImsException e) { |
| 11362 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11363 | } finally { |
| 11364 | Binder.restoreCallingIdentity(identity); |
| 11365 | } |
| 11366 | } |
| 11367 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11368 | /** |
| 11369 | * Remove UCE requests cannot be sent to the network status. |
| 11370 | */ |
| 11371 | // Used for SHELL command only. |
| 11372 | @Override |
| 11373 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11374 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11375 | final long identity = Binder.clearCallingIdentity(); |
| 11376 | try { |
| 11377 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11378 | } catch (ImsException e) { |
| 11379 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11380 | } finally { |
| 11381 | Binder.restoreCallingIdentity(identity); |
| 11382 | } |
| 11383 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11384 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11385 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11386 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11387 | String callingPackage) { |
| 11388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11389 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11390 | |
| 11391 | final int callingUid = Binder.getCallingUid(); |
| 11392 | // Verify that tha callingPackage belongs to the calling UID |
| 11393 | mApp.getSystemService(AppOpsManager.class) |
| 11394 | .checkPackage(callingUid, callingPackage); |
| 11395 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11396 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11397 | |
| 11398 | final long identity = Binder.clearCallingIdentity(); |
| 11399 | try { |
| 11400 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11401 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11402 | |
| 11403 | if (result instanceof IllegalStateException) { |
| 11404 | throw (IllegalStateException) result; |
| 11405 | } |
| 11406 | } finally { |
| 11407 | Binder.restoreCallingIdentity(identity); |
| 11408 | } |
| 11409 | } |
| 11410 | |
| 11411 | @Override |
| 11412 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11413 | String callingPackage) { |
| 11414 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11415 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11416 | |
| 11417 | final int callingUid = Binder.getCallingUid(); |
| 11418 | // Verify that tha callingPackage belongs to the calling UID |
| 11419 | mApp.getSystemService(AppOpsManager.class) |
| 11420 | .checkPackage(callingUid, callingPackage); |
| 11421 | |
| 11422 | final long identity = Binder.clearCallingIdentity(); |
| 11423 | try { |
| 11424 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11425 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11426 | |
| 11427 | if (result instanceof IllegalStateException) { |
| 11428 | throw (IllegalStateException) result; |
| 11429 | } |
| 11430 | } finally { |
| 11431 | Binder.restoreCallingIdentity(identity); |
| 11432 | } |
| 11433 | } |
| 11434 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11435 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11436 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11437 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11438 | // phone/system process do not have further restriction on request |
| 11439 | return; |
| 11440 | } |
| 11441 | |
| 11442 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11443 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11444 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11445 | context.enforceCallingOrSelfPermission( |
| 11446 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11447 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11448 | } |
| 11449 | |
| 11450 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11451 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11452 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11453 | || info.isEnabled()) { |
| 11454 | throw new IllegalArgumentException( |
| 11455 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11456 | } |
| 11457 | |
| 11458 | // Thresholds length for each RAN need in range. This has been validated in |
| 11459 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11460 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11461 | final int[] thresholds = info.getThresholds(); |
| 11462 | Objects.requireNonNull(thresholds); |
| 11463 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11464 | || thresholds.length |
| 11465 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11466 | throw new IllegalArgumentException( |
| 11467 | "thresholds length is out of range: " + thresholds.length); |
| 11468 | } |
| 11469 | } |
| 11470 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11471 | |
| 11472 | /** |
| 11473 | * Gets the current phone capability. |
| 11474 | * |
| 11475 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11476 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11477 | * It's used to evaluate possible phone config change, for example from single |
| 11478 | * SIM device to multi-SIM device. |
| 11479 | */ |
| 11480 | @Override |
| 11481 | public PhoneCapability getPhoneCapability() { |
| 11482 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11483 | final long identity = Binder.clearCallingIdentity(); |
| 11484 | try { |
| 11485 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11486 | } finally { |
| 11487 | Binder.restoreCallingIdentity(identity); |
| 11488 | } |
| 11489 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11490 | |
| 11491 | /** |
| 11492 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11493 | * required to be done shortly after the API is invoked. |
| 11494 | */ |
| 11495 | @Override |
| 11496 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11497 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11498 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11499 | enforceRebootPermission(); |
| 11500 | |
| 11501 | final long identity = Binder.clearCallingIdentity(); |
| 11502 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11503 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11504 | } finally { |
| 11505 | Binder.restoreCallingIdentity(identity); |
| 11506 | } |
| 11507 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11508 | |
| 11509 | /** |
| 11510 | * Request to get the current slicing configuration including URSP rules and |
| 11511 | * NSSAIs (configured, allowed and rejected). |
| 11512 | * |
| 11513 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11514 | */ |
| 11515 | @Override |
| 11516 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11517 | TelephonyPermissions |
| 11518 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11519 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11520 | |
| 11521 | final long identity = Binder.clearCallingIdentity(); |
| 11522 | try { |
| 11523 | Phone phone = getDefaultPhone(); |
| 11524 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11525 | } finally { |
| 11526 | Binder.restoreCallingIdentity(identity); |
| 11527 | } |
| 11528 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11529 | |
| 11530 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11531 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11532 | * |
| 11533 | * @param capability The premium capability to check. |
| 11534 | * @param subId The subId to check the premium capability for. |
| 11535 | * |
| 11536 | * @return Whether the given premium capability is available to purchase. |
| 11537 | */ |
| 11538 | @Override |
| 11539 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11540 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11541 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11542 | log("Premium capability " |
| 11543 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11544 | + " is not available for purchase due to missing permissions."); |
| 11545 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11546 | + "permission READ_BASIC_PHONE_STATE."); |
| 11547 | } |
| 11548 | |
| 11549 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11550 | if (phone == null) { |
| 11551 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11552 | return false; |
| 11553 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11554 | final long identity = Binder.clearCallingIdentity(); |
| 11555 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 11556 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11557 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11558 | } finally { |
| 11559 | Binder.restoreCallingIdentity(identity); |
| 11560 | } |
| 11561 | } |
| 11562 | |
| 11563 | /** |
| 11564 | * Purchase the given premium capability from the carrier. |
| 11565 | * |
| 11566 | * @param capability The premium capability to purchase. |
| 11567 | * @param callback The result of the purchase request. |
| 11568 | * @param subId The subId to purchase the premium capability for. |
| 11569 | */ |
| 11570 | @Override |
| 11571 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11572 | log("purchasePremiumCapability: capability=" |
| 11573 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11574 | + getCurrentPackageName()); |
| 11575 | |
| 11576 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11577 | mApp, "purchasePremiumCapability")) { |
| 11578 | log("purchasePremiumCapability " |
| 11579 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11580 | + " failed due to missing permissions."); |
| 11581 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11582 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11583 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11584 | mApp, "purchasePremiumCapability")) { |
| 11585 | log("purchasePremiumCapability " |
| 11586 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11587 | + " failed due to missing permissions."); |
| 11588 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11589 | } |
| 11590 | |
| 11591 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11592 | if (phone == null) { |
| 11593 | try { |
| 11594 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11595 | callback.accept(result); |
| 11596 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11597 | } catch (RemoteException e) { |
| 11598 | String logStr = "Purchase premium capability " |
| 11599 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11600 | + " failed due to RemoteException handling null phone: " + e; |
| 11601 | if (DBG) log(logStr); |
| 11602 | AnomalyReporter.reportAnomaly( |
| 11603 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11604 | } |
| 11605 | return; |
| 11606 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11607 | |
| 11608 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11609 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11610 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11611 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11612 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11613 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11614 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11615 | |
| 11616 | boolean isVisible = false; |
| 11617 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11618 | if (am != null) { |
| 11619 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11620 | if (processes != null) { |
| 11621 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11622 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 11623 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11624 | if (process.processName.equals(callingProcess) && process.importance |
| 11625 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11626 | isVisible = true; |
| 11627 | break; |
| 11628 | } |
| 11629 | } |
| 11630 | } |
| 11631 | } |
| 11632 | |
| 11633 | if (!isVisible) { |
| 11634 | try { |
| 11635 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11636 | callback.accept(result); |
| 11637 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11638 | } catch (RemoteException e) { |
| 11639 | String logStr = "Purchase premium capability " |
| 11640 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11641 | + " failed due to RemoteException handling background application: " + e; |
| 11642 | if (DBG) log(logStr); |
| 11643 | AnomalyReporter.reportAnomaly( |
| 11644 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11645 | } |
| 11646 | return; |
| 11647 | } |
| 11648 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11649 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11650 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11651 | } |
| 11652 | |
| 11653 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11654 | * Register an IMS connection state callback |
| 11655 | */ |
| 11656 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11657 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11658 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11659 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11660 | // ImsMmTelManager |
| 11661 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11662 | TelephonyPermissions |
| 11663 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11664 | mApp, subId, "registerImsStateCallback"); |
| 11665 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11666 | // ImsRcsManager or SipDelegateManager |
| 11667 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11668 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11669 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11670 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11671 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11672 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11673 | } |
| 11674 | |
| 11675 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11676 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11677 | "IMS not available on device."); |
| 11678 | } |
| 11679 | |
| 11680 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11681 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11682 | } |
| 11683 | |
| 11684 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11685 | if (controller == null) { |
| 11686 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11687 | "IMS not available on device."); |
| 11688 | } |
| 11689 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11690 | if (callingPackage == null) { |
| 11691 | callingPackage = getCurrentPackageName(); |
| 11692 | } |
| 11693 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11694 | final long token = Binder.clearCallingIdentity(); |
| 11695 | try { |
| 11696 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11697 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11698 | } catch (ImsException e) { |
| 11699 | throw new ServiceSpecificException(e.getCode()); |
| 11700 | } finally { |
| 11701 | Binder.restoreCallingIdentity(token); |
| 11702 | } |
| 11703 | } |
| 11704 | |
| 11705 | /** |
| 11706 | * Unregister an IMS connection state callback |
| 11707 | */ |
| 11708 | @Override |
| 11709 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11710 | final long token = Binder.clearCallingIdentity(); |
| 11711 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11712 | if (controller == null) { |
| 11713 | return; |
| 11714 | } |
| 11715 | try { |
| 11716 | controller.unregisterImsStateCallback(cb); |
| 11717 | } finally { |
| 11718 | Binder.restoreCallingIdentity(token); |
| 11719 | } |
| 11720 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11721 | |
| 11722 | /** |
| 11723 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11724 | * |
| 11725 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame^] | 11726 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11727 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame^] | 11728 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11729 | * If there is current registered network this value will be same as the registered cell |
| 11730 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11731 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11732 | * it will be cleared and null will be returned. |
| 11733 | * |
| 11734 | */ |
| 11735 | @Override |
| 11736 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11737 | String callingFeatureId) { |
| 11738 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11739 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11740 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11741 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11742 | .setCallingPackage(callingPackage) |
| 11743 | .setCallingFeatureId(callingFeatureId) |
| 11744 | .setCallingPid(Binder.getCallingPid()) |
| 11745 | .setCallingUid(Binder.getCallingUid()) |
| 11746 | .setMethod("getLastKnownCellIdentity") |
| 11747 | .setLogAsInfo(true) |
| 11748 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11749 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11750 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11751 | .build()); |
| 11752 | |
| 11753 | boolean hasFinePermission = |
| 11754 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11755 | if (!hasFinePermission |
| 11756 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11757 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11758 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11759 | } |
| 11760 | |
| 11761 | final long identity = Binder.clearCallingIdentity(); |
| 11762 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11763 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11764 | if (sst == null) return null; |
| 11765 | return sst.getLastKnownCellIdentity(); |
| 11766 | } finally { |
| 11767 | Binder.restoreCallingIdentity(identity); |
| 11768 | } |
| 11769 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11770 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11771 | /** |
| 11772 | * Sets the modem service class Name that Telephony will bind to. |
| 11773 | * |
| 11774 | * @param serviceName The class name of the modem service. |
| 11775 | * @return true if the operation is succeed, otherwise false. |
| 11776 | */ |
| 11777 | public boolean setModemService(String serviceName) { |
| 11778 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11779 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11780 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11781 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11782 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11783 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11784 | } |
| 11785 | |
| 11786 | /** |
| 11787 | * Return the class name of the currently bounded modem service. |
| 11788 | * |
| 11789 | * @return the class name of the modem service. |
| 11790 | */ |
| 11791 | public String getModemService() { |
| 11792 | String result; |
| 11793 | Log.d(LOG_TAG, "getModemService"); |
| 11794 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11795 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11796 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11797 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11798 | "getModemService"); |
| 11799 | result = mPhoneConfigurationManager.getModemService(); |
| 11800 | Log.d(LOG_TAG, "result = " + result); |
| 11801 | return result; |
| 11802 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11803 | |
| 11804 | @Override |
| 11805 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11806 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11807 | mApp.enforceCallingOrSelfPermission( |
| 11808 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11809 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11810 | |
| 11811 | final long identity = Binder.clearCallingIdentity(); |
| 11812 | try { |
| 11813 | Phone phone = getPhone(subId); |
| 11814 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11815 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11816 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11817 | phone.setVoiceServiceStateOverride(hasService); |
| 11818 | } finally { |
| 11819 | Binder.restoreCallingIdentity(identity); |
| 11820 | } |
| 11821 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11822 | |
| 11823 | /** |
| 11824 | * set removable eSIM as default eUICC. |
| 11825 | * |
| 11826 | * @hide |
| 11827 | */ |
| 11828 | @Override |
| 11829 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11830 | enforceModifyPermission(); |
| 11831 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11832 | |
| 11833 | final long identity = Binder.clearCallingIdentity(); |
| 11834 | try { |
| 11835 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11836 | } finally { |
| 11837 | Binder.restoreCallingIdentity(identity); |
| 11838 | } |
| 11839 | } |
| 11840 | |
| 11841 | /** |
| 11842 | * Returns whether the removable eSIM is default eUICC or not. |
| 11843 | * |
| 11844 | * @hide |
| 11845 | */ |
| 11846 | @Override |
| 11847 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11848 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11849 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11850 | |
| 11851 | final long identity = Binder.clearCallingIdentity(); |
| 11852 | try { |
| 11853 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11854 | } finally { |
| 11855 | Binder.restoreCallingIdentity(identity); |
| 11856 | } |
| 11857 | } |
| 11858 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11859 | /** |
| 11860 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11861 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11862 | * application currently configured for this user. |
| 11863 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11864 | * {@code null} if the functionality is not supported. |
| 11865 | * @hide |
| 11866 | */ |
| 11867 | @Override |
| 11868 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11869 | boolean updateIfNeeded) { |
| 11870 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11871 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11872 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11873 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11874 | UserHandle userHandle = null; |
| 11875 | final long identity = Binder.clearCallingIdentity(); |
| 11876 | try { |
| 11877 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11878 | } finally { |
| 11879 | Binder.restoreCallingIdentity(identity); |
| 11880 | } |
| 11881 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11882 | updateIfNeeded, userHandle); |
| 11883 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11884 | |
| 11885 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11886 | * Set whether the device is able to connect with null ciphering or integrity |
| 11887 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11888 | * and all new subscriptions after this. |
| 11889 | * |
| 11890 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11891 | * @hide |
| 11892 | */ |
| 11893 | @Override |
| 11894 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11895 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11896 | enforceModifyPermission(); |
| 11897 | checkForNullCipherAndIntegritySupport(); |
| 11898 | |
| 11899 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11900 | // for listening to these preference changes and applying them immediately. |
| 11901 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11902 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11903 | editor.apply(); |
| 11904 | |
| 11905 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11906 | phone.handleNullCipherEnabledChange(); |
| 11907 | } |
| 11908 | } |
| 11909 | |
| 11910 | |
| 11911 | /** |
| 11912 | * Get whether the device is able to connect with null ciphering or integrity |
| 11913 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11914 | * the state of the radio. |
| 11915 | * |
| 11916 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11917 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11918 | * version for this feature. |
| 11919 | * @hide |
| 11920 | */ |
| 11921 | @Override |
| 11922 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11923 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11924 | enforceReadPermission(); |
| 11925 | checkForNullCipherAndIntegritySupport(); |
| 11926 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11927 | } |
| 11928 | |
| 11929 | private void checkForNullCipherAndIntegritySupport() { |
| 11930 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11931 | throw new UnsupportedOperationException( |
| 11932 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11933 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11934 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11935 | throw new UnsupportedOperationException( |
| 11936 | "Null cipher and integrity operations unsupported by modem"); |
| 11937 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11938 | } |
| 11939 | |
| 11940 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11941 | * Get the SIM state for the slot index. |
| 11942 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11943 | * |
| 11944 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11945 | */ |
| 11946 | @Override |
| 11947 | @SimState |
| 11948 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11949 | IccCardConstants.State simState; |
| 11950 | if (slotIndex < 0) { |
| 11951 | simState = IccCardConstants.State.UNKNOWN; |
| 11952 | } else { |
| 11953 | Phone phone = null; |
| 11954 | try { |
| 11955 | phone = PhoneFactory.getPhone(slotIndex); |
| 11956 | } catch (IllegalStateException e) { |
| 11957 | // ignore |
| 11958 | } |
| 11959 | if (phone == null) { |
| 11960 | simState = IccCardConstants.State.UNKNOWN; |
| 11961 | } else { |
| 11962 | IccCard icc = phone.getIccCard(); |
| 11963 | if (icc == null) { |
| 11964 | simState = IccCardConstants.State.UNKNOWN; |
| 11965 | } else { |
| 11966 | simState = icc.getState(); |
| 11967 | } |
| 11968 | } |
| 11969 | } |
| 11970 | return simState.ordinal(); |
| 11971 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11972 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 11973 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 11974 | boolean enableLogcat, |
| 11975 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 11976 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 11977 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 11978 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 11979 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 11980 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 11981 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 11982 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 11983 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 11984 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 11985 | Executors.newCachedThreadPool(), db, |
| 11986 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 11987 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 11988 | } |
| 11989 | |
| 11990 | /** |
| 11991 | * Request telephony to persist state for debugging emergency call failures. |
| 11992 | * |
| 11993 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 11994 | * @param enableLogcat whether to collect logcat output |
| 11995 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 11996 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 11997 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 11998 | */ |
| 11999 | @Override |
| 12000 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12001 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12002 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12003 | boolean enableTelephonyDump) { |
| 12004 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12005 | "persistEmergencyCallDiagnosticData"); |
| 12006 | final long identity = Binder.clearCallingIdentity(); |
| 12007 | try { |
| 12008 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12009 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12010 | |
| 12011 | } finally { |
| 12012 | Binder.restoreCallingIdentity(identity); |
| 12013 | } |
| 12014 | } |
| 12015 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12016 | /** |
| 12017 | * Get current cell broadcast ranges. |
| 12018 | */ |
| 12019 | @Override |
| 12020 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12021 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12022 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12023 | "getCellBroadcastIdRanges"); |
| 12024 | final long identity = Binder.clearCallingIdentity(); |
| 12025 | try { |
| 12026 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12027 | } finally { |
| 12028 | Binder.restoreCallingIdentity(identity); |
| 12029 | } |
| 12030 | } |
| 12031 | |
| 12032 | /** |
| 12033 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12034 | * |
| 12035 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12036 | */ |
| 12037 | @Override |
| 12038 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12039 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12040 | @Nullable IIntegerConsumer callback) { |
| 12041 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12042 | "setCellBroadcastIdRanges"); |
| 12043 | final long identity = Binder.clearCallingIdentity(); |
| 12044 | try { |
| 12045 | Phone phone = getPhoneFromSubId(subId); |
| 12046 | if (DBG) { |
| 12047 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12048 | } |
| 12049 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12050 | if (callback != null) { |
| 12051 | try { |
| 12052 | callback.accept(result); |
| 12053 | } catch (RemoteException e) { |
| 12054 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12055 | } |
| 12056 | } |
| 12057 | }); |
| 12058 | } finally { |
| 12059 | Binder.restoreCallingIdentity(identity); |
| 12060 | } |
| 12061 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12062 | |
| 12063 | /** |
| 12064 | * Returns whether the device supports the domain selection service. |
| 12065 | * |
| 12066 | * @return {@code true} if the device supports the domain selection service. |
| 12067 | */ |
| 12068 | @Override |
| 12069 | public boolean isDomainSelectionSupported() { |
| 12070 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12071 | "isDomainSelectionSupported"); |
| 12072 | |
| 12073 | final long identity = Binder.clearCallingIdentity(); |
| 12074 | try { |
| 12075 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12076 | } finally { |
| 12077 | Binder.restoreCallingIdentity(identity); |
| 12078 | } |
| 12079 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12080 | |
| 12081 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12082 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12083 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12084 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12085 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12086 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12087 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12088 | * {@code false} to disable. |
| 12089 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12090 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12091 | * |
| 12092 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12093 | */ |
| 12094 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12095 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12096 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12097 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12098 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12099 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12100 | } |
| 12101 | |
| 12102 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12103 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12104 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12105 | * @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] | 12106 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12107 | * 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] | 12108 | * |
| 12109 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12110 | */ |
| 12111 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12112 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12113 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12114 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12115 | } |
| 12116 | |
| 12117 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12118 | * Request to get whether the satellite service demo mode is enabled. |
| 12119 | * |
| 12120 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12121 | * is enabled for. |
| 12122 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12123 | * if the request is successful or an error code if the request failed. |
| 12124 | * |
| 12125 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12126 | */ |
| 12127 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12128 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12129 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12130 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12131 | } |
| 12132 | |
| 12133 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12134 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12135 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12136 | * @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] | 12137 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12138 | * 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] | 12139 | */ |
| 12140 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12141 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12142 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12143 | } |
| 12144 | |
| 12145 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12146 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12147 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12148 | * @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] | 12149 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12150 | * 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] | 12151 | * |
| 12152 | * @throws SecurityException if the caller doesn't have required permission. |
| 12153 | */ |
| 12154 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12155 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12156 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12157 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12158 | } |
| 12159 | |
| 12160 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12161 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12162 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12163 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12164 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12165 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12166 | * @param resultCallback The callback to get the result of the request. |
| 12167 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12168 | * |
| 12169 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12170 | */ |
| 12171 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12172 | public void startSatelliteTransmissionUpdates(int subId, |
| 12173 | @NonNull IIntegerConsumer resultCallback, |
| 12174 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12175 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12176 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12177 | } |
| 12178 | |
| 12179 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12180 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12181 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12182 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12183 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12184 | * @param resultCallback The callback to get the result of the request. |
| 12185 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12186 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12187 | * |
| 12188 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12189 | */ |
| 12190 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12191 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12192 | @NonNull IIntegerConsumer resultCallback, |
| 12193 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12194 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12195 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12196 | } |
| 12197 | |
| 12198 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12199 | * Register the subscription with a satellite provider. |
| 12200 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12201 | * |
| 12202 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12203 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12204 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12205 | * @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] | 12206 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12207 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12208 | * @return The signal transport used by the caller to cancel the provision request, |
| 12209 | * or {@code null} if the request failed. |
| 12210 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12211 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12212 | */ |
| 12213 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12214 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12215 | @NonNull String token, @NonNull byte[] provisionData, |
| 12216 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12217 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12218 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 12219 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12220 | } |
| 12221 | |
| 12222 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12223 | * Unregister the device/subscription with the satellite provider. |
| 12224 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12225 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12226 | * should report as deprovisioned. |
| 12227 | * |
| 12228 | * @param subId The subId of the subscription to be deprovisioned. |
| 12229 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12230 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12231 | * |
| 12232 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12233 | */ |
| 12234 | @Override |
| 12235 | public void deprovisionSatelliteService(int subId, |
| 12236 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12237 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12238 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12239 | } |
| 12240 | |
| 12241 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12242 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12243 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12244 | * @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] | 12245 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12246 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12247 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12248 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12249 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12250 | */ |
| 12251 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12252 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 12253 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12254 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12255 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12256 | } |
| 12257 | |
| 12258 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12259 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12260 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12261 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12262 | * @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] | 12263 | * @param callback The callback that was passed to |
| 12264 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12265 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12266 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12267 | */ |
| 12268 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12269 | public void unregisterForSatelliteProvisionStateChanged( |
| 12270 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12271 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12272 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12273 | } |
| 12274 | |
| 12275 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12276 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12277 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12278 | * @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] | 12279 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12280 | * satellite provider if the request is successful or an error code if the |
| 12281 | * request failed. |
| 12282 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12283 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12284 | */ |
| 12285 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12286 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12287 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12288 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12289 | } |
| 12290 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12291 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12292 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12293 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12294 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12295 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12296 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12297 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12298 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12299 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12300 | */ |
| 12301 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12302 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12303 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12304 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12305 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12306 | } |
| 12307 | |
| 12308 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12309 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12310 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12311 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12312 | * @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] | 12313 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12314 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12315 | * |
| 12316 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12317 | */ |
| 12318 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12319 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12320 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12321 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12322 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12323 | } |
| 12324 | |
| 12325 | /** |
| 12326 | * Register to receive incoming datagrams over satellite. |
| 12327 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12328 | * @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] | 12329 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12330 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12331 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12332 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12333 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12334 | */ |
| 12335 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12336 | @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12337 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12338 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12339 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12340 | } |
| 12341 | |
| 12342 | /** |
| 12343 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12344 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12345 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12346 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12347 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12348 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12349 | * |
| 12350 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12351 | */ |
| 12352 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12353 | public void unregisterForSatelliteDatagram(int subId, |
| 12354 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12355 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12356 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12357 | } |
| 12358 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12359 | /** |
| 12360 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12361 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12362 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12363 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 12364 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12365 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12366 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12367 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12368 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12369 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12370 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12371 | @Override |
| 12372 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12373 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12374 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12375 | } |
| 12376 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12377 | /** |
| 12378 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12379 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12380 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 12381 | * input to this method. Datagram received here will be passed down to modem without any |
| 12382 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12383 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12384 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 12385 | * @param datagramType datagram type indicating whether the datagram is of type |
| 12386 | * SOS_SMS or LOCATION_SHARING. |
| 12387 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 12388 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12389 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 12390 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12391 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12392 | * |
| 12393 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12394 | */ |
| 12395 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12396 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 12397 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 12398 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12399 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12400 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 12401 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12402 | } |
| 12403 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12404 | /** |
| 12405 | * Request to get whether satellite communication is allowed for the current location. |
| 12406 | * |
| 12407 | * @param subId The subId of the subscription to check whether satellite communication is |
| 12408 | * allowed for the current location for. |
| 12409 | * @param result The result receiver that returns whether satellite communication is allowed |
| 12410 | * for the current location if the request is successful or an error code |
| 12411 | * if the request failed. |
| 12412 | * |
| 12413 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12414 | */ |
| 12415 | @Override |
| 12416 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 12417 | @NonNull ResultReceiver result) { |
| 12418 | enforceSatelliteCommunicationPermission( |
| 12419 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12420 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 12421 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12422 | } |
| 12423 | |
| 12424 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12425 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12426 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12427 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12428 | * @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] | 12429 | * be visible if the request is successful or an error code if the request failed. |
| 12430 | * |
| 12431 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12432 | */ |
| 12433 | @Override |
| 12434 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 12435 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12436 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12437 | } |
| 12438 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12439 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12440 | * Inform that Device is aligned to satellite for demo mode. |
| 12441 | * |
| 12442 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12443 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 12444 | * {@code false} Device fails to align with the satellite for demo mode. |
| 12445 | * |
| 12446 | * @throws SecurityException if the caller doesn't have required permission. |
| 12447 | */ |
| 12448 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 12449 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12450 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12451 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12452 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12453 | } |
| 12454 | |
| 12455 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 12456 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12457 | * by modem. |
| 12458 | * |
| 12459 | * @param subId The subId of the subscription to request for. |
| 12460 | * @param reason Reason for disallowing satellite communication for carrier. |
| 12461 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12462 | * operation. |
| 12463 | * |
| 12464 | * @throws SecurityException if the caller doesn't have required permission. |
| 12465 | */ |
| 12466 | public void addSatelliteAttachRestrictionForCarrier(int subId, |
| 12467 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12468 | @NonNull IIntegerConsumer callback) { |
| 12469 | enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier"); |
| 12470 | final long identity = Binder.clearCallingIdentity(); |
| 12471 | try { |
| 12472 | mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback); |
| 12473 | } finally { |
| 12474 | Binder.restoreCallingIdentity(identity); |
| 12475 | } |
| 12476 | } |
| 12477 | |
| 12478 | /** |
| 12479 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12480 | * by modem. |
| 12481 | * |
| 12482 | * @param subId The subId of the subscription to request for. |
| 12483 | * @param reason Reason for disallowing satellite communication. |
| 12484 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12485 | * operation. |
| 12486 | * |
| 12487 | * @throws SecurityException if the caller doesn't have required permission. |
| 12488 | */ |
| 12489 | public void removeSatelliteAttachRestrictionForCarrier(int subId, |
| 12490 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12491 | @NonNull IIntegerConsumer callback) { |
| 12492 | enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier"); |
| 12493 | final long identity = Binder.clearCallingIdentity(); |
| 12494 | try { |
| 12495 | mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason, |
| 12496 | callback); |
| 12497 | } finally { |
| 12498 | Binder.restoreCallingIdentity(identity); |
| 12499 | } |
| 12500 | } |
| 12501 | |
| 12502 | /** |
| 12503 | * Get reasons for disallowing satellite communication, as requested by |
| 12504 | * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
| 12505 | * |
| 12506 | * @param subId The subId of the subscription to request for. |
| 12507 | * |
| 12508 | * @return Integer array of reasons for disallowing satellite communication. |
| 12509 | * |
| 12510 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12511 | */ |
| 12512 | public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier( |
| 12513 | int subId) { |
| 12514 | enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier"); |
| 12515 | final long identity = Binder.clearCallingIdentity(); |
| 12516 | try { |
| 12517 | Set<Integer> reasonSet = |
| 12518 | mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId); |
| 12519 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 12520 | } finally { |
| 12521 | Binder.restoreCallingIdentity(identity); |
| 12522 | } |
| 12523 | } |
| 12524 | |
| 12525 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12526 | * Request to get the signal strength of the satellite connection. |
| 12527 | * |
| 12528 | * @param subId The subId of the subscription to request for. |
| 12529 | * @param result Result receiver to get the error code of the request and the current signal |
| 12530 | * strength of the satellite connection. |
| 12531 | * |
| 12532 | * @throws SecurityException if the caller doesn't have required permission. |
| 12533 | */ |
| 12534 | @Override |
| 12535 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 12536 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 12537 | final long identity = Binder.clearCallingIdentity(); |
| 12538 | try { |
| 12539 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 12540 | } finally { |
| 12541 | Binder.restoreCallingIdentity(identity); |
| 12542 | } |
| 12543 | } |
| 12544 | |
| 12545 | /** |
| 12546 | * Registers for NTN signal strength changed from satellite modem. |
| 12547 | * |
| 12548 | * @param subId The subId of the subscription to request for. |
| 12549 | * @param callback The callback to handle the NTN signal strength changed event. |
| 12550 | * |
| 12551 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 12552 | * |
| 12553 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12554 | */ |
| 12555 | @Override |
| 12556 | @SatelliteManager.SatelliteResult public int registerForNtnSignalStrengthChanged( |
| 12557 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 12558 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 12559 | final long identity = Binder.clearCallingIdentity(); |
| 12560 | try { |
| 12561 | return mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
| 12562 | } finally { |
| 12563 | Binder.restoreCallingIdentity(identity); |
| 12564 | } |
| 12565 | } |
| 12566 | |
| 12567 | /** |
| 12568 | * Unregisters for NTN signal strength changed from satellite modem. |
| 12569 | * If callback was not registered before, the request will be ignored. |
| 12570 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12571 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 12572 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12573 | * @param callback The callback that was passed to |
| 12574 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 12575 | * |
| 12576 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12577 | */ |
| 12578 | @Override |
| 12579 | public void unregisterForNtnSignalStrengthChanged( |
| 12580 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 12581 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 12582 | final long identity = Binder.clearCallingIdentity(); |
| 12583 | try { |
| 12584 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 12585 | } finally { |
| 12586 | Binder.restoreCallingIdentity(identity); |
| 12587 | } |
| 12588 | } |
| 12589 | |
| 12590 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12591 | * Registers for satellite capabilities change event from the satellite service. |
| 12592 | * |
| 12593 | * @param subId The subId of the subscription to request for. |
| 12594 | * @param callback The callback to handle the satellite capabilities changed event. |
| 12595 | * |
| 12596 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 12597 | * |
| 12598 | * @throws SecurityException if the caller doesn't have required permission. |
| 12599 | */ |
| 12600 | @Override |
| 12601 | @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged( |
| 12602 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12603 | enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged"); |
| 12604 | final long identity = Binder.clearCallingIdentity(); |
| 12605 | try { |
| 12606 | return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback); |
| 12607 | } finally { |
| 12608 | Binder.restoreCallingIdentity(identity); |
| 12609 | } |
| 12610 | } |
| 12611 | |
| 12612 | /** |
| 12613 | * Unregisters for satellite capabilities change event from the satellite service. |
| 12614 | * If callback was not registered before, the request will be ignored. |
| 12615 | * |
| 12616 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 12617 | * @param callback The callback that was passed to. |
| 12618 | * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
| 12619 | * |
| 12620 | * @throws SecurityException if the caller doesn't have required permission. |
| 12621 | */ |
| 12622 | @Override |
| 12623 | public void unregisterForSatelliteCapabilitiesChanged( |
| 12624 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12625 | enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged"); |
| 12626 | final long identity = Binder.clearCallingIdentity(); |
| 12627 | try { |
| 12628 | mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback); |
| 12629 | } finally { |
| 12630 | Binder.restoreCallingIdentity(identity); |
| 12631 | } |
| 12632 | } |
| 12633 | |
| 12634 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 12635 | * This API can be used by only CTS to update satellite vendor service package name. |
| 12636 | * |
| 12637 | * @param servicePackageName The package name of the satellite vendor service. |
| 12638 | * @return {@code true} if the satellite vendor service is set successfully, |
| 12639 | * {@code false} otherwise. |
| 12640 | */ |
| 12641 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 12642 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 12643 | TelephonyPermissions.enforceShellOnly( |
| 12644 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 12645 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12646 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12647 | "setSatelliteServicePackageName"); |
| 12648 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 12649 | } |
| 12650 | |
| 12651 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 12652 | * This API can be used by only CTS to update satellite gateway service package name. |
| 12653 | * |
| 12654 | * @param servicePackageName The package name of the satellite gateway service. |
| 12655 | * @return {@code true} if the satellite gateway service is set successfully, |
| 12656 | * {@code false} otherwise. |
| 12657 | */ |
| 12658 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 12659 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 12660 | TelephonyPermissions.enforceShellOnly( |
| 12661 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 12662 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12663 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12664 | "setSatelliteGatewayServicePackageName"); |
| 12665 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 12666 | } |
| 12667 | |
| 12668 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 12669 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 12670 | * |
| 12671 | * @param packageName The package name of the satellite pointing UI app. |
| 12672 | * @param className The class name of the satellite pointing UI app. |
| 12673 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 12674 | * {@code false} otherwise. |
| 12675 | */ |
| 12676 | public boolean setSatellitePointingUiClassName( |
| 12677 | @Nullable String packageName, @Nullable String className) { |
| 12678 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 12679 | + ", className=" + className); |
| 12680 | TelephonyPermissions.enforceShellOnly( |
| 12681 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 12682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12683 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12684 | "setSatelliteGatewayServicePackageName"); |
| 12685 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 12686 | } |
| 12687 | |
| 12688 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 12689 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 12690 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 12691 | * listening mode. |
| 12692 | * |
| 12693 | * @param timeoutMillis The timeout duration in millisecond. |
| 12694 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12695 | */ |
| 12696 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 12697 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 12698 | TelephonyPermissions.enforceShellOnly( |
| 12699 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 12700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12701 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12702 | "setSatelliteListeningTimeoutDuration"); |
| 12703 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 12704 | } |
| 12705 | |
| 12706 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12707 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 12708 | * the device is aligned with the satellite for demo mode |
| 12709 | * |
| 12710 | * @param timeoutMillis The timeout duration in millisecond. |
| 12711 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12712 | */ |
| 12713 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 12714 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 12715 | TelephonyPermissions.enforceShellOnly( |
| 12716 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 12717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12718 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12719 | "setDeviceAlignedTimeoutDuration"); |
| 12720 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 12721 | } |
| 12722 | |
| 12723 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 12724 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 12725 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 12726 | * |
| 12727 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 12728 | * of the following values to enable the override: |
| 12729 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 12730 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 12731 | * To disable the override, use -1 for handoverType. |
| 12732 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 12733 | * delaySeconds after the emergency call starts. |
| 12734 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 12735 | */ |
| 12736 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 12737 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 12738 | TelephonyPermissions.enforceShellOnly( |
| 12739 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 12740 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12741 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12742 | "setEmergencyCallToSatelliteHandoverType"); |
| 12743 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 12744 | handoverType, delaySeconds); |
| 12745 | } |
| 12746 | |
| 12747 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 12748 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 12749 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 12750 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 12751 | * |
| 12752 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 12753 | * satellite modem or not. |
| 12754 | * |
| 12755 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 12756 | */ |
| 12757 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 12758 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 12759 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 12760 | + "disabled"); |
| 12761 | return false; |
| 12762 | } |
| 12763 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 12764 | TelephonyPermissions.enforceShellOnly( |
| 12765 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 12766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12767 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12768 | "setShouldSendDatagramToModemInDemoMode"); |
| 12769 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 12770 | shouldSendToModemInDemoMode); |
| 12771 | } |
| 12772 | |
| 12773 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12774 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12775 | * |
| 12776 | * <p>This method behaves in one of the following ways: |
| 12777 | * <ul> |
| 12778 | * <li>return true : if the calling package has the appop permission {@link |
| 12779 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12780 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12781 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12782 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12783 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12784 | * </ul> |
| 12785 | */ |
| 12786 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12787 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12788 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12789 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12790 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12791 | return true; |
| 12792 | } |
| 12793 | } |
| 12794 | return false; |
| 12795 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12796 | |
| 12797 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12798 | * @return The subscription manager service instance. |
| 12799 | */ |
| 12800 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12801 | return SubscriptionManagerService.getInstance(); |
| 12802 | } |
| 12803 | |
| 12804 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12805 | * Class binds the consumer[callback] and carrierId. |
| 12806 | */ |
| 12807 | private static class CallerCallbackInfo { |
| 12808 | private final Consumer<Integer> mConsumer; |
| 12809 | private final int mCarrierId; |
| 12810 | |
| 12811 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12812 | mConsumer = consumer; |
| 12813 | mCarrierId = carrierId; |
| 12814 | } |
| 12815 | |
| 12816 | public Consumer<Integer> getConsumer() { |
| 12817 | return mConsumer; |
| 12818 | } |
| 12819 | |
| 12820 | public int getCarrierId() { |
| 12821 | return mCarrierId; |
| 12822 | } |
| 12823 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12824 | } |