Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 20 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 22 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 23 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 27 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 28 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 29 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 30 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 32 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 33 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 34 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 35 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 37 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 38 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 39 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 40 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 41 | import android.compat.annotation.ChangeId; |
| 42 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 43 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 44 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 45 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.content.Context; |
| 47 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 48 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 49 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 50 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.net.Uri; |
| 52 | import android.os.AsyncResult; |
| 53 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 54 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 56 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 58 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 59 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 60 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.os.Looper; |
| 62 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 63 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 64 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 65 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 66 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 67 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 68 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 69 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 70 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 71 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 73 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 74 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 75 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 76 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 77 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 78 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 79 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 80 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 81 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 82 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 83 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 84 | import android.telephony.AccessNetworkConstants; |
| 85 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 86 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 87 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 88 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 89 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 90 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 91 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 92 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 93 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 94 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 95 | import android.telephony.CellIdentityCdma; |
| 96 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 97 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 98 | import android.telephony.CellInfoGsm; |
| 99 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 100 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 101 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 102 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 103 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 104 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 105 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 106 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 107 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 108 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 109 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 110 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 111 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 112 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 114 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 115 | import android.telephony.SignalStrengthUpdateRequest; |
| 116 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 117 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 118 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 119 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 120 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 121 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 122 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 123 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 124 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 125 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 126 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 127 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 128 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 129 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 130 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 131 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 132 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 133 | import android.telephony.gba.GbaAuthRequest; |
| 134 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 135 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 136 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 137 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 138 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 139 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 145 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 146 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 147 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 148 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 149 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 150 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 151 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 152 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 153 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 154 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame^] | 156 | import android.telephony.satellite.NtnSignalStrength; |
| 157 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 158 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 159 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 160 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 162 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 163 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 164 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 165 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 167 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 168 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 169 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 170 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 171 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 172 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 187 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 204 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 207 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.SmsPermissions; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 210 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 213 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 217 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 219 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 220 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 222 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 224 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 225 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.IccIoResult; |
| 227 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 229 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 230 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 231 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 232 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 233 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 234 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 235 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 236 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 237 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 238 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 239 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 240 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 241 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 242 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 243 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 244 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 245 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 246 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 247 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 248 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 249 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 250 | import com.android.services.telephony.TelecomAccountRegistry; |
| 251 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 252 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 253 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 254 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 255 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 256 | import java.io.IOException; |
| 257 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 258 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 259 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 260 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 261 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 262 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 263 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 264 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 265 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 266 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 267 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 268 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 269 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 270 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 271 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 272 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 273 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 274 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | |
| 276 | /** |
| 277 | * Implementation of the ITelephony interface. |
| 278 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 279 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 280 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 281 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 282 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 283 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 284 | |
| 285 | // Message codes used with mMainThreadHandler |
| 286 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 287 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 288 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 289 | private static final int CMD_OPEN_CHANNEL = 9; |
| 290 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 291 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 292 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 293 | private static final int CMD_NV_READ_ITEM = 13; |
| 294 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 295 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 296 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 297 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 298 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 299 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 300 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 301 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 302 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 303 | private static final int CMD_SEND_ENVELOPE = 25; |
| 304 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 305 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 306 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 307 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 308 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 309 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 310 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 311 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 312 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 313 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 314 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 315 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 316 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 317 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 318 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 319 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 320 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 321 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 322 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 323 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 324 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 325 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 326 | private static final int CMD_SWITCH_SLOTS = 50; |
| 327 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 329 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 330 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 331 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 332 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 333 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 334 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 335 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 336 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 337 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 338 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 339 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 340 | private static final int CMD_MODEM_REBOOT = 64; |
| 341 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 342 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 343 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 344 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 345 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 346 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 347 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 348 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 349 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 350 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 351 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 352 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 353 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 354 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 355 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 356 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 357 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 358 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 359 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 360 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 361 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 362 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 363 | private static final int CMD_GET_CALL_WAITING = 87; |
| 364 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 365 | private static final int CMD_SET_CALL_WAITING = 89; |
| 366 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 367 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 368 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 369 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 370 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 371 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 372 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 373 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 374 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 375 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 376 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 377 | private static final int CMD_SET_SIM_POWER = 101; |
| 378 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 379 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 380 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 381 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 382 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 383 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 384 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 385 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 386 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 387 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 388 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 389 | private static final int CMD_ENABLE_VONR = 113; |
| 390 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 391 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 392 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 393 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 394 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 395 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 396 | // Parameters of select command. |
| 397 | private static final int SELECT_COMMAND = 0xA4; |
| 398 | private static final int SELECT_P1 = 0x04; |
| 399 | private static final int SELECT_P2 = 0; |
| 400 | private static final int SELECT_P3 = 0x10; |
| 401 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 402 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 403 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 404 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | /** The singleton instance. */ |
| 406 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 407 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 408 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 409 | private final PhoneGlobals mApp; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 410 | private final FeatureFlags mFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 411 | private final CallManager mCM; |
| 412 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 413 | |
| 414 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 415 | private final UserManager mUserManager; |
| 416 | private final AppOpsManager mAppOps; |
| 417 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 418 | private final SharedPreferences mTelephonySharedPreferences; |
| 419 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 420 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 422 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 423 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 424 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 425 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 426 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 427 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 428 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 429 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 430 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 431 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 432 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 433 | // String to store multi SIM allowed |
| 434 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 435 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 436 | // The AID of ISD-R. |
| 437 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 438 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 439 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 440 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 441 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 442 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 443 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 444 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 445 | 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] | 446 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 447 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 448 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 449 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 450 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 451 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 452 | */ |
| 453 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 454 | "reset_network_erase_modem_config_enabled"; |
| 455 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 456 | 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] | 457 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 458 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 459 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 460 | /** |
| 461 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 462 | * one ICCID active at the same time. |
| 463 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 464 | * |
| 465 | * @hide |
| 466 | */ |
| 467 | @ChangeId |
| 468 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 469 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 470 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 471 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 472 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 473 | * operation fails. |
| 474 | */ |
| 475 | @ChangeId |
| 476 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 477 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 478 | |
| 479 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 480 | * A request object to use for transmitting data to an ICC. |
| 481 | */ |
| 482 | private static final class IccAPDUArgument { |
| 483 | public int channel, cla, command, p1, p2, p3; |
| 484 | public String data; |
| 485 | |
| 486 | public IccAPDUArgument(int channel, int cla, int command, |
| 487 | int p1, int p2, int p3, String data) { |
| 488 | this.channel = channel; |
| 489 | this.cla = cla; |
| 490 | this.command = command; |
| 491 | this.p1 = p1; |
| 492 | this.p2 = p2; |
| 493 | this.p3 = p3; |
| 494 | this.data = data; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 499 | * A request object to use for transmitting data to an ICC. |
| 500 | */ |
| 501 | private static final class ManualNetworkSelectionArgument { |
| 502 | public OperatorInfo operatorInfo; |
| 503 | public boolean persistSelection; |
| 504 | |
| 505 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 506 | this.operatorInfo = operatorInfo; |
| 507 | this.persistSelection = persistSelection; |
| 508 | } |
| 509 | } |
| 510 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 511 | private static final class PurchasePremiumCapabilityArgument { |
| 512 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 513 | public @NonNull IIntegerConsumer callback; |
| 514 | |
| 515 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 516 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 517 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 518 | this.callback = callback; |
| 519 | } |
| 520 | } |
| 521 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 522 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 523 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 524 | * request after sending. The main thread will notify the request when it is complete. |
| 525 | */ |
| 526 | private static final class MainThreadRequest { |
| 527 | /** The argument to use for the request */ |
| 528 | public Object argument; |
| 529 | /** The result of the request that is run on the main thread */ |
| 530 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 531 | // The subscriber id that this request applies to. Defaults to |
| 532 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 533 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 534 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 535 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 536 | public Phone phone; |
| 537 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 538 | public WorkSource workSource; |
| 539 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 540 | public MainThreadRequest(Object argument) { |
| 541 | this.argument = argument; |
| 542 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 543 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 544 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 545 | this.argument = argument; |
| 546 | if (phone != null) { |
| 547 | this.phone = phone; |
| 548 | } |
| 549 | this.workSource = workSource; |
| 550 | } |
| 551 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 552 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 553 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 554 | if (subId != null) { |
| 555 | this.subId = subId; |
| 556 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 557 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 558 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 561 | private static final class IncomingThirdPartyCallArgs { |
| 562 | public final ComponentName component; |
| 563 | public final String callId; |
| 564 | public final String callerDisplayName; |
| 565 | |
| 566 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 567 | String callerDisplayName) { |
| 568 | this.component = component; |
| 569 | this.callId = callId; |
| 570 | this.callerDisplayName = callerDisplayName; |
| 571 | } |
| 572 | } |
| 573 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 574 | /** |
| 575 | * A handler that processes messages on the main thread in the phone process. Since many |
| 576 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 577 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 578 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 579 | * on, which will be notified when the operation completes and will contain the result of the |
| 580 | * request. |
| 581 | * |
| 582 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 583 | * note that request.result must be set to something non-null for the calling thread to |
| 584 | * unblock. |
| 585 | */ |
| 586 | private final class MainThreadHandler extends Handler { |
| 587 | @Override |
| 588 | public void handleMessage(Message msg) { |
| 589 | MainThreadRequest request; |
| 590 | Message onCompleted; |
| 591 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 592 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 594 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 595 | |
| 596 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 597 | case CMD_HANDLE_USSD_REQUEST: { |
| 598 | request = (MainThreadRequest) msg.obj; |
| 599 | final Phone phone = getPhoneFromRequest(request); |
| 600 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 601 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 603 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 604 | if (!isUssdApiAllowed(request.subId)) { |
| 605 | // Carrier does not support use of this API, return failure. |
| 606 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 607 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 608 | Bundle returnData = new Bundle(); |
| 609 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 610 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 611 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 612 | request.result = true; |
| 613 | notifyRequester(request); |
| 614 | return; |
| 615 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 616 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | try { |
| 618 | request.result = phone != null |
| 619 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 620 | } catch (CallStateException cse) { |
| 621 | request.result = false; |
| 622 | } |
| 623 | // Wake up the requesting thread |
| 624 | notifyRequester(request); |
| 625 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 628 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 629 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 630 | final Phone phone = getPhoneFromRequest(request); |
| 631 | request.result = phone != null ? |
| 632 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 633 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 634 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 635 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 636 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 637 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 638 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 641 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 642 | uiccPort = getUiccPortFromRequest(request); |
| 643 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 644 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 645 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 646 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 647 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 648 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 649 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 650 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 651 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 652 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 653 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 654 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | break; |
| 656 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 657 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 658 | ar = (AsyncResult) msg.obj; |
| 659 | request = (MainThreadRequest) ar.userObj; |
| 660 | if (ar.exception == null && ar.result != null) { |
| 661 | request.result = ar.result; |
| 662 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 663 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | if (ar.result == null) { |
| 665 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | } else { |
| 670 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 671 | } |
| 672 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | break; |
| 675 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 676 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 677 | request = (MainThreadRequest) msg.obj; |
| 678 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 679 | uiccPort = getUiccPortFromRequest(request); |
| 680 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 683 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | } else { |
| 685 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 686 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 687 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 688 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 689 | iccArgument.p2, |
| 690 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | } |
| 692 | break; |
| 693 | |
| 694 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 695 | ar = (AsyncResult) msg.obj; |
| 696 | request = (MainThreadRequest) ar.userObj; |
| 697 | if (ar.exception == null && ar.result != null) { |
| 698 | request.result = ar.result; |
| 699 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 700 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 701 | if (ar.result == null) { |
| 702 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 703 | } else if (ar.exception instanceof CommandException) { |
| 704 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 705 | ar.exception); |
| 706 | } else { |
| 707 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 708 | } |
| 709 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 710 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 711 | break; |
| 712 | |
| 713 | case CMD_EXCHANGE_SIM_IO: |
| 714 | request = (MainThreadRequest) msg.obj; |
| 715 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 716 | uiccPort = getUiccPortFromRequest(request); |
| 717 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 718 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 719 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 720 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 721 | } else { |
| 722 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 723 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 724 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 725 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 726 | iccArgument.data, onCompleted); |
| 727 | } |
| 728 | break; |
| 729 | |
| 730 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 731 | ar = (AsyncResult) msg.obj; |
| 732 | request = (MainThreadRequest) ar.userObj; |
| 733 | if (ar.exception == null && ar.result != null) { |
| 734 | request.result = ar.result; |
| 735 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 736 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 737 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 738 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 739 | break; |
| 740 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 741 | case CMD_SEND_ENVELOPE: |
| 742 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 743 | uiccPort = getUiccPortFromRequest(request); |
| 744 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 745 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 746 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 747 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 748 | } else { |
| 749 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 750 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 751 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 752 | break; |
| 753 | |
| 754 | case EVENT_SEND_ENVELOPE_DONE: |
| 755 | ar = (AsyncResult) msg.obj; |
| 756 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 757 | if (ar.exception == null && ar.result != null) { |
| 758 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 759 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 760 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 761 | if (ar.result == null) { |
| 762 | loge("sendEnvelopeWithStatus: Empty response"); |
| 763 | } else if (ar.exception instanceof CommandException) { |
| 764 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 765 | ar.exception); |
| 766 | } else { |
| 767 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 768 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 769 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 770 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 771 | break; |
| 772 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 773 | case CMD_OPEN_CHANNEL: |
| 774 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 775 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 776 | IccLogicalChannelRequest openChannelRequest = |
| 777 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 778 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 779 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 780 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 781 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 782 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 783 | } else { |
| 784 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 785 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 786 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 787 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 788 | break; |
| 789 | |
| 790 | case EVENT_OPEN_CHANNEL_DONE: |
| 791 | ar = (AsyncResult) msg.obj; |
| 792 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 793 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 794 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 795 | int[] result = (int[]) ar.result; |
| 796 | int channelId = result[0]; |
| 797 | byte[] selectResponse = null; |
| 798 | if (result.length > 1) { |
| 799 | selectResponse = new byte[result.length - 1]; |
| 800 | for (int i = 1; i < result.length; ++i) { |
| 801 | selectResponse[i - 1] = (byte) result[i]; |
| 802 | } |
| 803 | } |
| 804 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 805 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 806 | |
| 807 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 808 | if (uiccPort == null) { |
| 809 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 810 | } else { |
| 811 | IccLogicalChannelRequest channelRequest = |
| 812 | (IccLogicalChannelRequest) request.argument; |
| 813 | channelRequest.channel = channelId; |
| 814 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 815 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 816 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 817 | if (ar.result == null) { |
| 818 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 819 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 820 | if (ar.exception != null) { |
| 821 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 822 | } |
| 823 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 824 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 825 | if (ar.exception instanceof CommandException) { |
| 826 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 827 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 828 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 829 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 830 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 831 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 835 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 836 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 837 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 838 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 839 | break; |
| 840 | |
| 841 | case CMD_CLOSE_CHANNEL: |
| 842 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 843 | uiccPort = getUiccPortFromRequest(request); |
| 844 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 845 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 846 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 847 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 848 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 849 | } else { |
| 850 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 851 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 852 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 853 | break; |
| 854 | |
| 855 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 856 | ar = (AsyncResult) msg.obj; |
| 857 | request = (MainThreadRequest) ar.userObj; |
| 858 | if (ar.exception == null) { |
| 859 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 860 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 861 | if (uiccPort == null) { |
| 862 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 863 | } else { |
| 864 | final int channelId = (Integer) request.argument; |
| 865 | uiccPort.onLogicalChannelClosed(channelId); |
| 866 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 867 | } else { |
| 868 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 869 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 870 | if (ar.exception instanceof CommandException) { |
| 871 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 872 | CommandException.Error error = |
| 873 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 874 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 875 | // should only throw exceptions from the binder threads. |
| 876 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 877 | "iccCloseLogicalChannel: invalid argument "); |
| 878 | } |
| 879 | } else { |
| 880 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 881 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 882 | request.result = (exception != null) ? exception : |
| 883 | new IllegalStateException( |
| 884 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 885 | } |
| 886 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | case CMD_NV_READ_ITEM: |
| 890 | request = (MainThreadRequest) msg.obj; |
| 891 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 892 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 893 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 897 | ar = (AsyncResult) msg.obj; |
| 898 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 899 | if (ar.exception == null && ar.result != null) { |
| 900 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 901 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 902 | request.result = ""; |
| 903 | if (ar.result == null) { |
| 904 | loge("nvReadItem: Empty response"); |
| 905 | } else if (ar.exception instanceof CommandException) { |
| 906 | loge("nvReadItem: CommandException: " + |
| 907 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 908 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 909 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 912 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 913 | break; |
| 914 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 915 | case CMD_NV_WRITE_ITEM: |
| 916 | request = (MainThreadRequest) msg.obj; |
| 917 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 918 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 919 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 920 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
| 923 | case EVENT_NV_WRITE_ITEM_DONE: |
| 924 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 925 | break; |
| 926 | |
| 927 | case CMD_NV_WRITE_CDMA_PRL: |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 930 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 931 | break; |
| 932 | |
| 933 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 934 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 935 | break; |
| 936 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 937 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 938 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 939 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 940 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 941 | break; |
| 942 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 943 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 944 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 945 | break; |
| 946 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 947 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 948 | request = (MainThreadRequest) msg.obj; |
| 949 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 950 | request); |
| 951 | Phone phone = getPhoneFromRequest(request); |
| 952 | if (phone != null) { |
| 953 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 954 | } else { |
| 955 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 956 | request.result = false; |
| 957 | notifyRequester(request); |
| 958 | } |
| 959 | break; |
| 960 | } |
| 961 | |
| 962 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 963 | ar = (AsyncResult) msg.obj; |
| 964 | request = (MainThreadRequest) ar.userObj; |
| 965 | if (ar.exception == null && ar.result != null) { |
| 966 | request.result = ar.result; |
| 967 | } else { |
| 968 | // request.result must be set to something non-null |
| 969 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 970 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 971 | request.result = ar.result; |
| 972 | } else { |
| 973 | request.result = false; |
| 974 | } |
| 975 | if (ar.result == null) { |
| 976 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 977 | } else if (ar.exception instanceof CommandException) { |
| 978 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 979 | + ar.exception); |
| 980 | } else { |
| 981 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 982 | } |
| 983 | } |
| 984 | notifyRequester(request); |
| 985 | break; |
| 986 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 987 | case CMD_IS_VONR_ENABLED: { |
| 988 | request = (MainThreadRequest) msg.obj; |
| 989 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 990 | request); |
| 991 | Phone phone = getPhoneFromRequest(request); |
| 992 | if (phone != null) { |
| 993 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 994 | } else { |
| 995 | loge("isVoNrEnabled: No phone object"); |
| 996 | request.result = false; |
| 997 | notifyRequester(request); |
| 998 | } |
| 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1003 | ar = (AsyncResult) msg.obj; |
| 1004 | request = (MainThreadRequest) ar.userObj; |
| 1005 | if (ar.exception == null && ar.result != null) { |
| 1006 | request.result = ar.result; |
| 1007 | } else { |
| 1008 | // request.result must be set to something non-null |
| 1009 | // for the calling thread to unblock |
| 1010 | if (ar.result != null) { |
| 1011 | request.result = ar.result; |
| 1012 | } else { |
| 1013 | request.result = false; |
| 1014 | } |
| 1015 | if (ar.result == null) { |
| 1016 | loge("isVoNrEnabled: Empty response"); |
| 1017 | } else if (ar.exception instanceof CommandException) { |
| 1018 | loge("isVoNrEnabled: CommandException: " |
| 1019 | + ar.exception); |
| 1020 | } else { |
| 1021 | loge("isVoNrEnabled: Unknown exception"); |
| 1022 | } |
| 1023 | } |
| 1024 | notifyRequester(request); |
| 1025 | break; |
| 1026 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1027 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1030 | Phone phone = getPhoneFromRequest(request); |
| 1031 | if (phone != null) { |
| 1032 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1033 | request.workSource); |
| 1034 | } else { |
| 1035 | loge("enableNrDualConnectivity: No phone object"); |
| 1036 | request.result = |
| 1037 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1038 | notifyRequester(request); |
| 1039 | } |
| 1040 | break; |
| 1041 | } |
| 1042 | |
| 1043 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1044 | ar = (AsyncResult) msg.obj; |
| 1045 | request = (MainThreadRequest) ar.userObj; |
| 1046 | if (ar.exception == null) { |
| 1047 | request.result = |
| 1048 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1049 | } else { |
| 1050 | request.result = |
| 1051 | TelephonyManager |
| 1052 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1053 | if (ar.exception instanceof CommandException) { |
| 1054 | CommandException.Error error = |
| 1055 | ((CommandException) (ar.exception)).getCommandError(); |
| 1056 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1057 | request.result = |
| 1058 | TelephonyManager |
| 1059 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1060 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1061 | request.result = |
| 1062 | TelephonyManager |
| 1063 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1064 | } |
| 1065 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1066 | + ar.exception); |
| 1067 | } else { |
| 1068 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1069 | } |
| 1070 | } |
| 1071 | notifyRequester(request); |
| 1072 | break; |
| 1073 | } |
| 1074 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1075 | case CMD_ENABLE_VONR: { |
| 1076 | request = (MainThreadRequest) msg.obj; |
| 1077 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1078 | Phone phone = getPhoneFromRequest(request); |
| 1079 | if (phone != null) { |
| 1080 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1081 | request.workSource); |
| 1082 | } else { |
| 1083 | loge("setVoNrEnabled: No phone object"); |
| 1084 | request.result = |
| 1085 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1086 | notifyRequester(request); |
| 1087 | } |
| 1088 | break; |
| 1089 | } |
| 1090 | |
| 1091 | case EVENT_ENABLE_VONR_DONE: { |
| 1092 | ar = (AsyncResult) msg.obj; |
| 1093 | request = (MainThreadRequest) ar.userObj; |
| 1094 | if (ar.exception == null) { |
| 1095 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1096 | } else { |
| 1097 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1098 | if (ar.exception instanceof CommandException) { |
| 1099 | CommandException.Error error = |
| 1100 | ((CommandException) (ar.exception)).getCommandError(); |
| 1101 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1102 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1103 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1104 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1105 | } else { |
| 1106 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1107 | } |
| 1108 | loge("setVoNrEnabled" + ": CommandException: " |
| 1109 | + ar.exception); |
| 1110 | } else { |
| 1111 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1112 | } |
| 1113 | } |
| 1114 | notifyRequester(request); |
| 1115 | break; |
| 1116 | } |
| 1117 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1118 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1119 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1120 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1121 | request); |
| 1122 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1123 | break; |
| 1124 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1125 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1126 | ar = (AsyncResult) msg.obj; |
| 1127 | request = (MainThreadRequest) ar.userObj; |
| 1128 | if (ar.exception == null && ar.result != null) { |
| 1129 | request.result = ar.result; // Integer |
| 1130 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1131 | // request.result must be set to something non-null |
| 1132 | // for the calling thread to unblock |
| 1133 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1134 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1135 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1136 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1137 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1138 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1139 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1140 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1141 | } |
| 1142 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1143 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1144 | break; |
| 1145 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1146 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1147 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1148 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1149 | request); |
| 1150 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1151 | (Pair<Integer, Long>) request.argument; |
| 1152 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1153 | reasonWithNetworkTypes.first, |
| 1154 | reasonWithNetworkTypes.second, |
| 1155 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1156 | break; |
| 1157 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1158 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1159 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1160 | break; |
| 1161 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1162 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1163 | request = (MainThreadRequest) msg.obj; |
| 1164 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1165 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1166 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1167 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1168 | break; |
| 1169 | |
| 1170 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1171 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1172 | break; |
| 1173 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1174 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1175 | request = (MainThreadRequest) msg.obj; |
| 1176 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1177 | request); |
| 1178 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1179 | break; |
| 1180 | |
| 1181 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1182 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1183 | break; |
| 1184 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1185 | case CMD_PERFORM_NETWORK_SCAN: |
| 1186 | request = (MainThreadRequest) msg.obj; |
| 1187 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1188 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1189 | break; |
| 1190 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1191 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | request = (MainThreadRequest) msg.obj; |
| 1193 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1194 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1195 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1196 | request.argument; |
| 1197 | int callForwardingReason = args.first; |
| 1198 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1199 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1200 | } |
| 1201 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | ar = (AsyncResult) msg.obj; |
| 1203 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1205 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1206 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1208 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1210 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1211 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1212 | // any service for voice call. |
| 1213 | if ((callForwardInfo.serviceClass |
| 1214 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1215 | callForwardingInfo = new CallForwardingInfo( |
| 1216 | callForwardInfo.status |
| 1217 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | callForwardInfo.reason, |
| 1219 | callForwardInfo.number, |
| 1220 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | break; |
| 1222 | } |
| 1223 | } |
| 1224 | // Didn't find a call forward info for voice call. |
| 1225 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1227 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1229 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | } else { |
| 1231 | if (ar.result == null) { |
| 1232 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1233 | } |
| 1234 | if (ar.exception != null) { |
| 1235 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1236 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1237 | int errorCode = TelephonyManager |
| 1238 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | if (ar.exception instanceof CommandException) { |
| 1240 | CommandException.Error error = |
| 1241 | ((CommandException) (ar.exception)).getCommandError(); |
| 1242 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1243 | errorCode = TelephonyManager |
| 1244 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1246 | errorCode = TelephonyManager |
| 1247 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | } |
| 1249 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1251 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | request = (MainThreadRequest) msg.obj; |
| 1257 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1261 | request.argument).first; |
| 1262 | request.phone.setCallForwardingOption( |
| 1263 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1264 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | callForwardingInfoToSet.getReason(), |
| 1267 | callForwardingInfoToSet.getNumber(), |
| 1268 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1269 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1270 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1271 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1272 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | ar = (AsyncResult) msg.obj; |
| 1274 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | Consumer<Integer> callback = |
| 1276 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1277 | request.argument).second; |
| 1278 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1280 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1281 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | if (ar.exception instanceof CommandException) { |
| 1283 | CommandException.Error error = |
| 1284 | ((CommandException) (ar.exception)).getCommandError(); |
| 1285 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1286 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1287 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1288 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1289 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1290 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1291 | } |
| 1292 | } |
| 1293 | callback.accept(errorCode); |
| 1294 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1295 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1296 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | request = (MainThreadRequest) msg.obj; |
| 1302 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1303 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1304 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | ar = (AsyncResult) msg.obj; |
| 1309 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1311 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1313 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1314 | // Service Class is a bit mask per 3gpp 27.007. |
| 1315 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1316 | if (callForwardResults.length > 1 |
| 1317 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1318 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1319 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1320 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1321 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1322 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1323 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | } |
| 1325 | } else { |
| 1326 | if (ar.result == null) { |
| 1327 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1328 | } |
| 1329 | if (ar.exception != null) { |
| 1330 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1331 | } |
| 1332 | if (ar.exception instanceof CommandException) { |
| 1333 | CommandException.Error error = |
| 1334 | ((CommandException) (ar.exception)).getCommandError(); |
| 1335 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1336 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1337 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1338 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1339 | callWaitingStatus = |
| 1340 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1344 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1345 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1346 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1348 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1349 | request = (MainThreadRequest) msg.obj; |
| 1350 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1351 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1352 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1353 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1354 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1355 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1356 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1357 | ar = (AsyncResult) msg.obj; |
| 1358 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1359 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1360 | Consumer<Integer> callback = |
| 1361 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1362 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1363 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1364 | if (ar.exception instanceof CommandException) { |
| 1365 | CommandException.Error error = |
| 1366 | ((CommandException) (ar.exception)).getCommandError(); |
| 1367 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1368 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1369 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1370 | callback.accept( |
| 1371 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1372 | } else { |
| 1373 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1374 | } |
| 1375 | } else { |
| 1376 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1377 | } |
| 1378 | } else { |
| 1379 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1380 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1381 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1382 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1383 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1384 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1385 | ar = (AsyncResult) msg.obj; |
| 1386 | request = (MainThreadRequest) ar.userObj; |
| 1387 | CellNetworkScanResult cellScanResult; |
| 1388 | if (ar.exception == null && ar.result != null) { |
| 1389 | cellScanResult = new CellNetworkScanResult( |
| 1390 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1391 | (List<OperatorInfo>) ar.result); |
| 1392 | } else { |
| 1393 | if (ar.result == null) { |
| 1394 | loge("getCellNetworkScanResults: Empty response"); |
| 1395 | } |
| 1396 | if (ar.exception != null) { |
| 1397 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1398 | } |
| 1399 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1400 | if (ar.exception instanceof CommandException) { |
| 1401 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1402 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1403 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1404 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1405 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1406 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1407 | } |
| 1408 | } |
| 1409 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1410 | } |
| 1411 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1412 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1413 | break; |
| 1414 | |
| 1415 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1416 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1417 | ManualNetworkSelectionArgument selArg = |
| 1418 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1419 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1420 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1421 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1422 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1423 | break; |
| 1424 | |
| 1425 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1426 | ar = (AsyncResult) msg.obj; |
| 1427 | request = (MainThreadRequest) ar.userObj; |
| 1428 | if (ar.exception == null) { |
| 1429 | request.result = true; |
| 1430 | } else { |
| 1431 | request.result = false; |
| 1432 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1433 | } |
| 1434 | notifyRequester(request); |
| 1435 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1436 | break; |
| 1437 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1438 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1439 | request = (MainThreadRequest) msg.obj; |
| 1440 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1441 | if (defaultPhone != null) { |
| 1442 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1443 | } else { |
| 1444 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1445 | Bundle bundle = new Bundle(); |
| 1446 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1447 | new ModemActivityInfo(0, 0, 0, |
| 1448 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1449 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1450 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1451 | break; |
| 1452 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1453 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1454 | ar = (AsyncResult) msg.obj; |
| 1455 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1456 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1457 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1458 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1459 | if (mLastModemActivityInfo == null) { |
| 1460 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1461 | mLastModemActivitySpecificInfo[0] = |
| 1462 | new ActivityStatsTechSpecificInfo( |
| 1463 | 0, |
| 1464 | 0, |
| 1465 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1466 | 0); |
| 1467 | mLastModemActivityInfo = |
| 1468 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1469 | } |
| 1470 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1471 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1472 | // Update the last modem activity info and the result of the request. |
| 1473 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1474 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1475 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1476 | } else { |
| 1477 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1478 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1479 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1480 | // We don't want to return mLastModemActivityInfo which is updated |
| 1481 | // inside mergeModemActivityInfo() |
| 1482 | ret = new ModemActivityInfo( |
| 1483 | mLastModemActivityInfo.getTimestampMillis(), |
| 1484 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1485 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1486 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1487 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1488 | } else { |
| 1489 | if (ar.result == null) { |
| 1490 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1491 | error = TelephonyManager.ModemActivityInfoException |
| 1492 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1493 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1494 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1495 | error = TelephonyManager.ModemActivityInfoException |
| 1496 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1497 | } else { |
| 1498 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1499 | error = TelephonyManager.ModemActivityInfoException |
| 1500 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1501 | } |
| 1502 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1503 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1504 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1505 | bundle.putParcelable( |
| 1506 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1507 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1508 | } else { |
| 1509 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1510 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1511 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1512 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1513 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1514 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1515 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1516 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1517 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1518 | CarrierRestrictionRules argument = |
| 1519 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1520 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1521 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1522 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1523 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1524 | |
| 1525 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1526 | ar = (AsyncResult) msg.obj; |
| 1527 | request = (MainThreadRequest) ar.userObj; |
| 1528 | if (ar.exception == null && ar.result != null) { |
| 1529 | request.result = ar.result; |
| 1530 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1531 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1532 | if (ar.exception instanceof CommandException) { |
| 1533 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1534 | CommandException.Error error = |
| 1535 | ((CommandException) (ar.exception)).getCommandError(); |
| 1536 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1537 | request.result = |
| 1538 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1539 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1540 | } else { |
| 1541 | loge("setAllowedCarriers: Unknown exception"); |
| 1542 | } |
| 1543 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1544 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1545 | break; |
| 1546 | |
| 1547 | case CMD_GET_ALLOWED_CARRIERS: |
| 1548 | request = (MainThreadRequest) msg.obj; |
| 1549 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1550 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1551 | break; |
| 1552 | |
| 1553 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1554 | ar = (AsyncResult) msg.obj; |
| 1555 | request = (MainThreadRequest) ar.userObj; |
| 1556 | if (ar.exception == null && ar.result != null) { |
| 1557 | request.result = ar.result; |
| 1558 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1559 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1560 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1561 | if (ar.result == null) { |
| 1562 | loge("getAllowedCarriers: Empty response"); |
| 1563 | } else if (ar.exception instanceof CommandException) { |
| 1564 | loge("getAllowedCarriers: CommandException: " + |
| 1565 | ar.exception); |
| 1566 | } else { |
| 1567 | loge("getAllowedCarriers: Unknown exception"); |
| 1568 | } |
| 1569 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1570 | if (request.argument != null) { |
| 1571 | // This is for the implementation of carrierRestrictionStatus. |
| 1572 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1573 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1574 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1575 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1576 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1577 | CarrierRestrictionRules carrierRestrictionRules = |
| 1578 | (CarrierRestrictionRules) ar.result; |
| 1579 | int carrierId = -1; |
| 1580 | try { |
| 1581 | CarrierIdentifier carrierIdentifier = |
| 1582 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1583 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1584 | carrierIdentifier); |
| 1585 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1586 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1587 | } |
| 1588 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1589 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1590 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1591 | lockStatus = TelephonyManager |
| 1592 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1593 | } |
| 1594 | } else { |
| 1595 | Rlog.e(LOG_TAG, |
| 1596 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1597 | } |
| 1598 | callback.accept(lockStatus); |
| 1599 | } else { |
| 1600 | // This is for the implementation of getAllowedCarriers. |
| 1601 | notifyRequester(request); |
| 1602 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1603 | break; |
| 1604 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1605 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1606 | ar = (AsyncResult) msg.obj; |
| 1607 | request = (MainThreadRequest) ar.userObj; |
| 1608 | if (ar.exception == null && ar.result != null) { |
| 1609 | request.result = ar.result; |
| 1610 | } else { |
| 1611 | request.result = new IllegalArgumentException( |
| 1612 | "Failed to retrieve Forbidden Plmns"); |
| 1613 | if (ar.result == null) { |
| 1614 | loge("getForbiddenPlmns: Empty response"); |
| 1615 | } else { |
| 1616 | loge("getForbiddenPlmns: Unknown exception"); |
| 1617 | } |
| 1618 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1619 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1620 | break; |
| 1621 | |
| 1622 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1623 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1624 | uiccPort = getUiccPortFromRequest(request); |
| 1625 | if (uiccPort == null) { |
| 1626 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1627 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1628 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1629 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1630 | break; |
| 1631 | } |
| 1632 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1633 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1634 | if (uiccApp == null) { |
| 1635 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1636 | + appType); |
| 1637 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1638 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1639 | break; |
| 1640 | } else { |
| 1641 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1642 | + " specified type -- " + appType); |
| 1643 | } |
| 1644 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1645 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1646 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1647 | break; |
| 1648 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1649 | case CMD_SWITCH_SLOTS: |
| 1650 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1651 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1652 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1653 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1654 | break; |
| 1655 | |
| 1656 | case EVENT_SWITCH_SLOTS_DONE: |
| 1657 | ar = (AsyncResult) msg.obj; |
| 1658 | request = (MainThreadRequest) ar.userObj; |
| 1659 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1660 | notifyRequester(request); |
| 1661 | break; |
| 1662 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1663 | request = (MainThreadRequest) msg.obj; |
| 1664 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1665 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1666 | break; |
| 1667 | |
| 1668 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1669 | ar = (AsyncResult) msg.obj; |
| 1670 | request = (MainThreadRequest) ar.userObj; |
| 1671 | if (ar.exception != null) { |
| 1672 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1673 | } else { |
| 1674 | int mode = ((int[]) ar.result)[0]; |
| 1675 | if (mode == 0) { |
| 1676 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1677 | } else { |
| 1678 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1679 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1680 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1681 | notifyRequester(request); |
| 1682 | break; |
| 1683 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1684 | request = (MainThreadRequest) msg.obj; |
| 1685 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1686 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1687 | break; |
| 1688 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1689 | ar = (AsyncResult) msg.obj; |
| 1690 | request = (MainThreadRequest) ar.userObj; |
| 1691 | if (ar.exception != null) { |
| 1692 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1693 | } else { |
| 1694 | request.result = ((int[]) ar.result)[0]; |
| 1695 | } |
| 1696 | notifyRequester(request); |
| 1697 | break; |
| 1698 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1699 | request = (MainThreadRequest) msg.obj; |
| 1700 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1701 | int mode = (int) request.argument; |
| 1702 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1703 | break; |
| 1704 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1705 | ar = (AsyncResult) msg.obj; |
| 1706 | request = (MainThreadRequest) ar.userObj; |
| 1707 | request.result = ar.exception == null; |
| 1708 | notifyRequester(request); |
| 1709 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1710 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1711 | request = (MainThreadRequest) msg.obj; |
| 1712 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1713 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1714 | break; |
| 1715 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1716 | ar = (AsyncResult) msg.obj; |
| 1717 | request = (MainThreadRequest) ar.userObj; |
| 1718 | if (ar.exception != null) { |
| 1719 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1720 | } else { |
| 1721 | request.result = ((int[]) ar.result)[0]; |
| 1722 | } |
| 1723 | notifyRequester(request); |
| 1724 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1725 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1726 | request = (MainThreadRequest) msg.obj; |
| 1727 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1728 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1729 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1730 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1731 | break; |
| 1732 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1733 | ar = (AsyncResult) msg.obj; |
| 1734 | request = (MainThreadRequest) ar.userObj; |
| 1735 | request.result = ar.exception == null; |
| 1736 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1737 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1738 | case CMD_GET_ALL_CELL_INFO: |
| 1739 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1740 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1741 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1742 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1743 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1744 | ar = (AsyncResult) msg.obj; |
| 1745 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1746 | // If a timeout occurs, the response will be null |
| 1747 | request.result = (ar.exception == null && ar.result != null) |
| 1748 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1749 | synchronized (request) { |
| 1750 | request.notifyAll(); |
| 1751 | } |
| 1752 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1753 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1754 | request = (MainThreadRequest) msg.obj; |
| 1755 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1756 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1757 | break; |
| 1758 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1759 | ar = (AsyncResult) msg.obj; |
| 1760 | request = (MainThreadRequest) ar.userObj; |
| 1761 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1762 | try { |
| 1763 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1764 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1765 | cb.onError( |
| 1766 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1767 | ar.exception.getClass().getName(), |
| 1768 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1769 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1770 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1771 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1772 | } else { |
| 1773 | // use the result as returned |
| 1774 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1775 | } |
| 1776 | } catch (RemoteException re) { |
| 1777 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1778 | } |
| 1779 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1780 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1781 | request = (MainThreadRequest) msg.obj; |
| 1782 | WorkSource ws = (WorkSource) request.argument; |
| 1783 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1784 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1785 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1786 | } |
| 1787 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1788 | ar = (AsyncResult) msg.obj; |
| 1789 | request = (MainThreadRequest) ar.userObj; |
| 1790 | if (ar.exception == null) { |
| 1791 | request.result = ar.result; |
| 1792 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1793 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1794 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1795 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | synchronized (request) { |
| 1799 | request.notifyAll(); |
| 1800 | } |
| 1801 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1802 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1803 | case CMD_MODEM_REBOOT: |
| 1804 | request = (MainThreadRequest) msg.obj; |
| 1805 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1806 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1807 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1808 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1809 | handleNullReturnEvent(msg, "rebootModem"); |
| 1810 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1811 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1812 | request = (MainThreadRequest) msg.obj; |
| 1813 | boolean enable = (boolean) request.argument; |
| 1814 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1815 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1816 | PhoneConfigurationManager.getInstance() |
| 1817 | .enablePhone(request.phone, enable, onCompleted); |
| 1818 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1819 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1820 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1821 | ar = (AsyncResult) msg.obj; |
| 1822 | request = (MainThreadRequest) ar.userObj; |
| 1823 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1824 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1825 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1826 | if ((boolean) request.result) { |
| 1827 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1828 | updateModemStateMetrics(); |
| 1829 | } else { |
| 1830 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1831 | + ar.exception); |
| 1832 | } |
| 1833 | notifyRequester(request); |
| 1834 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1835 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1836 | case CMD_GET_MODEM_STATUS: |
| 1837 | request = (MainThreadRequest) msg.obj; |
| 1838 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1839 | PhoneConfigurationManager.getInstance() |
| 1840 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1841 | break; |
| 1842 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1843 | ar = (AsyncResult) msg.obj; |
| 1844 | request = (MainThreadRequest) ar.userObj; |
| 1845 | int id = request.phone.getPhoneId(); |
| 1846 | if (ar.exception == null && ar.result != null) { |
| 1847 | request.result = ar.result; |
| 1848 | //update the cache as modem status has changed |
| 1849 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1850 | (boolean) request.result); |
| 1851 | } else { |
| 1852 | // Return true if modem status cannot be retrieved. For most cases, |
| 1853 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1854 | // and disable modem are not supported. Modem is always on. |
| 1855 | // TODO: this should be fixed in R to support a third |
| 1856 | // status UNKNOWN b/131631629 |
| 1857 | request.result = true; |
| 1858 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1859 | + ar.exception); |
| 1860 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1861 | notifyRequester(request); |
| 1862 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1863 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1864 | request = (MainThreadRequest) msg.obj; |
| 1865 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1866 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1867 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1868 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1869 | break; |
| 1870 | } |
| 1871 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1872 | ar = (AsyncResult) msg.obj; |
| 1873 | request = (MainThreadRequest) ar.userObj; |
| 1874 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1875 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1876 | args.second.accept(ar.exception == null); |
| 1877 | notifyRequester(request); |
| 1878 | break; |
| 1879 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1880 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1881 | request = (MainThreadRequest) msg.obj; |
| 1882 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1883 | Phone phone = getPhoneFromRequest(request); |
| 1884 | if (phone != null) { |
| 1885 | phone.getSystemSelectionChannels(onCompleted); |
| 1886 | } else { |
| 1887 | loge("getSystemSelectionChannels: No phone object"); |
| 1888 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1889 | notifyRequester(request); |
| 1890 | } |
| 1891 | break; |
| 1892 | } |
| 1893 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1894 | ar = (AsyncResult) msg.obj; |
| 1895 | request = (MainThreadRequest) ar.userObj; |
| 1896 | if (ar.exception == null && ar.result != null) { |
| 1897 | request.result = ar.result; |
| 1898 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1899 | request.result = new IllegalStateException( |
| 1900 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1901 | if (ar.result == null) { |
| 1902 | loge("getSystemSelectionChannels: Empty response"); |
| 1903 | } else { |
| 1904 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1905 | } |
| 1906 | } |
| 1907 | notifyRequester(request); |
| 1908 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1909 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1910 | ar = (AsyncResult) msg.obj; |
| 1911 | request = (MainThreadRequest) ar.userObj; |
| 1912 | if (ar.exception == null && ar.result != null) { |
| 1913 | request.result = ar.result; |
| 1914 | } else { |
| 1915 | request.result = -1; |
| 1916 | loge("Failed to set Forbidden Plmns"); |
| 1917 | if (ar.result == null) { |
| 1918 | loge("setForbidenPlmns: Empty response"); |
| 1919 | } else if (ar.exception != null) { |
| 1920 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1921 | request.result = -1; |
| 1922 | } else { |
| 1923 | loge("setForbiddenPlmns: Unknown exception"); |
| 1924 | } |
| 1925 | } |
| 1926 | notifyRequester(request); |
| 1927 | break; |
| 1928 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1929 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1930 | uiccPort = getUiccPortFromRequest(request); |
| 1931 | if (uiccPort == null) { |
| 1932 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1933 | request.result = -1; |
| 1934 | notifyRequester(request); |
| 1935 | break; |
| 1936 | } |
| 1937 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1938 | (Pair<Integer, List<String>>) request.argument; |
| 1939 | appType = setFplmnsArgs.first; |
| 1940 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1941 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1942 | if (uiccApp == null) { |
| 1943 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1944 | request.result = -1; |
| 1945 | loge("Failed to get UICC App"); |
| 1946 | notifyRequester(request); |
| 1947 | } else { |
| 1948 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1949 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1950 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1951 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1952 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1953 | case CMD_ERASE_MODEM_CONFIG: |
| 1954 | request = (MainThreadRequest) msg.obj; |
| 1955 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1956 | defaultPhone.eraseModemConfig(onCompleted); |
| 1957 | break; |
| 1958 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1959 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1960 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1961 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1962 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1963 | request = (MainThreadRequest) msg.obj; |
| 1964 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1965 | notifyRequester(request); |
| 1966 | break; |
| 1967 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1968 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1969 | request = (MainThreadRequest) msg.obj; |
| 1970 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1971 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1972 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1973 | changed.first, changed.second, onCompleted); |
| 1974 | break; |
| 1975 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1976 | ar = (AsyncResult) msg.obj; |
| 1977 | request = (MainThreadRequest) ar.userObj; |
| 1978 | if (ar.exception == null) { |
| 1979 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1980 | // If the operation is successful, update the PIN storage |
| 1981 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1982 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1983 | UiccController.getInstance().getPinStorage() |
| 1984 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1985 | } else { |
| 1986 | request.result = msg.arg1; |
| 1987 | } |
| 1988 | notifyRequester(request); |
| 1989 | break; |
| 1990 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1991 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1992 | request = (MainThreadRequest) msg.obj; |
| 1993 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1994 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1995 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1996 | enabled.first, enabled.second, onCompleted); |
| 1997 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1998 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1999 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2000 | ar = (AsyncResult) msg.obj; |
| 2001 | request = (MainThreadRequest) ar.userObj; |
| 2002 | if (ar.exception == null) { |
| 2003 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2004 | // If the operation is successful, update the PIN storage |
| 2005 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2006 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2007 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2008 | UiccController.getInstance().getPinStorage() |
| 2009 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2010 | } else { |
| 2011 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2012 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2013 | } else { |
| 2014 | request.result = msg.arg1; |
| 2015 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2016 | |
| 2017 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2018 | notifyRequester(request); |
| 2019 | break; |
| 2020 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2021 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2022 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2023 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2024 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2025 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2026 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2027 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2028 | |
| 2029 | case CMD_SET_DATA_THROTTLING: { |
| 2030 | request = (MainThreadRequest) msg.obj; |
| 2031 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2032 | DataThrottlingRequest dataThrottlingRequest = |
| 2033 | (DataThrottlingRequest) request.argument; |
| 2034 | Phone phone = getPhoneFromRequest(request); |
| 2035 | if (phone != null) { |
| 2036 | phone.setDataThrottling(onCompleted, |
| 2037 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2038 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2039 | } else { |
| 2040 | loge("setDataThrottling: No phone object"); |
| 2041 | request.result = |
| 2042 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2043 | notifyRequester(request); |
| 2044 | } |
| 2045 | |
| 2046 | break; |
| 2047 | } |
| 2048 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2049 | ar = (AsyncResult) msg.obj; |
| 2050 | request = (MainThreadRequest) ar.userObj; |
| 2051 | |
| 2052 | if (ar.exception == null) { |
| 2053 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2054 | } else if (ar.exception instanceof CommandException) { |
| 2055 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2056 | CommandException.Error error = |
| 2057 | ((CommandException) (ar.exception)).getCommandError(); |
| 2058 | |
| 2059 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2060 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2061 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2062 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2063 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2064 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2065 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2066 | } else { |
| 2067 | request.result = |
| 2068 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2069 | } |
| 2070 | } else { |
| 2071 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2072 | } |
| 2073 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2074 | notifyRequester(request); |
| 2075 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2076 | |
| 2077 | case CMD_SET_SIM_POWER: { |
| 2078 | request = (MainThreadRequest) msg.obj; |
| 2079 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2080 | request = (MainThreadRequest) msg.obj; |
| 2081 | int stateToSet = |
| 2082 | ((Pair<Integer, IIntegerConsumer>) |
| 2083 | request.argument).first; |
| 2084 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2085 | break; |
| 2086 | } |
| 2087 | case EVENT_SET_SIM_POWER_DONE: { |
| 2088 | ar = (AsyncResult) msg.obj; |
| 2089 | request = (MainThreadRequest) ar.userObj; |
| 2090 | IIntegerConsumer callback = |
| 2091 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2092 | if (ar.exception != null) { |
| 2093 | loge("setSimPower exception: " + ar.exception); |
| 2094 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2095 | .RESULT_ERROR_UNKNOWN; |
| 2096 | if (ar.exception instanceof CommandException) { |
| 2097 | CommandException.Error error = |
| 2098 | ((CommandException) (ar.exception)).getCommandError(); |
| 2099 | if (error == CommandException.Error.SIM_ERR) { |
| 2100 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2101 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2102 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2103 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2104 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2105 | } else { |
| 2106 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2107 | } |
| 2108 | } |
| 2109 | try { |
| 2110 | callback.accept(errorCode); |
| 2111 | } catch (RemoteException e) { |
| 2112 | // Ignore if the remote process is no longer available to call back. |
| 2113 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2114 | } |
| 2115 | } else { |
| 2116 | try { |
| 2117 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2118 | } catch (RemoteException e) { |
| 2119 | // Ignore if the remote process is no longer available to call back. |
| 2120 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2121 | } |
| 2122 | } |
| 2123 | break; |
| 2124 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2125 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2126 | request = (MainThreadRequest) msg.obj; |
| 2127 | |
| 2128 | final Phone phone = getPhoneFromRequest(request); |
| 2129 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2130 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2131 | notifyRequester(request); |
| 2132 | break; |
| 2133 | } |
| 2134 | |
| 2135 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2136 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2137 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2138 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2139 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2140 | request.subId, pair.first /*callingUid*/, |
| 2141 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2142 | break; |
| 2143 | } |
| 2144 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2145 | ar = (AsyncResult) msg.obj; |
| 2146 | request = (MainThreadRequest) ar.userObj; |
| 2147 | // request.result will be the exception of ar if present, true otherwise. |
| 2148 | // Be cautious not to leave result null which will wait() forever |
| 2149 | request.result = ar.exception != null ? ar.exception : true; |
| 2150 | notifyRequester(request); |
| 2151 | break; |
| 2152 | } |
| 2153 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2154 | request = (MainThreadRequest) msg.obj; |
| 2155 | |
| 2156 | Phone phone = getPhoneFromRequest(request); |
| 2157 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2158 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2159 | notifyRequester(request); |
| 2160 | break; |
| 2161 | } |
| 2162 | |
| 2163 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2164 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2165 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2166 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2167 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2168 | request.subId, pair.first /*callingUid*/, |
| 2169 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2170 | break; |
| 2171 | } |
| 2172 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2173 | ar = (AsyncResult) msg.obj; |
| 2174 | request = (MainThreadRequest) ar.userObj; |
| 2175 | request.result = ar.exception != null ? ar.exception : true; |
| 2176 | notifyRequester(request); |
| 2177 | break; |
| 2178 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2179 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2180 | case CMD_GET_SLICING_CONFIG: { |
| 2181 | request = (MainThreadRequest) msg.obj; |
| 2182 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2183 | request.phone.getSlicingConfig(onCompleted); |
| 2184 | break; |
| 2185 | } |
| 2186 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2187 | ar = (AsyncResult) msg.obj; |
| 2188 | request = (MainThreadRequest) ar.userObj; |
| 2189 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2190 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2191 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2192 | Bundle bundle = new Bundle(); |
| 2193 | int resultCode = 0; |
| 2194 | if (ar.exception != null) { |
| 2195 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2196 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2197 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2198 | } else if (ar.result == null) { |
| 2199 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2200 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2201 | } else { |
| 2202 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2203 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2204 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2208 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2209 | } |
| 2210 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2211 | result.send(resultCode, bundle); |
| 2212 | notifyRequester(request); |
| 2213 | break; |
| 2214 | } |
| 2215 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2216 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2217 | request = (MainThreadRequest) msg.obj; |
| 2218 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2219 | PurchasePremiumCapabilityArgument arg = |
| 2220 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2221 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2222 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2223 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2224 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2225 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2226 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2227 | ar = (AsyncResult) msg.obj; |
| 2228 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2229 | PurchasePremiumCapabilityArgument arg = |
| 2230 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2231 | try { |
| 2232 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2233 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2234 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2235 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2236 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2237 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2238 | } catch (RemoteException e) { |
| 2239 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2240 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2241 | + " failed: " + e; |
| 2242 | if (DBG) log(logStr); |
| 2243 | AnomalyReporter.reportAnomaly( |
| 2244 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2245 | } |
| 2246 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2247 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2248 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2249 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2250 | request = (MainThreadRequest) msg.obj; |
| 2251 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2252 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2253 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2254 | notifyRequester(request); |
| 2255 | break; |
| 2256 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2257 | default: |
| 2258 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2259 | break; |
| 2260 | } |
| 2261 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2262 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2263 | private void notifyRequester(MainThreadRequest request) { |
| 2264 | synchronized (request) { |
| 2265 | request.notifyAll(); |
| 2266 | } |
| 2267 | } |
| 2268 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2269 | private void handleNullReturnEvent(Message msg, String command) { |
| 2270 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2271 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2272 | if (ar.exception == null) { |
| 2273 | request.result = true; |
| 2274 | } else { |
| 2275 | request.result = false; |
| 2276 | if (ar.exception instanceof CommandException) { |
| 2277 | loge(command + ": CommandException: " + ar.exception); |
| 2278 | } else { |
| 2279 | loge(command + ": Unknown exception"); |
| 2280 | } |
| 2281 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2282 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | /** |
| 2287 | * Posts the specified command to be executed on the main thread, |
| 2288 | * waits for the request to complete, and returns the result. |
| 2289 | * @see #sendRequestAsync |
| 2290 | */ |
| 2291 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2292 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2293 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /** |
| 2297 | * Posts the specified command to be executed on the main thread, |
| 2298 | * waits for the request to complete, and returns the result. |
| 2299 | * @see #sendRequestAsync |
| 2300 | */ |
| 2301 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2302 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2303 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * Posts the specified command to be executed on the main thread, |
| 2308 | * waits for the request to complete, and returns the result. |
| 2309 | * @see #sendRequestAsync |
| 2310 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2311 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2312 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * Posts the specified command to be executed on the main thread, |
| 2317 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2318 | * if not timeout or null otherwise. |
| 2319 | * @see #sendRequestAsync |
| 2320 | */ |
| 2321 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2322 | long timeoutInMs) { |
| 2323 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | /** |
| 2327 | * Posts the specified command to be executed on the main thread, |
| 2328 | * waits for the request to complete, and returns the result. |
| 2329 | * @see #sendRequestAsync |
| 2330 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2331 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2332 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | /** |
| 2336 | * Posts the specified command to be executed on the main thread, |
| 2337 | * waits for the request to complete, and returns the result. |
| 2338 | * @see #sendRequestAsync |
| 2339 | */ |
| 2340 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2341 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2342 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2346 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2347 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2348 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2349 | * @see #sendRequestAsync |
| 2350 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2351 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2352 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2354 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2355 | } |
| 2356 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2357 | MainThreadRequest request = null; |
| 2358 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2359 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2360 | } else if (phone != null) { |
| 2361 | request = new MainThreadRequest(argument, phone, workSource); |
| 2362 | } else { |
| 2363 | request = new MainThreadRequest(argument, subId, workSource); |
| 2364 | } |
| 2365 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2366 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2367 | msg.sendToTarget(); |
| 2368 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2369 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2370 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2371 | if (timeoutInMs >= 0) { |
| 2372 | // Wait for at least timeoutInMs before returning null request result |
| 2373 | long now = SystemClock.elapsedRealtime(); |
| 2374 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2375 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2376 | try { |
| 2377 | request.wait(deadline - now); |
| 2378 | } catch (InterruptedException e) { |
| 2379 | // Do nothing, go back and check if request is completed or timeout |
| 2380 | } finally { |
| 2381 | now = SystemClock.elapsedRealtime(); |
| 2382 | } |
| 2383 | } |
| 2384 | } else { |
| 2385 | // Wait for the request to complete |
| 2386 | while (request.result == null) { |
| 2387 | try { |
| 2388 | request.wait(); |
| 2389 | } catch (InterruptedException e) { |
| 2390 | // Do nothing, go back and wait until the request is complete |
| 2391 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2395 | if (request.result == null) { |
| 2396 | Log.wtf(LOG_TAG, |
| 2397 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | return request.result; |
| 2400 | } |
| 2401 | |
| 2402 | /** |
| 2403 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2404 | * Posts the specified command to be executed on the main thread, and |
| 2405 | * returns immediately. |
| 2406 | * @see #sendRequest |
| 2407 | */ |
| 2408 | private void sendRequestAsync(int command) { |
| 2409 | mMainThreadHandler.sendEmptyMessage(command); |
| 2410 | } |
| 2411 | |
| 2412 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2413 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2414 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2415 | */ |
| 2416 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2417 | sendRequestAsync(command, argument, null, null); |
| 2418 | } |
| 2419 | |
| 2420 | /** |
| 2421 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2422 | * @see {@link #sendRequest(int,Object)} |
| 2423 | */ |
| 2424 | private void sendRequestAsync( |
| 2425 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2426 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2427 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2428 | msg.sendToTarget(); |
| 2429 | } |
| 2430 | |
| 2431 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2432 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2433 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2434 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2435 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | synchronized (PhoneInterfaceManager.class) { |
| 2437 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2438 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | } else { |
| 2440 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2441 | } |
| 2442 | return sInstance; |
| 2443 | } |
| 2444 | } |
| 2445 | |
| 2446 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2447 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2449 | mFeatureFlags = featureFlags; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2450 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2451 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2452 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2453 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2455 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2456 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2457 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2458 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2459 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2460 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2461 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2463 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2466 | @VisibleForTesting |
| 2467 | public SharedPreferences getSharedPreferences() { |
| 2468 | return mTelephonySharedPreferences; |
| 2469 | } |
| 2470 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2471 | /** |
| 2472 | * Get the default phone for this device. |
| 2473 | */ |
| 2474 | @VisibleForTesting |
| 2475 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2476 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2477 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2478 | } |
| 2479 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | private void publish() { |
| 2481 | if (DBG) log("publish: " + this); |
| 2482 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2483 | TelephonyFrameworkInitializer |
| 2484 | .getTelephonyServiceManager() |
| 2485 | .getTelephonyServiceRegisterer() |
| 2486 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2489 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2490 | if (request.phone != null) { |
| 2491 | return request.phone; |
| 2492 | } else { |
| 2493 | return getPhoneFromSubId(request.subId); |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | private Phone getPhoneFromSubId(int subId) { |
| 2498 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2499 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2500 | } |
| 2501 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2502 | /** |
| 2503 | * Get phone object associated with a subscription. |
| 2504 | * Return default phone if phone object associated with subscription is null |
| 2505 | * @param subId - subscriptionId |
| 2506 | * @return phone object associated with a subscription or default phone if null. |
| 2507 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2508 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2509 | Phone phone = getPhoneFromSubId(subId); |
| 2510 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2511 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2512 | phone = getDefaultPhone(); |
| 2513 | } |
| 2514 | return phone; |
| 2515 | } |
| 2516 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2517 | @Nullable |
| 2518 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2519 | Phone phone = getPhoneFromRequest(request); |
| 2520 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2521 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2522 | } |
| 2523 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2524 | /** |
| 2525 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2526 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2527 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2528 | * @return The Phone associated the sub Id |
| 2529 | */ |
| 2530 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2531 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2532 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2533 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2534 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2535 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2536 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2537 | } |
| 2538 | |
| 2539 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2540 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2541 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2544 | private boolean isImsAvailableOnDevice() { |
| 2545 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2546 | if (pm == null) { |
| 2547 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2548 | // so do not throw error and allow. |
| 2549 | return true; |
| 2550 | } |
| 2551 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2552 | } |
| 2553 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2554 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2555 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2558 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2559 | if (DBG) log("dial: " + number); |
| 2560 | // No permission check needed here: This is just a wrapper around the |
| 2561 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2562 | // the UI before it does anything. |
| 2563 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | final long identity = Binder.clearCallingIdentity(); |
| 2565 | try { |
| 2566 | String url = createTelUrl(number); |
| 2567 | if (url == null) { |
| 2568 | return; |
| 2569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2570 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2571 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2572 | PhoneConstants.State state = mCM.getState(subId); |
| 2573 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2574 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2575 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2576 | mApp.startActivity(intent); |
| 2577 | } |
| 2578 | } finally { |
| 2579 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2580 | } |
| 2581 | } |
| 2582 | |
| 2583 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2584 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2587 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | if (DBG) log("call: " + number); |
| 2589 | |
| 2590 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2591 | // need to do a permission check since we're calling startActivity() |
| 2592 | // from the context of the phone app. |
| 2593 | enforceCallPermission(); |
| 2594 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2595 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2596 | != AppOpsManager.MODE_ALLOWED) { |
| 2597 | return; |
| 2598 | } |
| 2599 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | final long identity = Binder.clearCallingIdentity(); |
| 2601 | try { |
| 2602 | String url = createTelUrl(number); |
| 2603 | if (url == null) { |
| 2604 | return; |
| 2605 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | boolean isValid = false; |
| 2608 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2609 | if (slist != null) { |
| 2610 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2611 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2612 | isValid = true; |
| 2613 | break; |
| 2614 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2615 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2616 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2617 | if (!isValid) { |
| 2618 | return; |
| 2619 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2622 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2623 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2624 | mApp.startActivity(intent); |
| 2625 | } finally { |
| 2626 | Binder.restoreCallingIdentity(identity); |
| 2627 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | } |
| 2629 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2630 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2631 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2632 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2633 | } |
| 2634 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2635 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2636 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2637 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2638 | } |
| 2639 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2640 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2641 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | |
| 2643 | final long identity = Binder.clearCallingIdentity(); |
| 2644 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2645 | Phone phone = getPhone(subId); |
| 2646 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2647 | checkSimPin.start(); |
| 2648 | return checkSimPin.unlockSim(null, pin); |
| 2649 | } finally { |
| 2650 | Binder.restoreCallingIdentity(identity); |
| 2651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2654 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2655 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | |
| 2657 | final long identity = Binder.clearCallingIdentity(); |
| 2658 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2659 | Phone phone = getPhone(subId); |
| 2660 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | checkSimPuk.start(); |
| 2662 | return checkSimPuk.unlockSim(puk, pin); |
| 2663 | } finally { |
| 2664 | Binder.restoreCallingIdentity(identity); |
| 2665 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2669 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | * a synchronous one. |
| 2671 | */ |
| 2672 | private static class UnlockSim extends Thread { |
| 2673 | |
| 2674 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2675 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | |
| 2677 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2678 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2679 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2680 | |
| 2681 | // For replies from SimCard interface |
| 2682 | private Handler mHandler; |
| 2683 | |
| 2684 | // For async handler to identify request type |
| 2685 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2686 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2687 | UnlockSim(int phoneId, IccCard simCard) { |
| 2688 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2689 | mSimCard = simCard; |
| 2690 | } |
| 2691 | |
| 2692 | @Override |
| 2693 | public void run() { |
| 2694 | Looper.prepare(); |
| 2695 | synchronized (UnlockSim.this) { |
| 2696 | mHandler = new Handler() { |
| 2697 | @Override |
| 2698 | public void handleMessage(Message msg) { |
| 2699 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2700 | switch (msg.what) { |
| 2701 | case SUPPLY_PIN_COMPLETE: |
| 2702 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2703 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2704 | mRetryCount = msg.arg1; |
| 2705 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2706 | CommandException.Error error = null; |
| 2707 | if (ar.exception instanceof CommandException) { |
| 2708 | error = ((CommandException) (ar.exception)) |
| 2709 | .getCommandError(); |
| 2710 | } |
| 2711 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2712 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2713 | } else if (error == CommandException.Error.ABORTED) { |
| 2714 | /* When UiccCardApp dispose, handle message and return |
| 2715 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2716 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2717 | } else { |
| 2718 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2719 | } |
| 2720 | } else { |
| 2721 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2722 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2723 | mDone = true; |
| 2724 | UnlockSim.this.notifyAll(); |
| 2725 | } |
| 2726 | break; |
| 2727 | } |
| 2728 | } |
| 2729 | }; |
| 2730 | UnlockSim.this.notifyAll(); |
| 2731 | } |
| 2732 | Looper.loop(); |
| 2733 | } |
| 2734 | |
| 2735 | /* |
| 2736 | * Use PIN or PUK to unlock SIM card |
| 2737 | * |
| 2738 | * If PUK is null, unlock SIM card with PIN |
| 2739 | * |
| 2740 | * 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] | 2741 | * |
| 2742 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2743 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2744 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2745 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2746 | |
| 2747 | while (mHandler == null) { |
| 2748 | try { |
| 2749 | wait(); |
| 2750 | } catch (InterruptedException e) { |
| 2751 | Thread.currentThread().interrupt(); |
| 2752 | } |
| 2753 | } |
| 2754 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2755 | |
| 2756 | if (puk == null) { |
| 2757 | mSimCard.supplyPin(pin, callback); |
| 2758 | } else { |
| 2759 | mSimCard.supplyPuk(puk, pin, callback); |
| 2760 | } |
| 2761 | |
| 2762 | while (!mDone) { |
| 2763 | try { |
| 2764 | Log.d(LOG_TAG, "wait for done"); |
| 2765 | wait(); |
| 2766 | } catch (InterruptedException e) { |
| 2767 | // Restore the interrupted status |
| 2768 | Thread.currentThread().interrupt(); |
| 2769 | } |
| 2770 | } |
| 2771 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2772 | int[] resultArray = new int[2]; |
| 2773 | resultArray[0] = mResult; |
| 2774 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2775 | |
| 2776 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2777 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2778 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2779 | // This instance is no longer reused, so quit its thread's looper. |
| 2780 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2781 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2782 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2786 | /** |
| 2787 | * This method has been removed due to privacy and stability concerns. |
| 2788 | */ |
| 2789 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2790 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2791 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2792 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2795 | @Override |
| 2796 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2797 | mApp.getSystemService(AppOpsManager.class) |
| 2798 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2799 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2800 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2801 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2802 | // Callers targeting S have no business invoking this method. |
| 2803 | return; |
| 2804 | } |
| 2805 | |
| 2806 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2807 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2808 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2809 | .setCallingPackage(callingPackage) |
| 2810 | .setCallingFeatureId(null) |
| 2811 | .setCallingPid(Binder.getCallingPid()) |
| 2812 | .setCallingUid(Binder.getCallingUid()) |
| 2813 | .setMethod("updateServiceLocation") |
| 2814 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2815 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2816 | .build()); |
| 2817 | // Apps that lack location permission have no business calling this method; |
| 2818 | // however, because no permission was declared in the public API, denials must |
| 2819 | // all be "soft". |
| 2820 | switch (locationResult) { |
| 2821 | case DENIED_HARD: /* fall through */ |
| 2822 | case DENIED_SOFT: |
| 2823 | return; |
| 2824 | } |
| 2825 | |
| 2826 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2827 | final long identity = Binder.clearCallingIdentity(); |
| 2828 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2829 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2832 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2835 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2836 | @Override |
| 2837 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2838 | return isRadioOnWithFeature(callingPackage, null); |
| 2839 | } |
| 2840 | |
| 2841 | |
| 2842 | @Override |
| 2843 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2844 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2845 | callingFeatureId); |
| 2846 | } |
| 2847 | |
| 2848 | @Deprecated |
| 2849 | @Override |
| 2850 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2851 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2854 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2855 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2856 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2857 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2858 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2859 | return false; |
| 2860 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2861 | |
| 2862 | final long identity = Binder.clearCallingIdentity(); |
| 2863 | try { |
| 2864 | return isRadioOnForSubscriber(subId); |
| 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(identity); |
| 2867 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2871 | final long identity = Binder.clearCallingIdentity(); |
| 2872 | try { |
| 2873 | final Phone phone = getPhone(subId); |
| 2874 | if (phone != null) { |
| 2875 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2876 | } else { |
| 2877 | return false; |
| 2878 | } |
| 2879 | } finally { |
| 2880 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2881 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2885 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2886 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2887 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2888 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2889 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2890 | |
| 2891 | final long identity = Binder.clearCallingIdentity(); |
| 2892 | try { |
| 2893 | final Phone phone = getPhone(subId); |
| 2894 | if (phone != null) { |
| 2895 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2896 | } |
| 2897 | } finally { |
| 2898 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2899 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2903 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2906 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2907 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2908 | |
| 2909 | final long identity = Binder.clearCallingIdentity(); |
| 2910 | try { |
| 2911 | final Phone phone = getPhone(subId); |
| 2912 | if (phone == null) { |
| 2913 | return false; |
| 2914 | } |
| 2915 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2916 | toggleRadioOnOffForSubscriber(subId); |
| 2917 | } |
| 2918 | return true; |
| 2919 | } finally { |
| 2920 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2921 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2922 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2923 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2924 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2925 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2926 | /* |
| 2927 | * If any of the Radios are available, it will need to be |
| 2928 | * shutdown. So return true if any Radio is available. |
| 2929 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2930 | final long identity = Binder.clearCallingIdentity(); |
| 2931 | try { |
| 2932 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2933 | Phone phone = PhoneFactory.getPhone(i); |
| 2934 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2935 | } |
| 2936 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2937 | return false; |
| 2938 | } finally { |
| 2939 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2940 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2943 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2944 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2945 | enforceModifyPermission(); |
| 2946 | |
| 2947 | final long identity = Binder.clearCallingIdentity(); |
| 2948 | try { |
| 2949 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2950 | logv("Shutting down Phone " + i); |
| 2951 | shutdownRadioUsingPhoneId(i); |
| 2952 | } |
| 2953 | } finally { |
| 2954 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2959 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2960 | if (phone != null && phone.isRadioAvailable()) { |
| 2961 | phone.shutdownRadio(); |
| 2962 | } |
| 2963 | } |
| 2964 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2965 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2966 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2967 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2968 | if (!turnOn) { |
| 2969 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 2970 | } |
| 2971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2975 | if (defaultPhone != null) { |
| 2976 | defaultPhone.setRadioPower(turnOn); |
| 2977 | return true; |
| 2978 | } else { |
| 2979 | loge("There's no default phone."); |
| 2980 | return false; |
| 2981 | } |
| 2982 | } finally { |
| 2983 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2984 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2987 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2988 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2989 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2990 | if (!turnOn) { |
| 2991 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 2992 | + ",callingPackage=" + getCurrentPackageName()); |
| 2993 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2994 | final long identity = Binder.clearCallingIdentity(); |
| 2995 | try { |
| 2996 | final Phone phone = getPhone(subId); |
| 2997 | if (phone != null) { |
| 2998 | phone.setRadioPower(turnOn); |
| 2999 | return true; |
| 3000 | } else { |
| 3001 | return false; |
| 3002 | } |
| 3003 | } finally { |
| 3004 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3005 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3008 | /** |
| 3009 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3010 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3011 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3012 | * powering it off, and these radio off votes will be cleared. |
| 3013 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3014 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3015 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3016 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3017 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3018 | * check its vote. |
| 3019 | * |
| 3020 | * @param subId The subscription ID. |
| 3021 | * @param reason The reason for powering off radio. |
| 3022 | * @return true on success and false on failure. |
| 3023 | */ |
| 3024 | public boolean requestRadioPowerOffForReason(int subId, |
| 3025 | @TelephonyManager.RadioPowerReason int reason) { |
| 3026 | enforceModifyPermission(); |
| 3027 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3028 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3029 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3030 | final long identity = Binder.clearCallingIdentity(); |
| 3031 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3032 | boolean result = false; |
| 3033 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3034 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3035 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3036 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3037 | if (!result) { |
| 3038 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3039 | } |
| 3040 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | /** |
| 3047 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3048 | * {@link requestRadioPowerOffForReason}. |
| 3049 | * |
| 3050 | * @param subId The subscription ID. |
| 3051 | * @param reason The reason for powering off radio. |
| 3052 | * @return true on success and false on failure. |
| 3053 | */ |
| 3054 | public boolean clearRadioPowerOffForReason(int subId, |
| 3055 | @TelephonyManager.RadioPowerReason int reason) { |
| 3056 | enforceModifyPermission(); |
| 3057 | |
| 3058 | final long identity = Binder.clearCallingIdentity(); |
| 3059 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3060 | boolean result = false; |
| 3061 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3062 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3063 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3064 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3065 | if (!result) { |
| 3066 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3067 | } |
| 3068 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
| 3071 | } |
| 3072 | } |
| 3073 | |
| 3074 | /** |
| 3075 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3076 | * |
| 3077 | * @param subId The subscription ID. |
| 3078 | * @param callingPackage The package making the call. |
| 3079 | * @param callingFeatureId The feature in the package. |
| 3080 | * @return List of reasons for powering off radio. |
| 3081 | */ |
| 3082 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3083 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3084 | |
| 3085 | final long identity = Binder.clearCallingIdentity(); |
| 3086 | List result = new ArrayList(); |
| 3087 | try { |
| 3088 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3089 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3090 | return result; |
| 3091 | } |
| 3092 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3093 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3094 | if (phone != null) { |
| 3095 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3096 | } else { |
| 3097 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3098 | } |
| 3099 | } finally { |
| 3100 | Binder.restoreCallingIdentity(identity); |
| 3101 | } |
| 3102 | return result; |
| 3103 | } |
| 3104 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3105 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3106 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3107 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3108 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3109 | |
| 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3112 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | final Phone phone = getPhone(subId); |
| 3114 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3115 | phone.getDataSettingsManager().setDataEnabled( |
| 3116 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3117 | return true; |
| 3118 | } else { |
| 3119 | return false; |
| 3120 | } |
| 3121 | } finally { |
| 3122 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3123 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3126 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3127 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3128 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3129 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3130 | |
| 3131 | final long identity = Binder.clearCallingIdentity(); |
| 3132 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3133 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3134 | final Phone phone = getPhone(subId); |
| 3135 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3136 | phone.getDataSettingsManager().setDataEnabled( |
| 3137 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3138 | return true; |
| 3139 | } else { |
| 3140 | return false; |
| 3141 | } |
| 3142 | } finally { |
| 3143 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3144 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3147 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3148 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | try { |
| 3151 | final Phone phone = getPhone(subId); |
| 3152 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3153 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3154 | } else { |
| 3155 | return false; |
| 3156 | } |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3159 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3163 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3166 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3167 | enforceCallPermission(); |
| 3168 | |
| 3169 | final long identity = Binder.clearCallingIdentity(); |
| 3170 | try { |
| 3171 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3172 | return; |
| 3173 | } |
| 3174 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3175 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3176 | } finally { |
| 3177 | Binder.restoreCallingIdentity(identity); |
| 3178 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3179 | }; |
| 3180 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3181 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3182 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3183 | |
| 3184 | final long identity = Binder.clearCallingIdentity(); |
| 3185 | try { |
| 3186 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3187 | return false; |
| 3188 | } |
| 3189 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3190 | } finally { |
| 3191 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3192 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3195 | /** |
| 3196 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3197 | * tag on getCallState Binder call. |
| 3198 | */ |
| 3199 | @Deprecated |
| 3200 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3201 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3202 | if (CompatChanges.isChangeEnabled( |
| 3203 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3204 | Binder.getCallingUid())) { |
| 3205 | // Do not allow this API to be called on API version 31+, it should only be |
| 3206 | // called on old apps using this Binder call directly. |
| 3207 | throw new SecurityException("This method can only be used for applications " |
| 3208 | + "targeting API version 30 or less."); |
| 3209 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3212 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3213 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(identity); |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | @Override |
| 3220 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3221 | if (CompatChanges.isChangeEnabled( |
| 3222 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3223 | Binder.getCallingUid())) { |
| 3224 | // Check READ_PHONE_STATE for API version 31+ |
| 3225 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3226 | featureId, "getCallStateForSubscription")) { |
| 3227 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3228 | + "targeting API level 31+."); |
| 3229 | } |
| 3230 | } |
| 3231 | final long identity = Binder.clearCallingIdentity(); |
| 3232 | try { |
| 3233 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3234 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3235 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3236 | } finally { |
| 3237 | Binder.restoreCallingIdentity(identity); |
| 3238 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3241 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3242 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3243 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | @Override |
| 3247 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | final long identity = Binder.clearCallingIdentity(); |
| 3249 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3250 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3252 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3253 | } else { |
| 3254 | return PhoneConstantConversions.convertDataState( |
| 3255 | PhoneConstants.DataState.DISCONNECTED); |
| 3256 | } |
| 3257 | } finally { |
| 3258 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3259 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3262 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3263 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3264 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3268 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3269 | final long identity = Binder.clearCallingIdentity(); |
| 3270 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3271 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3273 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | } else { |
| 3275 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3276 | } |
| 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3283 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3284 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3285 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3286 | |
| 3287 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3288 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3289 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3290 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3291 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3292 | .setCallingPid(Binder.getCallingPid()) |
| 3293 | .setCallingUid(Binder.getCallingUid()) |
| 3294 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3295 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3296 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3297 | .build()); |
| 3298 | switch (locationResult) { |
| 3299 | case DENIED_HARD: |
| 3300 | throw new SecurityException("Not allowed to access cell location"); |
| 3301 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3302 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3303 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3306 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3307 | final long identity = Binder.clearCallingIdentity(); |
| 3308 | try { |
| 3309 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3310 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3311 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3312 | } finally { |
| 3313 | Binder.restoreCallingIdentity(identity); |
| 3314 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3317 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3318 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3319 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3320 | // registered cell info, so return a NULL country instead. |
| 3321 | final long identity = Binder.clearCallingIdentity(); |
| 3322 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3323 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3324 | // Get default phone in this case. |
| 3325 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3326 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3327 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3328 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3329 | if (phone == null) return ""; |
| 3330 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3331 | if (sst == null) return ""; |
| 3332 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3333 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3334 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(identity); |
| 3337 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3338 | } |
| 3339 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3340 | /** |
| 3341 | * This method was removed due to potential issues caused by performing partial |
| 3342 | * updates of service state, and lack of a credible use case. |
| 3343 | * |
| 3344 | * This has the ability to break the telephony implementation by disabling notification of |
| 3345 | * changes in device connectivity. DO NOT USE THIS! |
| 3346 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3347 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3348 | public void enableLocationUpdates() { |
| 3349 | mApp.enforceCallingOrSelfPermission( |
| 3350 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3351 | } |
| 3352 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3353 | /** |
| 3354 | * This method was removed due to potential issues caused by performing partial |
| 3355 | * updates of service state, and lack of a credible use case. |
| 3356 | * |
| 3357 | * This has the ability to break the telephony implementation by disabling notification of |
| 3358 | * changes in device connectivity. DO NOT USE THIS! |
| 3359 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3360 | @Override |
| 3361 | public void disableLocationUpdates() { |
| 3362 | mApp.enforceCallingOrSelfPermission( |
| 3363 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | @Override |
| 3367 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3368 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3369 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3370 | try { |
| 3371 | mApp.getSystemService(AppOpsManager.class) |
| 3372 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3373 | } catch (SecurityException e) { |
| 3374 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3375 | throw e; |
| 3376 | } |
| 3377 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3378 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3379 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3380 | throw new SecurityException( |
| 3381 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3382 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3383 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3384 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3385 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3386 | return null; |
| 3387 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3388 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3389 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3390 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3391 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3392 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3393 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3394 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3395 | for (CellInfo ci : info) { |
| 3396 | if (ci instanceof CellInfoGsm) { |
| 3397 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3398 | } else if (ci instanceof CellInfoWcdma) { |
| 3399 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3400 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3401 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3402 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3405 | private List<CellInfo> getCachedCellInfo() { |
| 3406 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3407 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3408 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3409 | if (info != null) cellInfos.addAll(info); |
| 3410 | } |
| 3411 | return cellInfos; |
| 3412 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3413 | |
| 3414 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3415 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3416 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3417 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3418 | |
| 3419 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3420 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3421 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3422 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3423 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3424 | .setCallingPid(Binder.getCallingPid()) |
| 3425 | .setCallingUid(Binder.getCallingUid()) |
| 3426 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3427 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3428 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3429 | .build()); |
| 3430 | switch (locationResult) { |
| 3431 | case DENIED_HARD: |
| 3432 | throw new SecurityException("Not allowed to access cell info"); |
| 3433 | case DENIED_SOFT: |
| 3434 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3437 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3438 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3439 | return getCachedCellInfo(); |
| 3440 | } |
| 3441 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3442 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3443 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
| 3446 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3447 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3448 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3449 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3450 | if (info != null) cellInfos.addAll(info); |
| 3451 | } |
| 3452 | return cellInfos; |
| 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3455 | } |
| 3456 | } |
| 3457 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3458 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3459 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3460 | String callingFeatureId) { |
| 3461 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3462 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3466 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3467 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3468 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3469 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3472 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3473 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3474 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3475 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3476 | |
| 3477 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3478 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3479 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3480 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3481 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3482 | .setCallingPid(Binder.getCallingPid()) |
| 3483 | .setCallingUid(Binder.getCallingUid()) |
| 3484 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3485 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3486 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3487 | .build()); |
| 3488 | switch (locationResult) { |
| 3489 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3490 | if (TelephonyPermissions |
| 3491 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3492 | // Safetynet logging for b/154934934 |
| 3493 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3494 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3495 | throw new SecurityException("Not allowed to access cell info"); |
| 3496 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3497 | if (TelephonyPermissions |
| 3498 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3499 | // Safetynet logging for b/154934934 |
| 3500 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3501 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3502 | try { |
| 3503 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3504 | } catch (RemoteException re) { |
| 3505 | // Drop without consequences |
| 3506 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3507 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3510 | |
| 3511 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3512 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3513 | |
| 3514 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3515 | } |
| 3516 | |
| 3517 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3518 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3519 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3520 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3521 | |
| 3522 | final long identity = Binder.clearCallingIdentity(); |
| 3523 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3524 | Phone phone = getPhone(subId); |
| 3525 | if (phone == null) { |
| 3526 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3527 | } else { |
| 3528 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3530 | } finally { |
| 3531 | Binder.restoreCallingIdentity(identity); |
| 3532 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3533 | } |
| 3534 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3535 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3536 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3537 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3538 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3539 | return null; |
| 3540 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3541 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3542 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3543 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3544 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3545 | return null; |
| 3546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3547 | |
| 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | return phone.getImei(); |
| 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
| 3553 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3557 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3558 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3559 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3560 | callingFeatureId, "getPrimaryImei")) { |
| 3561 | throw new SecurityException("Caller does not have permission"); |
| 3562 | } |
| 3563 | final long identity = Binder.clearCallingIdentity(); |
| 3564 | try { |
| 3565 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3566 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3567 | return phone.getImei(); |
| 3568 | } |
| 3569 | } |
| 3570 | throw new UnsupportedOperationException("Operation not supported"); |
| 3571 | } finally { |
| 3572 | Binder.restoreCallingIdentity(identity); |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3577 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3578 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3579 | String tac = null; |
| 3580 | if (phone != null) { |
| 3581 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3582 | try { |
| 3583 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3584 | } catch (IndexOutOfBoundsException e) { |
| 3585 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3586 | return null; |
| 3587 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3588 | } |
| 3589 | return tac; |
| 3590 | } |
| 3591 | |
| 3592 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3593 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3594 | try { |
| 3595 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3596 | } catch (SecurityException se) { |
| 3597 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3598 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3599 | + Binder.getCallingUid()); |
| 3600 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3601 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3602 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3603 | return null; |
| 3604 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3605 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3606 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3607 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3608 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3609 | return null; |
| 3610 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3611 | |
| 3612 | final long identity = Binder.clearCallingIdentity(); |
| 3613 | try { |
| 3614 | return phone.getMeid(); |
| 3615 | } finally { |
| 3616 | Binder.restoreCallingIdentity(identity); |
| 3617 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3621 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3622 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3623 | String manufacturerCode = null; |
| 3624 | if (phone != null) { |
| 3625 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3626 | try { |
| 3627 | manufacturerCode = |
| 3628 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3629 | } catch (IndexOutOfBoundsException e) { |
| 3630 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3631 | return null; |
| 3632 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3633 | } |
| 3634 | return manufacturerCode; |
| 3635 | } |
| 3636 | |
| 3637 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3638 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3639 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3640 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3641 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3642 | return null; |
| 3643 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3644 | int subId = phone.getSubId(); |
| 3645 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3646 | mApp, subId, callingPackage, callingFeatureId, |
| 3647 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3648 | return null; |
| 3649 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3650 | |
| 3651 | final long identity = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | return phone.getDeviceSvn(); |
| 3654 | } finally { |
| 3655 | Binder.restoreCallingIdentity(identity); |
| 3656 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3659 | @Override |
| 3660 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
| 3663 | final Phone phone = getPhone(subId); |
| 3664 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3665 | } finally { |
| 3666 | Binder.restoreCallingIdentity(identity); |
| 3667 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | @Override |
| 3671 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3672 | final long identity = Binder.clearCallingIdentity(); |
| 3673 | try { |
| 3674 | final Phone phone = getPhone(subId); |
| 3675 | return phone == null ? null : phone.getCarrierName(); |
| 3676 | } finally { |
| 3677 | Binder.restoreCallingIdentity(identity); |
| 3678 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3679 | } |
| 3680 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3681 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3682 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3683 | final long identity = Binder.clearCallingIdentity(); |
| 3684 | try { |
| 3685 | final Phone phone = getPhone(subId); |
| 3686 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3687 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(identity); |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3694 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3695 | final long identity = Binder.clearCallingIdentity(); |
| 3696 | try { |
| 3697 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3698 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
| 3701 | } |
| 3702 | } |
| 3703 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3704 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3705 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3706 | if (!isSubscriptionMccMnc) { |
| 3707 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3708 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3709 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3710 | if (phone == null) { |
| 3711 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3712 | } |
| 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3716 | } finally { |
| 3717 | Binder.restoreCallingIdentity(identity); |
| 3718 | } |
| 3719 | } |
| 3720 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3721 | // |
| 3722 | // Internal helper methods. |
| 3723 | // |
| 3724 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3725 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3726 | * Make sure the caller is the calling package itself |
| 3727 | * |
| 3728 | * @throws SecurityException if the caller is not the calling package |
| 3729 | */ |
| 3730 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3731 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3732 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3733 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3734 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3735 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3736 | } catch (PackageManager.NameNotFoundException e) { |
| 3737 | // packageUid is -1 |
| 3738 | } |
| 3739 | if (packageUid != callingUid) { |
| 3740 | throw new SecurityException(message + ": Package " + callingPackage |
| 3741 | + " does not belong to " + callingUid); |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3746 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3747 | * |
| 3748 | * @throws SecurityException if the caller does not have the required permission |
| 3749 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3750 | @VisibleForTesting |
| 3751 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3752 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3753 | } |
| 3754 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3755 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3756 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3757 | * |
| 3758 | * @throws SecurityException if the caller does not have the required permission |
| 3759 | */ |
| 3760 | @VisibleForTesting |
| 3761 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3762 | enforceReadPermission(null); |
| 3763 | } |
| 3764 | |
| 3765 | /** |
| 3766 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3767 | * |
| 3768 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3769 | */ |
| 3770 | @VisibleForTesting |
| 3771 | public void enforceReadPermission(String msg) { |
| 3772 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3775 | private void enforceActiveEmergencySessionPermission() { |
| 3776 | mApp.enforceCallingOrSelfPermission( |
| 3777 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3778 | } |
| 3779 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3780 | /** |
| 3781 | * Make sure the caller has the CALL_PHONE permission. |
| 3782 | * |
| 3783 | * @throws SecurityException if the caller does not have the required permission |
| 3784 | */ |
| 3785 | private void enforceCallPermission() { |
| 3786 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3787 | } |
| 3788 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3789 | private void enforceSettingsPermission() { |
| 3790 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3791 | } |
| 3792 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3793 | private void enforceRebootPermission() { |
| 3794 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3795 | } |
| 3796 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3797 | /** |
| 3798 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3799 | * @param message - log message to print. |
| 3800 | * @throws SecurityException if the caller does not have the required permission |
| 3801 | */ |
| 3802 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3803 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3804 | } |
| 3805 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3806 | private String createTelUrl(String number) { |
| 3807 | if (TextUtils.isEmpty(number)) { |
| 3808 | return null; |
| 3809 | } |
| 3810 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3811 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3814 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3815 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3818 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3819 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3822 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3823 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3826 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3827 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3828 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3831 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3832 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3833 | final long identity = Binder.clearCallingIdentity(); |
| 3834 | try { |
| 3835 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3836 | if (phone == null) { |
| 3837 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3838 | } else { |
| 3839 | return phone.getPhoneType(); |
| 3840 | } |
| 3841 | } finally { |
| 3842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3843 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3844 | } |
| 3845 | |
| 3846 | /** |
| 3847 | * Returns the CDMA ERI icon index to display |
| 3848 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3849 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3850 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3851 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3852 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3853 | } |
| 3854 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3855 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3856 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3857 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3858 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3859 | mApp, subId, callingPackage, callingFeatureId, |
| 3860 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3861 | return -1; |
| 3862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | |
| 3864 | final long identity = Binder.clearCallingIdentity(); |
| 3865 | try { |
| 3866 | final Phone phone = getPhone(subId); |
| 3867 | if (phone != null) { |
| 3868 | return phone.getCdmaEriIconIndex(); |
| 3869 | } else { |
| 3870 | return -1; |
| 3871 | } |
| 3872 | } finally { |
| 3873 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | /** |
| 3878 | * Returns the CDMA ERI icon mode, |
| 3879 | * 0 - ON |
| 3880 | * 1 - FLASHING |
| 3881 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3882 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3883 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3884 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3885 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3888 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3889 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3890 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3891 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3892 | mApp, subId, callingPackage, callingFeatureId, |
| 3893 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3894 | return -1; |
| 3895 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3896 | |
| 3897 | final long identity = Binder.clearCallingIdentity(); |
| 3898 | try { |
| 3899 | final Phone phone = getPhone(subId); |
| 3900 | if (phone != null) { |
| 3901 | return phone.getCdmaEriIconMode(); |
| 3902 | } else { |
| 3903 | return -1; |
| 3904 | } |
| 3905 | } finally { |
| 3906 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3907 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | /** |
| 3911 | * Returns the CDMA ERI text, |
| 3912 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3913 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3914 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3915 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3916 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3917 | } |
| 3918 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3919 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3920 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3921 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3922 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3923 | mApp, subId, callingPackage, callingFeatureId, |
| 3924 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3925 | return null; |
| 3926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | |
| 3928 | final long identity = Binder.clearCallingIdentity(); |
| 3929 | try { |
| 3930 | final Phone phone = getPhone(subId); |
| 3931 | if (phone != null) { |
| 3932 | return phone.getCdmaEriText(); |
| 3933 | } else { |
| 3934 | return null; |
| 3935 | } |
| 3936 | } finally { |
| 3937 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3938 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3942 | * Returns the CDMA MDN. |
| 3943 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3944 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3945 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3946 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3947 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3948 | |
| 3949 | final long identity = Binder.clearCallingIdentity(); |
| 3950 | try { |
| 3951 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3952 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3953 | return phone.getLine1Number(); |
| 3954 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3955 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3956 | return null; |
| 3957 | } |
| 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | /** |
| 3964 | * Returns the CDMA MIN. |
| 3965 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3966 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3967 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3969 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3970 | |
| 3971 | final long identity = Binder.clearCallingIdentity(); |
| 3972 | try { |
| 3973 | final Phone phone = getPhone(subId); |
| 3974 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3975 | return phone.getCdmaMin(); |
| 3976 | } else { |
| 3977 | return null; |
| 3978 | } |
| 3979 | } finally { |
| 3980 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3984 | @Override |
| 3985 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3986 | INumberVerificationCallback callback, String callingPackage) { |
| 3987 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3988 | != PERMISSION_GRANTED) { |
| 3989 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3990 | } |
| 3991 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3992 | |
| 3993 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3994 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3995 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3996 | + "calling package: " + callingPackage |
| 3997 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3998 | } |
| 3999 | |
| 4000 | if (range == null) { |
| 4001 | throw new NullPointerException("Range must be non-null"); |
| 4002 | } |
| 4003 | |
| 4004 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4005 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4006 | |
| 4007 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4008 | } |
| 4009 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4010 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4011 | * Returns true if CDMA provisioning needs to run. |
| 4012 | */ |
| 4013 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4014 | final long identity = Binder.clearCallingIdentity(); |
| 4015 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4016 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | } finally { |
| 4018 | Binder.restoreCallingIdentity(identity); |
| 4019 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4023 | * Sets the voice mail number of a given subId. |
| 4024 | */ |
| 4025 | @Override |
| 4026 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4027 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4028 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4029 | |
| 4030 | final long identity = Binder.clearCallingIdentity(); |
| 4031 | try { |
| 4032 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4033 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4034 | return success; |
| 4035 | } finally { |
| 4036 | Binder.restoreCallingIdentity(identity); |
| 4037 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4038 | } |
| 4039 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4040 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4041 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4042 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4043 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4044 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4045 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4046 | throw new SecurityException("caller must be system dialer"); |
| 4047 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | |
| 4049 | final long identity = Binder.clearCallingIdentity(); |
| 4050 | try { |
| 4051 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4052 | if (phoneAccountHandle == null) { |
| 4053 | return null; |
| 4054 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4055 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4058 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4062 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4063 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4064 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4065 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4066 | mApp, subId, callingPackage, callingFeatureId, |
| 4067 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4068 | return null; |
| 4069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4070 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4071 | final long identity = Binder.clearCallingIdentity(); |
| 4072 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4073 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4074 | } finally { |
| 4075 | Binder.restoreCallingIdentity(identity); |
| 4076 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4080 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4081 | VisualVoicemailSmsFilterSettings settings) { |
| 4082 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4083 | |
| 4084 | final long identity = Binder.clearCallingIdentity(); |
| 4085 | try { |
| 4086 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4087 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4088 | } finally { |
| 4089 | Binder.restoreCallingIdentity(identity); |
| 4090 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4094 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4095 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4096 | |
| 4097 | final long identity = Binder.clearCallingIdentity(); |
| 4098 | try { |
| 4099 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4100 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(identity); |
| 4103 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4107 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4108 | String callingPackage, int subId) { |
| 4109 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4110 | |
| 4111 | final long identity = Binder.clearCallingIdentity(); |
| 4112 | try { |
| 4113 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4114 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4115 | } finally { |
| 4116 | Binder.restoreCallingIdentity(identity); |
| 4117 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4121 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4122 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4123 | |
| 4124 | final long identity = Binder.clearCallingIdentity(); |
| 4125 | try { |
| 4126 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4127 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4128 | } finally { |
| 4129 | Binder.restoreCallingIdentity(identity); |
| 4130 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4134 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4135 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4136 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4137 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4138 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4139 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4140 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4141 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4142 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4143 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4144 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4145 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4146 | * Sets the voice activation state of a given subId. |
| 4147 | */ |
| 4148 | @Override |
| 4149 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4151 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4152 | |
| 4153 | final long identity = Binder.clearCallingIdentity(); |
| 4154 | try { |
| 4155 | final Phone phone = getPhone(subId); |
| 4156 | if (phone != null) { |
| 4157 | phone.setVoiceActivationState(activationState); |
| 4158 | } else { |
| 4159 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4160 | } |
| 4161 | } finally { |
| 4162 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | /** |
| 4167 | * Sets the data activation state of a given subId. |
| 4168 | */ |
| 4169 | @Override |
| 4170 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4172 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4173 | |
| 4174 | final long identity = Binder.clearCallingIdentity(); |
| 4175 | try { |
| 4176 | final Phone phone = getPhone(subId); |
| 4177 | if (phone != null) { |
| 4178 | phone.setDataActivationState(activationState); |
| 4179 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4180 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4181 | } |
| 4182 | } finally { |
| 4183 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | /** |
| 4188 | * Returns the voice activation state of a given subId. |
| 4189 | */ |
| 4190 | @Override |
| 4191 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4192 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4193 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4194 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 | final long identity = Binder.clearCallingIdentity(); |
| 4196 | try { |
| 4197 | if (phone != null) { |
| 4198 | return phone.getVoiceActivationState(); |
| 4199 | } else { |
| 4200 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4201 | } |
| 4202 | } finally { |
| 4203 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | /** |
| 4208 | * Returns the data activation state of a given subId. |
| 4209 | */ |
| 4210 | @Override |
| 4211 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4212 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4214 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | final long identity = Binder.clearCallingIdentity(); |
| 4216 | try { |
| 4217 | if (phone != null) { |
| 4218 | return phone.getDataActivationState(); |
| 4219 | } else { |
| 4220 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4221 | } |
| 4222 | } finally { |
| 4223 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4228 | * Returns the unread count of voicemails for a subId |
| 4229 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4230 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4231 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4232 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4233 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4234 | mApp, subId, callingPackage, callingFeatureId, |
| 4235 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4236 | return 0; |
| 4237 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4238 | final long identity = Binder.clearCallingIdentity(); |
| 4239 | try { |
| 4240 | final Phone phone = getPhone(subId); |
| 4241 | if (phone != null) { |
| 4242 | return phone.getVoiceMessageCount(); |
| 4243 | } else { |
| 4244 | return 0; |
| 4245 | } |
| 4246 | } finally { |
| 4247 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4248 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4252 | * returns true, if the device is in a state where both voice and data |
| 4253 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4254 | */ |
| 4255 | @Override |
| 4256 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4257 | final long identity = Binder.clearCallingIdentity(); |
| 4258 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4259 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | } finally { |
| 4261 | Binder.restoreCallingIdentity(identity); |
| 4262 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4266 | * Send the dialer code if called from the current default dialer or the caller has |
| 4267 | * carrier privilege. |
| 4268 | * @param inputCode The dialer code to send |
| 4269 | */ |
| 4270 | @Override |
| 4271 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4272 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4273 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4274 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4275 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4276 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4277 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4278 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4279 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4280 | |
| 4281 | final long identity = Binder.clearCallingIdentity(); |
| 4282 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4283 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4284 | } finally { |
| 4285 | Binder.restoreCallingIdentity(identity); |
| 4286 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4287 | } |
| 4288 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4289 | @Override |
| 4290 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4291 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4292 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4293 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4294 | final long identity = Binder.clearCallingIdentity(); |
| 4295 | try { |
| 4296 | if (!isActiveSubscription(subId)) { |
| 4297 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4298 | } |
| 4299 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4300 | } finally { |
| 4301 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4302 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4303 | } |
| 4304 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4305 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4306 | public boolean isInEmergencySmsMode() { |
| 4307 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4308 | final long identity = Binder.clearCallingIdentity(); |
| 4309 | try { |
| 4310 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4311 | if (phone.isInEmergencySmsMode()) { |
| 4312 | return true; |
| 4313 | } |
| 4314 | } |
| 4315 | } finally { |
| 4316 | Binder.restoreCallingIdentity(identity); |
| 4317 | } |
| 4318 | return false; |
| 4319 | } |
| 4320 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4321 | /** |
| 4322 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4323 | * @param subId The subscription to use to check the configuration. |
| 4324 | * @param c The callback that will be used to send the result. |
| 4325 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4326 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4327 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4328 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4329 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4330 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4331 | |
| 4332 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4333 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4334 | "IMS not available on device."); |
| 4335 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4336 | final long token = Binder.clearCallingIdentity(); |
| 4337 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4338 | int slotId = getSlotIndexOrException(subId); |
| 4339 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4340 | |
| 4341 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4342 | if (controller != null) { |
| 4343 | ImsManager imsManager = controller.getImsManager(subId); |
| 4344 | if (imsManager != null) { |
| 4345 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4346 | } else { |
| 4347 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4348 | } |
| 4349 | } else { |
| 4350 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4351 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4352 | } catch (ImsException e) { |
| 4353 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4354 | } finally { |
| 4355 | Binder.restoreCallingIdentity(token); |
| 4356 | } |
| 4357 | } |
| 4358 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4359 | /** |
| 4360 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4361 | * @param subId The subscription to use to check the configuration. |
| 4362 | * @param c The callback that will be used to send the result. |
| 4363 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4364 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4365 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4366 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4367 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4368 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4369 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4370 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4371 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4372 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4373 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4374 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4375 | if (controller != null) { |
| 4376 | ImsManager imsManager = controller.getImsManager(subId); |
| 4377 | if (imsManager != null) { |
| 4378 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4379 | } else { |
| 4380 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4381 | + "is inactive, ignoring unregister."); |
| 4382 | // If the ImsManager is not valid, just return, since the callback |
| 4383 | // will already have been removed internally. |
| 4384 | } |
| 4385 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4386 | } finally { |
| 4387 | Binder.restoreCallingIdentity(token); |
| 4388 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4391 | /** |
| 4392 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4393 | */ |
| 4394 | @Override |
| 4395 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4396 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4397 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4398 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4399 | "IMS not available on device."); |
| 4400 | } |
| 4401 | final long token = Binder.clearCallingIdentity(); |
| 4402 | try { |
| 4403 | Phone phone = getPhone(subId); |
| 4404 | if (phone == null) { |
| 4405 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4406 | + subId + "'"); |
| 4407 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4408 | } |
| 4409 | phone.getImsRegistrationState(regState -> { |
| 4410 | try { |
| 4411 | consumer.accept((regState == null) |
| 4412 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4413 | } catch (RemoteException e) { |
| 4414 | // Ignore if the remote process is no longer available to call back. |
| 4415 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4416 | } |
| 4417 | }); |
| 4418 | } finally { |
| 4419 | Binder.restoreCallingIdentity(token); |
| 4420 | } |
| 4421 | } |
| 4422 | |
| 4423 | /** |
| 4424 | * Get the transport type for the IMS service registration state. |
| 4425 | */ |
| 4426 | @Override |
| 4427 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4428 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4429 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4430 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4431 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4432 | "IMS not available on device."); |
| 4433 | } |
| 4434 | final long token = Binder.clearCallingIdentity(); |
| 4435 | try { |
| 4436 | Phone phone = getPhone(subId); |
| 4437 | if (phone == null) { |
| 4438 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4439 | + subId + "'"); |
| 4440 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4441 | } |
| 4442 | phone.getImsRegistrationTech(regTech -> { |
| 4443 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4444 | int regTechConverted = (regTech == null) |
| 4445 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4446 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4447 | regTechConverted); |
| 4448 | try { |
| 4449 | consumer.accept(regTechConverted); |
| 4450 | } catch (RemoteException e) { |
| 4451 | // Ignore if the remote process is no longer available to call back. |
| 4452 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4453 | } |
| 4454 | }); |
| 4455 | } finally { |
| 4456 | Binder.restoreCallingIdentity(token); |
| 4457 | } |
| 4458 | } |
| 4459 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4460 | /** |
| 4461 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4462 | * @param subId The subscription to use to check the configuration. |
| 4463 | * @param c The callback that will be used to send the result. |
| 4464 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4465 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4466 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4467 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4468 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4469 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4470 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4471 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4472 | "IMS not available on device."); |
| 4473 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4474 | final long token = Binder.clearCallingIdentity(); |
| 4475 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4476 | int slotId = getSlotIndexOrException(subId); |
| 4477 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4478 | |
| 4479 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4480 | if (controller != null) { |
| 4481 | ImsManager imsManager = controller.getImsManager(subId); |
| 4482 | if (imsManager != null) { |
| 4483 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4484 | } else { |
| 4485 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4486 | } |
| 4487 | } else { |
| 4488 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4489 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4490 | } catch (ImsException e) { |
| 4491 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4492 | } finally { |
| 4493 | Binder.restoreCallingIdentity(token); |
| 4494 | } |
| 4495 | } |
| 4496 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4497 | /** |
| 4498 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4499 | * @param subId The subscription to use to check the configuration. |
| 4500 | * @param c The callback that will be used to send the result. |
| 4501 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4502 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4503 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4504 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4505 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4506 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4507 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4508 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4509 | |
| 4510 | final long token = Binder.clearCallingIdentity(); |
| 4511 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4512 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4513 | if (controller != null) { |
| 4514 | ImsManager imsManager = controller.getImsManager(subId); |
| 4515 | if (imsManager != null) { |
| 4516 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4517 | } else { |
| 4518 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4519 | + " is inactive, ignoring unregister."); |
| 4520 | // If the ImsManager is not valid, just return, since the callback |
| 4521 | // will already have been removed internally. |
| 4522 | } |
| 4523 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(token); |
| 4526 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4530 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4531 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4532 | final long token = Binder.clearCallingIdentity(); |
| 4533 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4534 | int slotId = getSlotIndexOrException(subId); |
| 4535 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4536 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4537 | } catch (com.android.ims.ImsException e) { |
| 4538 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4539 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4540 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4541 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4542 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4543 | } finally { |
| 4544 | Binder.restoreCallingIdentity(token); |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4549 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4550 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4551 | final long token = Binder.clearCallingIdentity(); |
| 4552 | try { |
| 4553 | Phone phone = getPhone(subId); |
| 4554 | if (phone == null) return false; |
| 4555 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4556 | } catch (com.android.ims.ImsException e) { |
| 4557 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4558 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4559 | } finally { |
| 4560 | Binder.restoreCallingIdentity(token); |
| 4561 | } |
| 4562 | } |
| 4563 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4564 | /** |
| 4565 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4566 | * subscription. |
| 4567 | * @param subId The subscription to use to check the configuration. |
| 4568 | * @param callback The callback that will be used to send the result. |
| 4569 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4570 | * @param transportType The transport type of the MmTelFeature capability. |
| 4571 | */ |
| 4572 | @Override |
| 4573 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4574 | int transportType) { |
| 4575 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4576 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4577 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4578 | "IMS not available on device."); |
| 4579 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4580 | final long token = Binder.clearCallingIdentity(); |
| 4581 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4582 | int slotId = getSlotIndex(subId); |
| 4583 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4584 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4585 | + subId + "'"); |
| 4586 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4587 | } |
| 4588 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4589 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4590 | transportType, aBoolean -> { |
| 4591 | try { |
| 4592 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4593 | } catch (RemoteException e) { |
| 4594 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4595 | + "running. Ignore"); |
| 4596 | } |
| 4597 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4598 | } catch (ImsException e) { |
| 4599 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4600 | } finally { |
| 4601 | Binder.restoreCallingIdentity(token); |
| 4602 | } |
| 4603 | } |
| 4604 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4605 | /** |
| 4606 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4607 | * @param subId The subscription to use to check the configuration. |
| 4608 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4609 | @Override |
| 4610 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4611 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4612 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4613 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4614 | final long token = Binder.clearCallingIdentity(); |
| 4615 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4616 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4617 | // 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] | 4618 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4619 | } catch (ImsException e) { |
| 4620 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(token); |
| 4623 | } |
| 4624 | } |
| 4625 | |
| 4626 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4627 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4629 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4630 | final long identity = Binder.clearCallingIdentity(); |
| 4631 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4632 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4633 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4634 | // 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] | 4635 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4636 | } catch (ImsException e) { |
| 4637 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4638 | } finally { |
| 4639 | Binder.restoreCallingIdentity(identity); |
| 4640 | } |
| 4641 | } |
| 4642 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4643 | /** |
| 4644 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4645 | * @param subId The subscription to use to check the configuration. |
| 4646 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4647 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4648 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4649 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4650 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4651 | final long identity = Binder.clearCallingIdentity(); |
| 4652 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4653 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4654 | // 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] | 4655 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4656 | } catch (ImsException e) { |
| 4657 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4658 | } finally { |
| 4659 | Binder.restoreCallingIdentity(identity); |
| 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4664 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4666 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4667 | final long identity = Binder.clearCallingIdentity(); |
| 4668 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4669 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4670 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4671 | // 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] | 4672 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4673 | } catch (ImsException e) { |
| 4674 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4675 | } finally { |
| 4676 | Binder.restoreCallingIdentity(identity); |
| 4677 | } |
| 4678 | } |
| 4679 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4680 | /** |
| 4681 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4682 | * @param subId The subscription to use to check the configuration. |
| 4683 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4684 | @Override |
| 4685 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4686 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4687 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4688 | final long identity = Binder.clearCallingIdentity(); |
| 4689 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4690 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4691 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4692 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4693 | } catch (ImsException e) { |
| 4694 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4695 | } finally { |
| 4696 | Binder.restoreCallingIdentity(identity); |
| 4697 | } |
| 4698 | } |
| 4699 | |
| 4700 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4701 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4702 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4703 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4704 | final long identity = Binder.clearCallingIdentity(); |
| 4705 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4706 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4707 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4708 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4709 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4710 | } catch (ImsException e) { |
| 4711 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4712 | } finally { |
| 4713 | Binder.restoreCallingIdentity(identity); |
| 4714 | } |
| 4715 | } |
| 4716 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4717 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4718 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4719 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4720 | * @param subId The subscription to use to check the configuration. |
| 4721 | */ |
| 4722 | @Override |
| 4723 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4724 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4725 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4726 | final long identity = Binder.clearCallingIdentity(); |
| 4727 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4728 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4729 | // 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] | 4730 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4731 | } catch (ImsException e) { |
| 4732 | throw new ServiceSpecificException(e.getCode()); |
| 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(identity); |
| 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | /** |
| 4739 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4740 | * Requires MODIFY_PHONE_STATE permission. |
| 4741 | * @param subId The subscription to use to check the configuration. |
| 4742 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4743 | * false otherwise |
| 4744 | */ |
| 4745 | @Override |
| 4746 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4748 | "setCrossSimCallingEnabled"); |
| 4749 | final long identity = Binder.clearCallingIdentity(); |
| 4750 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4751 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4752 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4753 | // 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] | 4754 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4755 | } catch (ImsException e) { |
| 4756 | throw new ServiceSpecificException(e.getCode()); |
| 4757 | } finally { |
| 4758 | Binder.restoreCallingIdentity(identity); |
| 4759 | } |
| 4760 | } |
| 4761 | |
| 4762 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4763 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4764 | * @param subId The subscription to use to check the configuration. |
| 4765 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4766 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4767 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4768 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4769 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4770 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4771 | final long identity = Binder.clearCallingIdentity(); |
| 4772 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4773 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4774 | // 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] | 4775 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4776 | } catch (ImsException e) { |
| 4777 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4778 | } finally { |
| 4779 | Binder.restoreCallingIdentity(identity); |
| 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4784 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4786 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4787 | final long identity = Binder.clearCallingIdentity(); |
| 4788 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4789 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4790 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4791 | // 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] | 4792 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4793 | } catch (ImsException e) { |
| 4794 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4795 | } finally { |
| 4796 | Binder.restoreCallingIdentity(identity); |
| 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | @Override |
| 4801 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4802 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4803 | "setVoWiFiNonPersistent"); |
| 4804 | final long identity = Binder.clearCallingIdentity(); |
| 4805 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4806 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4807 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4808 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4809 | } catch (ImsException e) { |
| 4810 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4811 | } finally { |
| 4812 | Binder.restoreCallingIdentity(identity); |
| 4813 | } |
| 4814 | } |
| 4815 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4816 | /** |
| 4817 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4818 | * @param subId The subscription to use to check the configuration. |
| 4819 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4820 | @Override |
| 4821 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4822 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4823 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4824 | final long identity = Binder.clearCallingIdentity(); |
| 4825 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4826 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4827 | // 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] | 4828 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4829 | } catch (ImsException e) { |
| 4830 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(identity); |
| 4833 | } |
| 4834 | } |
| 4835 | |
| 4836 | @Override |
| 4837 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4839 | "setVoWiFiModeSetting"); |
| 4840 | final long identity = Binder.clearCallingIdentity(); |
| 4841 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4842 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4843 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4844 | // 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] | 4845 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4846 | } catch (ImsException e) { |
| 4847 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4848 | } finally { |
| 4849 | Binder.restoreCallingIdentity(identity); |
| 4850 | } |
| 4851 | } |
| 4852 | |
| 4853 | @Override |
| 4854 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4855 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4856 | final long identity = Binder.clearCallingIdentity(); |
| 4857 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4858 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4859 | // 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] | 4860 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4861 | } catch (ImsException e) { |
| 4862 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4863 | } finally { |
| 4864 | Binder.restoreCallingIdentity(identity); |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | @Override |
| 4869 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4870 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4871 | "setVoWiFiRoamingModeSetting"); |
| 4872 | final long identity = Binder.clearCallingIdentity(); |
| 4873 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4874 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4875 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4876 | // 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] | 4877 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4878 | } catch (ImsException e) { |
| 4879 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4880 | } finally { |
| 4881 | Binder.restoreCallingIdentity(identity); |
| 4882 | } |
| 4883 | } |
| 4884 | |
| 4885 | @Override |
| 4886 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4888 | "setRttCapabilityEnabled"); |
| 4889 | final long identity = Binder.clearCallingIdentity(); |
| 4890 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4891 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4892 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4893 | // 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] | 4894 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4895 | } catch (ImsException e) { |
| 4896 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4897 | } finally { |
| 4898 | Binder.restoreCallingIdentity(identity); |
| 4899 | } |
| 4900 | } |
| 4901 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4902 | /** |
| 4903 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4904 | * @param subId The subscription to use to check the configuration. |
| 4905 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4906 | @Override |
| 4907 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4908 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4909 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4910 | final long identity = Binder.clearCallingIdentity(); |
| 4911 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4912 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4913 | // 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] | 4914 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4915 | } catch (ImsException e) { |
| 4916 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4917 | } finally { |
| 4918 | Binder.restoreCallingIdentity(identity); |
| 4919 | } |
| 4920 | } |
| 4921 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4922 | @Override |
| 4923 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4924 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4925 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4926 | final long identity = Binder.clearCallingIdentity(); |
| 4927 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4928 | if (!isImsAvailableOnDevice()) { |
| 4929 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4930 | "IMS not available on device."); |
| 4931 | } |
| 4932 | int slotId = getSlotIndexOrException(subId); |
| 4933 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4934 | |
| 4935 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4936 | if (controller != null) { |
| 4937 | ImsManager imsManager = controller.getImsManager(subId); |
| 4938 | if (imsManager != null) { |
| 4939 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 4940 | } else { |
| 4941 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4942 | } |
| 4943 | } else { |
| 4944 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4945 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4946 | } catch (ImsException e) { |
| 4947 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4948 | } finally { |
| 4949 | Binder.restoreCallingIdentity(identity); |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | @Override |
| 4954 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4955 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4956 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4957 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4958 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4959 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4960 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4961 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4962 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4963 | if (controller != null) { |
| 4964 | ImsManager imsManager = controller.getImsManager(subId); |
| 4965 | if (imsManager != null) { |
| 4966 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 4967 | } else { |
| 4968 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4969 | + " is inactive, ignoring unregister."); |
| 4970 | // If the ImsManager is not valid, just return, since the callback will already |
| 4971 | // have been removed internally. |
| 4972 | } |
| 4973 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4974 | } finally { |
| 4975 | Binder.restoreCallingIdentity(identity); |
| 4976 | } |
| 4977 | } |
| 4978 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4979 | @Override |
| 4980 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4981 | IFeatureProvisioningCallback callback) { |
| 4982 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4983 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4984 | |
| 4985 | final long identity = Binder.clearCallingIdentity(); |
| 4986 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4987 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4988 | } |
| 4989 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4990 | try { |
| 4991 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4992 | if (controller == null) { |
| 4993 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4994 | "Device does not support IMS"); |
| 4995 | } |
| 4996 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4997 | } finally { |
| 4998 | Binder.restoreCallingIdentity(identity); |
| 4999 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | @Override |
| 5003 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5004 | IFeatureProvisioningCallback callback) { |
| 5005 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5006 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5007 | |
| 5008 | final long identity = Binder.clearCallingIdentity(); |
| 5009 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5010 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5011 | } |
| 5012 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5013 | try { |
| 5014 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5015 | if (controller == null) { |
| 5016 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5017 | return; |
| 5018 | } |
| 5019 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5020 | } finally { |
| 5021 | Binder.restoreCallingIdentity(identity); |
| 5022 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5023 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5024 | |
| 5025 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5026 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5027 | message); |
| 5028 | } |
| 5029 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5030 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5031 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5032 | boolean isProvisioned) { |
| 5033 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5034 | |
| 5035 | final long identity = Binder.clearCallingIdentity(); |
| 5036 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5037 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5038 | if (controller == null) { |
| 5039 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5040 | return; |
| 5041 | } |
| 5042 | controller.setRcsProvisioningStatusForCapability( |
| 5043 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5044 | } finally { |
| 5045 | Binder.restoreCallingIdentity(identity); |
| 5046 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5047 | } |
| 5048 | |
| 5049 | |
| 5050 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5051 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5052 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5053 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5054 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5055 | final long identity = Binder.clearCallingIdentity(); |
| 5056 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5057 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5058 | if (controller == null) { |
| 5059 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5060 | |
| 5061 | // device does not support IMS, this method will return true always. |
| 5062 | return true; |
| 5063 | } |
| 5064 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5065 | } finally { |
| 5066 | Binder.restoreCallingIdentity(identity); |
| 5067 | } |
| 5068 | } |
| 5069 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5070 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5071 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5072 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5073 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5074 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5075 | final long identity = Binder.clearCallingIdentity(); |
| 5076 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5077 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5078 | if (controller == null) { |
| 5079 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5080 | return; |
| 5081 | } |
| 5082 | controller.setImsProvisioningStatusForCapability( |
| 5083 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5084 | } finally { |
| 5085 | Binder.restoreCallingIdentity(identity); |
| 5086 | } |
| 5087 | } |
| 5088 | |
| 5089 | @Override |
| 5090 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5091 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5092 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5093 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5094 | final long identity = Binder.clearCallingIdentity(); |
| 5095 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5096 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5097 | if (controller == null) { |
| 5098 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5099 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5100 | // device does not support IMS, this method will return true always. |
| 5101 | return true; |
| 5102 | } |
| 5103 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5104 | } finally { |
| 5105 | Binder.restoreCallingIdentity(identity); |
| 5106 | } |
| 5107 | } |
| 5108 | |
| 5109 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5110 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5111 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5112 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5113 | |
| 5114 | final long identity = Binder.clearCallingIdentity(); |
| 5115 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5116 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5117 | if (controller == null) { |
| 5118 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5119 | |
| 5120 | // device does not support IMS, this method will return false |
| 5121 | return false; |
| 5122 | } |
| 5123 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5124 | } finally { |
| 5125 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5126 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5130 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5131 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5132 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5133 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5134 | final long identity = Binder.clearCallingIdentity(); |
| 5135 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5136 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5137 | if (controller == null) { |
| 5138 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5139 | |
| 5140 | // device does not support IMS, this method will return false |
| 5141 | return false; |
| 5142 | } |
| 5143 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
| 5146 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5147 | } |
| 5148 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5149 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5150 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5151 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5152 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5153 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5154 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5155 | mApp, subId, "getImsProvisioningInt"); |
| 5156 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5157 | final long identity = Binder.clearCallingIdentity(); |
| 5158 | try { |
| 5159 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5160 | int slotId = getSlotIndex(subId); |
| 5161 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5162 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5163 | + subId + "' for key:" + key); |
| 5164 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5165 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5166 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5167 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5168 | if (controller == null) { |
| 5169 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5170 | |
| 5171 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5172 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5173 | } |
| 5174 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5175 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5176 | return retVal; |
| 5177 | } |
| 5178 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5179 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5180 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5181 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5182 | + subId + "' for key:" + key); |
| 5183 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5184 | } finally { |
| 5185 | Binder.restoreCallingIdentity(identity); |
| 5186 | } |
| 5187 | } |
| 5188 | |
| 5189 | @Override |
| 5190 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5191 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5192 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5193 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5194 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5195 | mApp, subId, "getImsProvisioningString"); |
| 5196 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5197 | final long identity = Binder.clearCallingIdentity(); |
| 5198 | try { |
| 5199 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5200 | int slotId = getSlotIndex(subId); |
| 5201 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5202 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5203 | + subId + "' for key:" + key); |
| 5204 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5205 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5206 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5207 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5208 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5209 | + subId + "' for key:" + key); |
| 5210 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5211 | } finally { |
| 5212 | Binder.restoreCallingIdentity(identity); |
| 5213 | } |
| 5214 | } |
| 5215 | |
| 5216 | @Override |
| 5217 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5218 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5219 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5220 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5222 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5223 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5224 | final long identity = Binder.clearCallingIdentity(); |
| 5225 | try { |
| 5226 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5227 | int slotId = getSlotIndex(subId); |
| 5228 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5229 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5230 | + subId + "' for key:" + key); |
| 5231 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5232 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5233 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5234 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5235 | if (controller == null) { |
| 5236 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5237 | |
| 5238 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5239 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5240 | } |
| 5241 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5242 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5243 | return retVal; |
| 5244 | } |
| 5245 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5246 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5247 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5248 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5249 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5250 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5251 | } finally { |
| 5252 | Binder.restoreCallingIdentity(identity); |
| 5253 | } |
| 5254 | } |
| 5255 | |
| 5256 | @Override |
| 5257 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5258 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5259 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5260 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5261 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5262 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5263 | final long identity = Binder.clearCallingIdentity(); |
| 5264 | try { |
| 5265 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5266 | int slotId = getSlotIndex(subId); |
| 5267 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5268 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5269 | + subId + "' for key:" + key); |
| 5270 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5271 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5272 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5273 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5274 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5275 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5276 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5277 | } finally { |
| 5278 | Binder.restoreCallingIdentity(identity); |
| 5279 | } |
| 5280 | } |
| 5281 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5282 | /** |
| 5283 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5284 | * for the given slot ID or no ImsResolver instance has been created. |
| 5285 | * @param slotId The slot ID that the IMS service is created for. |
| 5286 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5287 | */ |
| 5288 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5289 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5290 | ImsFeature.FEATURE_MMTEL)) { |
| 5291 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5292 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5293 | } |
| 5294 | } |
| 5295 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5296 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5297 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5298 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5299 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5300 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5301 | } |
| 5302 | return slotId; |
| 5303 | } |
| 5304 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5305 | private int getSlotIndex(int subId) { |
| 5306 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5307 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5308 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5309 | } |
| 5310 | return slotId; |
| 5311 | } |
| 5312 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5313 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5314 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5315 | */ |
| 5316 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5317 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5318 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5319 | try { |
| 5320 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5321 | } catch (SecurityException se) { |
| 5322 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5323 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5324 | + Binder.getCallingUid()); |
| 5325 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5326 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5327 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5328 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5329 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5330 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5331 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5332 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5333 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5334 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5335 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5336 | final long identity = Binder.clearCallingIdentity(); |
| 5337 | try { |
| 5338 | final Phone phone = getPhone(subId); |
| 5339 | if (phone != null) { |
| 5340 | return phone.getServiceState().getDataNetworkType(); |
| 5341 | } else { |
| 5342 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5343 | } |
| 5344 | } finally { |
| 5345 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5346 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5347 | } |
| 5348 | |
| 5349 | /** |
| 5350 | * Returns the data network type |
| 5351 | */ |
| 5352 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5353 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5354 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5355 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | /** |
| 5359 | * Returns the data network type for a subId |
| 5360 | */ |
| 5361 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5362 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5363 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5364 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5365 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5366 | mApp, functionName)) { |
| 5367 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5368 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5369 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5370 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5371 | } |
| 5372 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5373 | final long identity = Binder.clearCallingIdentity(); |
| 5374 | try { |
| 5375 | final Phone phone = getPhone(subId); |
| 5376 | if (phone != null) { |
| 5377 | return phone.getServiceState().getDataNetworkType(); |
| 5378 | } else { |
| 5379 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5380 | } |
| 5381 | } finally { |
| 5382 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5383 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5387 | * Returns the Voice network type for a subId |
| 5388 | */ |
| 5389 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5390 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5391 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5392 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5393 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5394 | mApp, functionName)) { |
| 5395 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5396 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5397 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5398 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5399 | } |
| 5400 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5401 | final long identity = Binder.clearCallingIdentity(); |
| 5402 | try { |
| 5403 | final Phone phone = getPhone(subId); |
| 5404 | if (phone != null) { |
| 5405 | return phone.getServiceState().getVoiceNetworkType(); |
| 5406 | } else { |
| 5407 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5408 | } |
| 5409 | } finally { |
| 5410 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5411 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | /** |
| 5415 | * @return true if a ICC card is present |
| 5416 | */ |
| 5417 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5418 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5419 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5420 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5424 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5425 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5426 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5427 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | final long identity = Binder.clearCallingIdentity(); |
| 5429 | try { |
| 5430 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5431 | if (phone != null) { |
| 5432 | return phone.getIccCard().hasIccCard(); |
| 5433 | } else { |
| 5434 | return false; |
| 5435 | } |
| 5436 | } finally { |
| 5437 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5438 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | /** |
| 5442 | * Return if the current radio is LTE on CDMA. This |
| 5443 | * is a tri-state return value as for a period of time |
| 5444 | * the mode may be unknown. |
| 5445 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5446 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5447 | * @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] | 5448 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5449 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5450 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5451 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5452 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5453 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5454 | } |
| 5455 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5456 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5457 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5458 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5459 | try { |
| 5460 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5461 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5462 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5463 | } |
| 5464 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
| 5467 | final Phone phone = getPhone(subId); |
| 5468 | if (phone == null) { |
| 5469 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5470 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5471 | return TelephonyProperties.lte_on_cdma_device() |
| 5472 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5473 | } |
| 5474 | } finally { |
| 5475 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5476 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5477 | } |
| 5478 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5479 | /** |
| 5480 | * {@hide} |
| 5481 | * Returns Default subId, 0 in the case of single standby. |
| 5482 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5483 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5484 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5485 | } |
| 5486 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5487 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5488 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5489 | } |
| 5490 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5491 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5492 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5493 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5494 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5495 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5496 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5497 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5498 | } |
| 5499 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5500 | /** |
| 5501 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5502 | */ |
| 5503 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5504 | final long identity = Binder.clearCallingIdentity(); |
| 5505 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5506 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5507 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5508 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5509 | } finally { |
| 5510 | Binder.restoreCallingIdentity(identity); |
| 5511 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5512 | } |
| 5513 | |
| 5514 | /** |
| 5515 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5516 | */ |
| 5517 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | final long identity = Binder.clearCallingIdentity(); |
| 5519 | try { |
| 5520 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5521 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5523 | } finally { |
| 5524 | Binder.restoreCallingIdentity(identity); |
| 5525 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5526 | } |
| 5527 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5528 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5529 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5530 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5531 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5532 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5533 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5534 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5535 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5536 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5537 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5538 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5539 | } |
| 5540 | return PhoneFactory.getPhone(phoneId); |
| 5541 | } |
| 5542 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5543 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5544 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5545 | @NonNull IccLogicalChannelRequest request) { |
| 5546 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5547 | /*message=*/ "iccOpenLogicalChannel"); |
| 5548 | |
| 5549 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5550 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5551 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5552 | |
| 5553 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5554 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5555 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5556 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5557 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5558 | Phone phone; |
| 5559 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5561 | mApp, request.subId, message); |
| 5562 | phone = getPhoneFromSubId(request.subId); |
| 5563 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5564 | enforceModifyPermission(); |
| 5565 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5566 | } else { |
| 5567 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5568 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5569 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5573 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 | final long identity = Binder.clearCallingIdentity(); |
| 5575 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5576 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5577 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5578 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5579 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5580 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5581 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | loge("The calling package is not allowed to access ISD-R."); |
| 5583 | throw new SecurityException( |
| 5584 | "The calling package is not allowed to access ISD-R."); |
| 5585 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5586 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5587 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5589 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5590 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5591 | return response; |
| 5592 | } finally { |
| 5593 | Binder.restoreCallingIdentity(identity); |
| 5594 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5595 | } |
| 5596 | |
| 5597 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5598 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5599 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5600 | /*message=*/"iccCloseLogicalChannel"); |
| 5601 | |
| 5602 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5603 | |
| 5604 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5605 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5606 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5607 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5608 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5609 | // before this feature is enabled, this API should only return false if |
| 5610 | // the operation fails instead of throwing runtime exception for |
| 5611 | // backward-compatibility. |
| 5612 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5613 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5614 | final long identity = Binder.clearCallingIdentity(); |
| 5615 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5616 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5617 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5618 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5619 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5620 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5621 | Boolean success = false; |
| 5622 | if (result instanceof RuntimeException) { |
| 5623 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5624 | if (shouldThrowExceptionOnFailure) { |
| 5625 | throw (RuntimeException) result; |
| 5626 | } else { |
| 5627 | return false; |
| 5628 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5629 | } else if (result instanceof Boolean) { |
| 5630 | success = (Boolean) result; |
| 5631 | } else { |
| 5632 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5633 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5634 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5635 | return success; |
| 5636 | } finally { |
| 5637 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5638 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5642 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5643 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5645 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5646 | if (DBG) { |
| 5647 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5648 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5649 | + p3 + " data=" + data); |
| 5650 | } |
| 5651 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5652 | command, p1, p2, p3, data); |
| 5653 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5654 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5655 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5656 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5657 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5658 | enforceModifyPermission(); |
| 5659 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5660 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5661 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5662 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5663 | } |
| 5664 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5665 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5666 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5670 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5671 | final long identity = Binder.clearCallingIdentity(); |
| 5672 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5673 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | return ""; |
| 5675 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5678 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5679 | null /* workSource */); |
| 5680 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5681 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5682 | // Append the returned status code to the end of the response payload. |
| 5683 | String s = Integer.toHexString( |
| 5684 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5685 | if (response.payload != null) { |
| 5686 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5687 | } |
| 5688 | return s; |
| 5689 | } finally { |
| 5690 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5691 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5692 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5693 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5694 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5695 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5696 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5697 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5698 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5700 | if (DBG) { |
| 5701 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5702 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5703 | } |
| 5704 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5705 | cla, command, p1, p2, p3, data); |
| 5706 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5707 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5708 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5709 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5710 | 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] | 5711 | enforceModifyPermission(); |
| 5712 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5713 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5714 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5715 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5716 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5720 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5721 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5725 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5726 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5727 | final long identity = Binder.clearCallingIdentity(); |
| 5728 | try { |
| 5729 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5730 | && TextUtils.equals(ISDR_AID, data)) { |
| 5731 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5732 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5733 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5734 | if (bestComponent == null |
| 5735 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5736 | loge("The calling package is not allowed to select ISD-R."); |
| 5737 | throw new SecurityException( |
| 5738 | "The calling package is not allowed to select ISD-R."); |
| 5739 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5740 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5741 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5742 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5743 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5744 | null /* workSource */); |
| 5745 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | // Append the returned status code to the end of the response payload. |
| 5748 | String s = Integer.toHexString( |
| 5749 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5750 | if (response.payload != null) { |
| 5751 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5752 | } |
| 5753 | return s; |
| 5754 | } finally { |
| 5755 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5756 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5757 | } |
| 5758 | |
| 5759 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5760 | 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] | 5761 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5762 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5763 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5764 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | final long identity = Binder.clearCallingIdentity(); |
| 5766 | try { |
| 5767 | if (DBG) { |
| 5768 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5769 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5770 | } |
| 5771 | |
| 5772 | IccIoResult response = |
| 5773 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5774 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5775 | subId); |
| 5776 | |
| 5777 | if (DBG) { |
| 5778 | log("Exchange SIM_IO [R]" + response); |
| 5779 | } |
| 5780 | |
| 5781 | byte[] result = null; |
| 5782 | int length = 2; |
| 5783 | if (response.payload != null) { |
| 5784 | length = 2 + response.payload.length; |
| 5785 | result = new byte[length]; |
| 5786 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5787 | } else { |
| 5788 | result = new byte[length]; |
| 5789 | } |
| 5790 | |
| 5791 | result[length - 1] = (byte) response.sw2; |
| 5792 | result[length - 2] = (byte) response.sw1; |
| 5793 | return result; |
| 5794 | } finally { |
| 5795 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5796 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5797 | } |
| 5798 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5799 | /** |
| 5800 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5801 | * on a particular subscription |
| 5802 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5803 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5804 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5805 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5806 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5807 | return null; |
| 5808 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5809 | |
| 5810 | final long identity = Binder.clearCallingIdentity(); |
| 5811 | try { |
| 5812 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5813 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5814 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5815 | return null; |
| 5816 | } |
| 5817 | Object response = sendRequest( |
| 5818 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5819 | if (response instanceof String[]) { |
| 5820 | return (String[]) response; |
| 5821 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5822 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5823 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5824 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5825 | } finally { |
| 5826 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5827 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5828 | } |
| 5829 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5830 | /** |
| 5831 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5832 | * subscription. |
| 5833 | * |
| 5834 | * @param subId the id of the subscription. |
| 5835 | * @param appType the uicc app type, must be USIM or SIM. |
| 5836 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5837 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5838 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5839 | * @return number of fplmns that is successfully written to the SIM. |
| 5840 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5841 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5842 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5844 | mApp, subId, "setForbiddenPlmns"); |
| 5845 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5846 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5847 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5848 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5849 | } |
| 5850 | if (fplmns == null) { |
| 5851 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5852 | } |
| 5853 | for (String fplmn : fplmns) { |
| 5854 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5855 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5856 | } |
| 5857 | } |
| 5858 | final long identity = Binder.clearCallingIdentity(); |
| 5859 | try { |
| 5860 | Object response = sendRequest( |
| 5861 | CMD_SET_FORBIDDEN_PLMNS, |
| 5862 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5863 | subId); |
| 5864 | return (int) response; |
| 5865 | } finally { |
| 5866 | Binder.restoreCallingIdentity(identity); |
| 5867 | } |
| 5868 | } |
| 5869 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5870 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5871 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5873 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5874 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5875 | final long identity = Binder.clearCallingIdentity(); |
| 5876 | try { |
| 5877 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5878 | if (response.payload == null) { |
| 5879 | return ""; |
| 5880 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5881 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | // Append the returned status code to the end of the response payload. |
| 5883 | String s = Integer.toHexString( |
| 5884 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5885 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5886 | return s; |
| 5887 | } finally { |
| 5888 | Binder.restoreCallingIdentity(identity); |
| 5889 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5892 | /** |
| 5893 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5894 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5895 | * |
| 5896 | * @param itemID the ID of the item to read |
| 5897 | * @return the NV item as a String, or null on error. |
| 5898 | */ |
| 5899 | @Override |
| 5900 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5901 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5902 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5903 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5904 | |
| 5905 | final long identity = Binder.clearCallingIdentity(); |
| 5906 | try { |
| 5907 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5908 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5909 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5910 | return value; |
| 5911 | } finally { |
| 5912 | Binder.restoreCallingIdentity(identity); |
| 5913 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | /** |
| 5917 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5918 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5919 | * |
| 5920 | * @param itemID the ID of the item to read |
| 5921 | * @param itemValue the value to write, as a String |
| 5922 | * @return true on success; false on any failure |
| 5923 | */ |
| 5924 | @Override |
| 5925 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5926 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5927 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5928 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | |
| 5930 | final long identity = Binder.clearCallingIdentity(); |
| 5931 | try { |
| 5932 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5933 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5934 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5936 | return success; |
| 5937 | } finally { |
| 5938 | Binder.restoreCallingIdentity(identity); |
| 5939 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | /** |
| 5943 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5944 | * Used for device configuration by some CDMA operators. |
| 5945 | * |
| 5946 | * @param preferredRoamingList byte array containing the new PRL |
| 5947 | * @return true on success; false on any failure |
| 5948 | */ |
| 5949 | @Override |
| 5950 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5952 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | |
| 5954 | final long identity = Binder.clearCallingIdentity(); |
| 5955 | try { |
| 5956 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5957 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5958 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5959 | return success; |
| 5960 | } finally { |
| 5961 | Binder.restoreCallingIdentity(identity); |
| 5962 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5966 | * 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] | 5967 | * Used for device configuration by some CDMA operators. |
| 5968 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5969 | * @param slotIndex - device slot. |
| 5970 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5971 | * @return true on success; false on any failure |
| 5972 | */ |
| 5973 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5974 | public boolean resetModemConfig(int slotIndex) { |
| 5975 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5976 | if (phone != null) { |
| 5977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5978 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5979 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5980 | final long identity = Binder.clearCallingIdentity(); |
| 5981 | try { |
| 5982 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5983 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5984 | return success; |
| 5985 | } finally { |
| 5986 | Binder.restoreCallingIdentity(identity); |
| 5987 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5988 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5989 | return false; |
| 5990 | } |
| 5991 | |
| 5992 | /** |
| 5993 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5994 | * |
| 5995 | * @param slotIndex - device slot. |
| 5996 | * |
| 5997 | * @return true on success; false on any failure |
| 5998 | */ |
| 5999 | @Override |
| 6000 | public boolean rebootModem(int slotIndex) { |
| 6001 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6002 | if (phone != null) { |
| 6003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6004 | mApp, phone.getSubId(), "rebootModem"); |
| 6005 | |
| 6006 | final long identity = Binder.clearCallingIdentity(); |
| 6007 | try { |
| 6008 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6009 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6010 | return success; |
| 6011 | } finally { |
| 6012 | Binder.restoreCallingIdentity(identity); |
| 6013 | } |
| 6014 | } |
| 6015 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6016 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6017 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6018 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6019 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6020 | * {@link #disableIms(int)}. |
| 6021 | * @param slotIndex device slot. |
| 6022 | */ |
| 6023 | public void resetIms(int slotIndex) { |
| 6024 | enforceModifyPermission(); |
| 6025 | |
| 6026 | final long identity = Binder.clearCallingIdentity(); |
| 6027 | try { |
| 6028 | if (mImsResolver == null) { |
| 6029 | // may happen if the does not support IMS. |
| 6030 | return; |
| 6031 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6032 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6033 | } finally { |
| 6034 | Binder.restoreCallingIdentity(identity); |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6039 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6040 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6041 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6042 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6043 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6044 | |
| 6045 | final long identity = Binder.clearCallingIdentity(); |
| 6046 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6047 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6048 | // may happen if the device does not support IMS. |
| 6049 | return; |
| 6050 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6051 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6052 | } finally { |
| 6053 | Binder.restoreCallingIdentity(identity); |
| 6054 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6058 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6059 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6060 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6061 | public void disableIms(int slotId) { |
| 6062 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6063 | |
| 6064 | final long identity = Binder.clearCallingIdentity(); |
| 6065 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6066 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6067 | // may happen if the device does not support IMS. |
| 6068 | return; |
| 6069 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6070 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6071 | } finally { |
| 6072 | Binder.restoreCallingIdentity(identity); |
| 6073 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6077 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6078 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6079 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6080 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6081 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6082 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6083 | |
| 6084 | final long identity = Binder.clearCallingIdentity(); |
| 6085 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6086 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6087 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6088 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6089 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6090 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6091 | } finally { |
| 6092 | Binder.restoreCallingIdentity(identity); |
| 6093 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6094 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6095 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6096 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6097 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6098 | @Override |
| 6099 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6100 | enforceModifyPermission(); |
| 6101 | |
| 6102 | final long identity = Binder.clearCallingIdentity(); |
| 6103 | try { |
| 6104 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6105 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6106 | } finally { |
| 6107 | Binder.restoreCallingIdentity(identity); |
| 6108 | } |
| 6109 | } |
| 6110 | |
| 6111 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6112 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6113 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6114 | */ |
| 6115 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6116 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6117 | |
| 6118 | final long identity = Binder.clearCallingIdentity(); |
| 6119 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6120 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6121 | // may happen if the device does not support IMS. |
| 6122 | return null; |
| 6123 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6124 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6125 | } finally { |
| 6126 | Binder.restoreCallingIdentity(identity); |
| 6127 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6128 | } |
| 6129 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6130 | /** |
| 6131 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6132 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6133 | */ |
| 6134 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6135 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6136 | |
| 6137 | final long identity = Binder.clearCallingIdentity(); |
| 6138 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6139 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6140 | // may happen if the device does not support IMS. |
| 6141 | return null; |
| 6142 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6143 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6144 | } finally { |
| 6145 | Binder.restoreCallingIdentity(identity); |
| 6146 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6147 | } |
| 6148 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6149 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6150 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6151 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6152 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6153 | * @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] | 6154 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6155 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6156 | * @param packageName The name of the package that the current configuration will be replaced |
| 6157 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6158 | * @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] | 6159 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6160 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6161 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6162 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6163 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6164 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | final long identity = Binder.clearCallingIdentity(); |
| 6167 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6168 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6169 | // may happen if the device does not support IMS. |
| 6170 | return false; |
| 6171 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6172 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6173 | for (int featureType : featureTypes) { |
| 6174 | featureConfig.put(featureType, packageName); |
| 6175 | } |
| 6176 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6177 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(identity); |
| 6180 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6184 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6185 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6186 | * |
| 6187 | * This should only be used for testing. |
| 6188 | * |
| 6189 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6190 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6191 | */ |
| 6192 | @Override |
| 6193 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6194 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6195 | "clearCarrierImsServiceOverride"); |
| 6196 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6197 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6198 | |
| 6199 | final long identity = Binder.clearCallingIdentity(); |
| 6200 | try { |
| 6201 | if (mImsResolver == null) { |
| 6202 | // may happen if the device does not support IMS. |
| 6203 | return false; |
| 6204 | } |
| 6205 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6206 | } finally { |
| 6207 | Binder.restoreCallingIdentity(identity); |
| 6208 | } |
| 6209 | } |
| 6210 | |
| 6211 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6212 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6213 | * |
| 6214 | * @param slotId The slot that the ImsService is associated with. |
| 6215 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6216 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6217 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6218 | * @return the package name of the ImsService configuration. |
| 6219 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6220 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6221 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6222 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6223 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6224 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6225 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6226 | final long identity = Binder.clearCallingIdentity(); |
| 6227 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6228 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6229 | // may happen if the device does not support IMS. |
| 6230 | return ""; |
| 6231 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6232 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6233 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6234 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6235 | } finally { |
| 6236 | Binder.restoreCallingIdentity(identity); |
| 6237 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6238 | } |
| 6239 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6240 | /** |
| 6241 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6242 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6243 | * @param callback A callback with an integer containing the |
| 6244 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6245 | */ |
| 6246 | @Override |
| 6247 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6248 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6249 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6250 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6251 | "IMS not available on device."); |
| 6252 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6253 | final long token = Binder.clearCallingIdentity(); |
| 6254 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6255 | int slotId = getSlotIndex(subId); |
| 6256 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6257 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6258 | + subId + "'"); |
| 6259 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6260 | } |
| 6261 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6262 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6263 | try { |
| 6264 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6265 | } catch (RemoteException e) { |
| 6266 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6267 | + "Ignore"); |
| 6268 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6269 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6270 | } catch (ImsException e) { |
| 6271 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6272 | } finally { |
| 6273 | Binder.restoreCallingIdentity(token); |
| 6274 | } |
| 6275 | } |
| 6276 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6277 | /** |
| 6278 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6279 | */ |
| 6280 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6281 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | |
| 6283 | final long identity = Binder.clearCallingIdentity(); |
| 6284 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6285 | // NOTE: Before S, this method only set the default phone. |
| 6286 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6287 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6288 | phone.setImsRegistrationState(registered); |
| 6289 | } |
| 6290 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6291 | } finally { |
| 6292 | Binder.restoreCallingIdentity(identity); |
| 6293 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6297 | * Set the network selection mode to automatic. |
| 6298 | * |
| 6299 | */ |
| 6300 | @Override |
| 6301 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6302 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6303 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6304 | |
| 6305 | final long identity = Binder.clearCallingIdentity(); |
| 6306 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6307 | if (!isActiveSubscription(subId)) { |
| 6308 | return; |
| 6309 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6310 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6311 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6312 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6313 | } finally { |
| 6314 | Binder.restoreCallingIdentity(identity); |
| 6315 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6316 | } |
| 6317 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6318 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6319 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6320 | * |
| 6321 | * @param subId the id of the subscription. |
| 6322 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6323 | * the operator to attach to. |
| 6324 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6325 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6326 | * normal network selection next time. |
| 6327 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6328 | */ |
| 6329 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6330 | public boolean setNetworkSelectionModeManual( |
| 6331 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6332 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6333 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6334 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6335 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6336 | if (!isActiveSubscription(subId)) { |
| 6337 | return false; |
| 6338 | } |
| 6339 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6340 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6341 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6342 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6343 | if (DBG) { |
| 6344 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6345 | + " operator: " + operatorInfo); |
| 6346 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6347 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6348 | } finally { |
| 6349 | Binder.restoreCallingIdentity(identity); |
| 6350 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6351 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6352 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6353 | * Get the manual network selection |
| 6354 | * |
| 6355 | * @param subId the id of the subscription. |
| 6356 | * |
| 6357 | * @return the previously saved user selected PLMN |
| 6358 | */ |
| 6359 | @Override |
| 6360 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6361 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6362 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6363 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6364 | |
| 6365 | final long identity = Binder.clearCallingIdentity(); |
| 6366 | try { |
| 6367 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6368 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | final Phone phone = getPhone(subId); |
| 6372 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6373 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6374 | } |
| 6375 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6376 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6377 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6378 | } finally { |
| 6379 | Binder.restoreCallingIdentity(identity); |
| 6380 | } |
| 6381 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6382 | |
| 6383 | /** |
| 6384 | * Scans for available networks. |
| 6385 | */ |
| 6386 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6387 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6388 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6389 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6390 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6391 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6392 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6393 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6394 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6395 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6396 | .setCallingPid(Binder.getCallingPid()) |
| 6397 | .setCallingUid(Binder.getCallingUid()) |
| 6398 | .setMethod("getCellNetworkScanResults") |
| 6399 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6400 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6401 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6402 | .build()); |
| 6403 | switch (locationResult) { |
| 6404 | case DENIED_HARD: |
| 6405 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6406 | case DENIED_SOFT: |
| 6407 | return null; |
| 6408 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6409 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6410 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6411 | try { |
| 6412 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6413 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | } finally { |
| 6416 | Binder.restoreCallingIdentity(identity); |
| 6417 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6418 | } |
| 6419 | |
| 6420 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6421 | * Get the call forwarding info, given the call forwarding reason. |
| 6422 | */ |
| 6423 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6424 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6425 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6426 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6427 | long identity = Binder.clearCallingIdentity(); |
| 6428 | try { |
| 6429 | if (DBG) { |
| 6430 | log("getCallForwarding: subId " + subId |
| 6431 | + " callForwardingReason" + callForwardingReason); |
| 6432 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6433 | |
| 6434 | Phone phone = getPhone(subId); |
| 6435 | if (phone == null) { |
| 6436 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6437 | callback.onError( |
| 6438 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6439 | } catch (RemoteException e) { |
| 6440 | // ignore |
| 6441 | } |
| 6442 | return; |
| 6443 | } |
| 6444 | |
| 6445 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6446 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6447 | @Override |
| 6448 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6449 | try { |
| 6450 | callback.onCallForwardingInfoAvailable(info); |
| 6451 | } catch (RemoteException e) { |
| 6452 | // ignore |
| 6453 | } |
| 6454 | } |
| 6455 | |
| 6456 | @Override |
| 6457 | public void onError(int error) { |
| 6458 | try { |
| 6459 | callback.onError(error); |
| 6460 | } catch (RemoteException e) { |
| 6461 | // ignore |
| 6462 | } |
| 6463 | } |
| 6464 | }); |
| 6465 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6466 | } finally { |
| 6467 | Binder.restoreCallingIdentity(identity); |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | /** |
| 6472 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6473 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6474 | */ |
| 6475 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6476 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6477 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6478 | enforceModifyPermission(); |
| 6479 | long identity = Binder.clearCallingIdentity(); |
| 6480 | try { |
| 6481 | if (DBG) { |
| 6482 | log("setCallForwarding: subId " + subId |
| 6483 | + " callForwardingInfo" + callForwardingInfo); |
| 6484 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6485 | |
| 6486 | Phone phone = getPhone(subId); |
| 6487 | if (phone == null) { |
| 6488 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6489 | callback.accept( |
| 6490 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6491 | } catch (RemoteException e) { |
| 6492 | // ignore |
| 6493 | } |
| 6494 | return; |
| 6495 | } |
| 6496 | |
| 6497 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6498 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6499 | |
| 6500 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6501 | } finally { |
| 6502 | Binder.restoreCallingIdentity(identity); |
| 6503 | } |
| 6504 | } |
| 6505 | |
| 6506 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6507 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6508 | */ |
| 6509 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6510 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6511 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6512 | long identity = Binder.clearCallingIdentity(); |
| 6513 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6514 | Phone phone = getPhone(subId); |
| 6515 | if (phone == null) { |
| 6516 | try { |
| 6517 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6518 | } catch (RemoteException e) { |
| 6519 | // ignore |
| 6520 | } |
| 6521 | return; |
| 6522 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6523 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6524 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6525 | boolean requireUssd = c.getBoolean( |
| 6526 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6527 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6528 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6529 | if (requireUssd) { |
| 6530 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6531 | getSubscriptionCarrierId(subId)); |
| 6532 | String newUssdCommand = ""; |
| 6533 | try { |
| 6534 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6535 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6536 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6537 | } catch (NullPointerException e) { |
| 6538 | loge("Failed to generate USSD number" + e); |
| 6539 | } |
| 6540 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6541 | mMainThreadHandler, callback, carrierXmlParser, |
| 6542 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6543 | final String ussdCommand = newUssdCommand; |
| 6544 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6545 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6546 | }); |
| 6547 | } else { |
| 6548 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6549 | callback::accept); |
| 6550 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6551 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6552 | } finally { |
| 6553 | Binder.restoreCallingIdentity(identity); |
| 6554 | } |
| 6555 | } |
| 6556 | |
| 6557 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6558 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6559 | */ |
| 6560 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6561 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6562 | enforceModifyPermission(); |
| 6563 | long identity = Binder.clearCallingIdentity(); |
| 6564 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6565 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6566 | |
| 6567 | Phone phone = getPhone(subId); |
| 6568 | if (phone == null) { |
| 6569 | try { |
| 6570 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6571 | } catch (RemoteException e) { |
| 6572 | // ignore |
| 6573 | } |
| 6574 | return; |
| 6575 | } |
| 6576 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6577 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6578 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6579 | boolean requireUssd = c.getBoolean( |
| 6580 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6581 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6582 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6583 | if (requireUssd) { |
| 6584 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6585 | getSubscriptionCarrierId(subId)); |
| 6586 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6587 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6588 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6589 | String newUssdCommand = ""; |
| 6590 | try { |
| 6591 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6592 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6593 | .makeCommand(ssAction, null); |
| 6594 | } catch (NullPointerException e) { |
| 6595 | loge("Failed to generate USSD number" + e); |
| 6596 | } |
| 6597 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6598 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6599 | final String ussdCommand = newUssdCommand; |
| 6600 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6601 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6602 | }); |
| 6603 | } else { |
| 6604 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6605 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6606 | |
| 6607 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6608 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6609 | } finally { |
| 6610 | Binder.restoreCallingIdentity(identity); |
| 6611 | } |
| 6612 | } |
| 6613 | |
| 6614 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6615 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6616 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6617 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6618 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6619 | * location related information which will be sent if the caller already possess |
| 6620 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6621 | * @param request contains the radio access networks with bands/channels to scan |
| 6622 | * @param messenger callback messenger for scan results or errors |
| 6623 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6624 | * @return the id of the requested scan which can be used to stop the scan. |
| 6625 | */ |
| 6626 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6627 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6628 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6629 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6631 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6632 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6633 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6634 | if (!renounceFineLocationAccess) { |
| 6635 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6636 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6637 | .setCallingPackage(callingPackage) |
| 6638 | .setCallingFeatureId(callingFeatureId) |
| 6639 | .setCallingPid(Binder.getCallingPid()) |
| 6640 | .setCallingUid(Binder.getCallingUid()) |
| 6641 | .setMethod("requestNetworkScan") |
| 6642 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6643 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6644 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6645 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6646 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6647 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6648 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6649 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6650 | if (e != null) { |
| 6651 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6652 | throw e; |
| 6653 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6654 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6655 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6656 | } |
| 6657 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6658 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6659 | int callingUid = Binder.getCallingUid(); |
| 6660 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6661 | final long identity = Binder.clearCallingIdentity(); |
| 6662 | try { |
| 6663 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6664 | renounceFineLocationAccess, request, messenger, binder, |
| 6665 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6666 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6667 | } finally { |
| 6668 | Binder.restoreCallingIdentity(identity); |
| 6669 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6670 | } |
| 6671 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6672 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6673 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6674 | boolean hasCarrierPriv; |
| 6675 | final long identity = Binder.clearCallingIdentity(); |
| 6676 | try { |
| 6677 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6678 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6679 | } finally { |
| 6680 | Binder.restoreCallingIdentity(identity); |
| 6681 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6682 | boolean hasNetworkScanPermission = |
| 6683 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6684 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6685 | |
| 6686 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6687 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6688 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6689 | } |
| 6690 | |
| 6691 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6692 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6693 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6694 | return new SecurityException("Specific channels must not be" |
| 6695 | + " scanned without location access."); |
| 6696 | } |
| 6697 | } |
| 6698 | } |
| 6699 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6700 | return null; |
| 6701 | } |
| 6702 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6703 | /** |
| 6704 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6705 | * |
| 6706 | * @param subId id of the subscription |
| 6707 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6708 | */ |
| 6709 | @Override |
| 6710 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6712 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6713 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6714 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | final long identity = Binder.clearCallingIdentity(); |
| 6716 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6717 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(identity); |
| 6720 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6724 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6725 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6726 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6727 | */ |
| 6728 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6729 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6730 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6731 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6732 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6733 | |
| 6734 | final long identity = Binder.clearCallingIdentity(); |
| 6735 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6736 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6737 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6738 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6739 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6740 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6741 | } finally { |
| 6742 | Binder.restoreCallingIdentity(identity); |
| 6743 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6747 | * Get the allowed network types for certain reason. |
| 6748 | * |
| 6749 | * @param subId the id of the subscription. |
| 6750 | * @param reason the reason the allowed network type change is taking place |
| 6751 | * @return the allowed network types. |
| 6752 | */ |
| 6753 | @Override |
| 6754 | public long getAllowedNetworkTypesForReason(int subId, |
| 6755 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6756 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6757 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6758 | final long identity = Binder.clearCallingIdentity(); |
| 6759 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6760 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6761 | } finally { |
| 6762 | Binder.restoreCallingIdentity(identity); |
| 6763 | } |
| 6764 | } |
| 6765 | |
| 6766 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6767 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6768 | * @param subId subscription id of the sim card |
| 6769 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6770 | * This can be passed following states |
| 6771 | * <ol> |
| 6772 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6773 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6774 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6775 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6776 | * </ol> |
| 6777 | * @return operation result. |
| 6778 | */ |
| 6779 | @Override |
| 6780 | public int setNrDualConnectivityState(int subId, |
| 6781 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6783 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6784 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6785 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6786 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6787 | } |
| 6788 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6789 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6790 | final long identity = Binder.clearCallingIdentity(); |
| 6791 | try { |
| 6792 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6793 | nrDualConnectivityState, subId, |
| 6794 | workSource); |
| 6795 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6796 | return result; |
| 6797 | } finally { |
| 6798 | Binder.restoreCallingIdentity(identity); |
| 6799 | } |
| 6800 | } |
| 6801 | |
| 6802 | /** |
| 6803 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6804 | * @return true if dual connectivity is enabled else false |
| 6805 | */ |
| 6806 | @Override |
| 6807 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6808 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6809 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6810 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6811 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6812 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6813 | return false; |
| 6814 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6815 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6816 | final long identity = Binder.clearCallingIdentity(); |
| 6817 | try { |
| 6818 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6819 | null, subId, workSource); |
| 6820 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6821 | return isEnabled; |
| 6822 | } finally { |
| 6823 | Binder.restoreCallingIdentity(identity); |
| 6824 | } |
| 6825 | } |
| 6826 | |
| 6827 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6828 | * Set the allowed network types of the device and |
| 6829 | * provide the reason triggering the allowed network change. |
| 6830 | * |
| 6831 | * @param subId the id of the subscription. |
| 6832 | * @param reason the reason the allowed network type change is taking place |
| 6833 | * @param allowedNetworkTypes the allowed network types. |
| 6834 | * @return true on success; false on any failure. |
| 6835 | */ |
| 6836 | @Override |
| 6837 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6838 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6839 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6841 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6842 | // If the caller only has carrier privileges, then they should not be able to override |
| 6843 | // any network types which were set for security reasons. |
| 6844 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6845 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6846 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6847 | throw new SecurityException( |
| 6848 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6849 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6850 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6851 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6852 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6853 | return false; |
| 6854 | } |
| 6855 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6856 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6857 | return false; |
| 6858 | } |
| 6859 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6860 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6861 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6862 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6863 | Phone phone = getPhone(subId); |
| 6864 | if (phone == null) { |
| 6865 | return false; |
| 6866 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6867 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6868 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6869 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6870 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6871 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6872 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6873 | final long identity = Binder.clearCallingIdentity(); |
| 6874 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6875 | Boolean success = (Boolean) sendRequest( |
| 6876 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6877 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6878 | |
| 6879 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6880 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6881 | } finally { |
| 6882 | Binder.restoreCallingIdentity(identity); |
| 6883 | } |
| 6884 | } |
| 6885 | |
| 6886 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6887 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6888 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6889 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6890 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6891 | * @hide |
| 6892 | */ |
| 6893 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6894 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6895 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6896 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6897 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6898 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6899 | if (phone != null) { |
| 6900 | return phone.hasMatchedTetherApnSetting(); |
| 6901 | } else { |
| 6902 | return false; |
| 6903 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | } finally { |
| 6905 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6906 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6907 | } |
| 6908 | |
| 6909 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6910 | * Get the user enabled state of Mobile Data. |
| 6911 | * |
| 6912 | * TODO: remove and use isUserDataEnabled. |
| 6913 | * This can't be removed now because some vendor codes |
| 6914 | * calls through ITelephony directly while they should |
| 6915 | * use TelephonyManager. |
| 6916 | * |
| 6917 | * @return true on enabled |
| 6918 | */ |
| 6919 | @Override |
| 6920 | public boolean getDataEnabled(int subId) { |
| 6921 | return isUserDataEnabled(subId); |
| 6922 | } |
| 6923 | |
| 6924 | /** |
| 6925 | * Get whether mobile data is enabled per user setting. |
| 6926 | * |
| 6927 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6928 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6929 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6930 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6931 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6932 | * |
| 6933 | * @return {@code true} if data is enabled else {@code false} |
| 6934 | */ |
| 6935 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6936 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6937 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6938 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6939 | try { |
| 6940 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6941 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6942 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6943 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6944 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6945 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6946 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6947 | mApp, subId, functionName); |
| 6948 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6949 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6950 | |
| 6951 | final long identity = Binder.clearCallingIdentity(); |
| 6952 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6953 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6954 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6955 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6956 | if (phone != null) { |
| 6957 | boolean retVal = phone.isUserDataEnabled(); |
| 6958 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6959 | return retVal; |
| 6960 | } else { |
| 6961 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6962 | return false; |
| 6963 | } |
| 6964 | } finally { |
| 6965 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6966 | } |
| 6967 | } |
| 6968 | |
| 6969 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6970 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6971 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6972 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6973 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6974 | * @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] | 6975 | */ |
| 6976 | @Override |
| 6977 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6978 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6979 | try { |
| 6980 | try { |
| 6981 | mApp.enforceCallingOrSelfPermission( |
| 6982 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6983 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6984 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6985 | try { |
| 6986 | mApp.enforceCallingOrSelfPermission( |
| 6987 | android.Manifest.permission.READ_PHONE_STATE, |
| 6988 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6989 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6990 | mApp.enforceCallingOrSelfPermission( |
| 6991 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6992 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6993 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6994 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6995 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6996 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6997 | |
| 6998 | final long identity = Binder.clearCallingIdentity(); |
| 6999 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7000 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7001 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7002 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7003 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7004 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | return retVal; |
| 7006 | } else { |
| 7007 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7008 | return false; |
| 7009 | } |
| 7010 | } finally { |
| 7011 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7012 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7013 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7014 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7015 | /** |
| 7016 | * Check if data is enabled for a specific reason |
| 7017 | * @param subId Subscription index |
| 7018 | * @param reason the reason the data enable change is taking place |
| 7019 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7020 | */ |
| 7021 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7022 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7023 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7024 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7025 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7026 | try { |
| 7027 | mApp.enforceCallingOrSelfPermission( |
| 7028 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7029 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7030 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7031 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7032 | functionName); |
| 7033 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7034 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7035 | try { |
| 7036 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7037 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7038 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7040 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7041 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7042 | } |
| 7043 | |
| 7044 | |
| 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7047 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7048 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7049 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7050 | + " reason=" + reason); |
| 7051 | } |
| 7052 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7053 | if (phone != null) { |
| 7054 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7055 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7056 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7057 | return retVal; |
| 7058 | } else { |
| 7059 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7060 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7061 | + subId + " retVal=false"); |
| 7062 | } |
| 7063 | return false; |
| 7064 | } |
| 7065 | } finally { |
| 7066 | Binder.restoreCallingIdentity(identity); |
| 7067 | } |
| 7068 | } |
| 7069 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7070 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7071 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7072 | // No permission needed; this only lets the caller inspect their own status. |
| 7073 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7074 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7075 | |
| 7076 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7077 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7078 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7079 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7080 | } |
| 7081 | |
| 7082 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7083 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7084 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7085 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7086 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7087 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7088 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7089 | if (cpt == null) { |
| 7090 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7091 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7092 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7093 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7097 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7098 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7099 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7100 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7101 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7102 | Phone phone = getPhone(subId); |
| 7103 | if (phone == null) { |
| 7104 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7105 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7106 | } |
| 7107 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7108 | if (cpt == null) { |
| 7109 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7110 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7111 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7112 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7113 | } |
| 7114 | |
| 7115 | @Override |
| 7116 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7117 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7118 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7119 | } |
| 7120 | |
| 7121 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7122 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7123 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7124 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7125 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7126 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7127 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7128 | if (phone == null) { |
| 7129 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7130 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7131 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7132 | if (cpt == null) { |
| 7133 | continue; |
| 7134 | } |
| 7135 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7136 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7137 | break; |
| 7138 | } |
| 7139 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7140 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7141 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7142 | |
| 7143 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7144 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7145 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7146 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7147 | if (phone == null) { |
| 7148 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7149 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7150 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7151 | if (cpt == null) { |
| 7152 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7153 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7154 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7155 | } |
| 7156 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7157 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7158 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7159 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7160 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7161 | if (phone == null) { |
| 7162 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7163 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7164 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7165 | if (cpt == null) { |
| 7166 | return Collections.emptyList(); |
| 7167 | } |
| 7168 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7169 | } |
| 7170 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7171 | @Override |
| 7172 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7173 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7174 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7175 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7176 | try { |
| 7177 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7178 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7179 | } |
| 7180 | } finally { |
| 7181 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7182 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7183 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7184 | } |
| 7185 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7186 | @Override |
| 7187 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7188 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7189 | |
| 7190 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7191 | if (phone == null) { |
| 7192 | return null; |
| 7193 | } |
| 7194 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7195 | if (cpt == null) { |
| 7196 | return null; |
| 7197 | } |
| 7198 | return cpt.getCarrierServicePackageName(); |
| 7199 | } |
| 7200 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7201 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7202 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7203 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7204 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7205 | return null; |
| 7206 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7207 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7208 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7209 | return null; |
| 7210 | } |
| 7211 | return iccId; |
| 7212 | } |
| 7213 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7214 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7215 | public void setCallComposerStatus(int subId, int status) { |
| 7216 | enforceModifyPermission(); |
| 7217 | |
| 7218 | final long identity = Binder.clearCallingIdentity(); |
| 7219 | try { |
| 7220 | Phone phone = getPhone(subId); |
| 7221 | if (phone != null) { |
| 7222 | Phone defaultPhone = phone.getImsPhone(); |
| 7223 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7224 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7225 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7226 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7227 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7228 | } |
| 7229 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7230 | } catch (ImsException e) { |
| 7231 | throw new ServiceSpecificException(e.getCode()); |
| 7232 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7233 | Binder.restoreCallingIdentity(identity); |
| 7234 | } |
| 7235 | } |
| 7236 | |
| 7237 | @Override |
| 7238 | public int getCallComposerStatus(int subId) { |
| 7239 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7240 | |
| 7241 | final long identity = Binder.clearCallingIdentity(); |
| 7242 | try { |
| 7243 | Phone phone = getPhone(subId); |
| 7244 | if (phone != null) { |
| 7245 | Phone defaultPhone = phone.getImsPhone(); |
| 7246 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7247 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7248 | return imsPhone.getCallComposerStatus(); |
| 7249 | } |
| 7250 | } |
| 7251 | } finally { |
| 7252 | Binder.restoreCallingIdentity(identity); |
| 7253 | } |
| 7254 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7255 | } |
| 7256 | |
| 7257 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7258 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7259 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7260 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7261 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7262 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7263 | final long identity = Binder.clearCallingIdentity(); |
| 7264 | try { |
| 7265 | final String iccId = getIccId(subId); |
| 7266 | final Phone phone = getPhone(subId); |
| 7267 | if (phone == null) { |
| 7268 | return false; |
| 7269 | } |
| 7270 | final String subscriberId = phone.getSubscriberId(); |
| 7271 | |
| 7272 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7273 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7274 | + subscriberId + " to " + number); |
| 7275 | } |
| 7276 | |
| 7277 | if (TextUtils.isEmpty(iccId)) { |
| 7278 | return false; |
| 7279 | } |
| 7280 | |
| 7281 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7282 | |
| 7283 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7284 | if (alphaTag == null) { |
| 7285 | editor.remove(alphaTagPrefKey); |
| 7286 | } else { |
| 7287 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7288 | } |
| 7289 | |
| 7290 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7291 | // track all merged IMSIs based on line number |
| 7292 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7293 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7294 | if (number == null) { |
| 7295 | editor.remove(numberPrefKey); |
| 7296 | editor.remove(subscriberPrefKey); |
| 7297 | } else { |
| 7298 | editor.putString(numberPrefKey, number); |
| 7299 | editor.putString(subscriberPrefKey, subscriberId); |
| 7300 | } |
| 7301 | |
| 7302 | editor.commit(); |
| 7303 | return true; |
| 7304 | } finally { |
| 7305 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7306 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7307 | } |
| 7308 | |
| 7309 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7310 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7311 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7312 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7313 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7314 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7315 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7316 | return null; |
| 7317 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7319 | final long identity = Binder.clearCallingIdentity(); |
| 7320 | try { |
| 7321 | String iccId = getIccId(subId); |
| 7322 | if (iccId != null) { |
| 7323 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7324 | if (DBG_MERGE) { |
| 7325 | log("getLine1NumberForDisplay returning " |
| 7326 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7327 | } |
| 7328 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7329 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7330 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7331 | return null; |
| 7332 | } finally { |
| 7333 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7334 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7335 | } |
| 7336 | |
| 7337 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7338 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7339 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7340 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7341 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7342 | return null; |
| 7343 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7344 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7345 | final long identity = Binder.clearCallingIdentity(); |
| 7346 | try { |
| 7347 | String iccId = getIccId(subId); |
| 7348 | if (iccId != null) { |
| 7349 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7350 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7351 | } |
| 7352 | return null; |
| 7353 | } finally { |
| 7354 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7355 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7356 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7357 | |
| 7358 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7359 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7360 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7361 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7362 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7363 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7364 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7365 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7366 | return null; |
| 7367 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7368 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7369 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7370 | // the process, where TelephonyManager was instantiated. |
| 7371 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7372 | final long identity = Binder.clearCallingIdentity(); |
| 7373 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7374 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7375 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7376 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7377 | |
| 7378 | // Figure out what subscribers are currently active |
| 7379 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7380 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7381 | // Only consider subs which match the current subId |
| 7382 | // This logic can be simplified. See b/131189269 for progress. |
| 7383 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7384 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7385 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7386 | |
| 7387 | // First pass, find a number override for an active subscriber |
| 7388 | String mergeNumber = null; |
| 7389 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7390 | for (String key : prefs.keySet()) { |
| 7391 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7392 | final String subscriberId = (String) prefs.get(key); |
| 7393 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7394 | final String iccId = key.substring( |
| 7395 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7396 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7397 | mergeNumber = (String) prefs.get(numberKey); |
| 7398 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7399 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7400 | + " for active subscriber " + subscriberId); |
| 7401 | } |
| 7402 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7403 | break; |
| 7404 | } |
| 7405 | } |
| 7406 | } |
| 7407 | } |
| 7408 | |
| 7409 | // Shortcut when no active merged subscribers |
| 7410 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7411 | return null; |
| 7412 | } |
| 7413 | |
| 7414 | // Second pass, find all subscribers under that line override |
| 7415 | final ArraySet<String> result = new ArraySet<>(); |
| 7416 | for (String key : prefs.keySet()) { |
| 7417 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7418 | final String number = (String) prefs.get(key); |
| 7419 | if (mergeNumber.equals(number)) { |
| 7420 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7421 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7422 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7423 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7424 | result.add(subscriberId); |
| 7425 | } |
| 7426 | } |
| 7427 | } |
| 7428 | } |
| 7429 | |
| 7430 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7431 | Arrays.sort(resultArray); |
| 7432 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7433 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7434 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7435 | } |
| 7436 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7437 | } finally { |
| 7438 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7439 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7440 | } |
| 7441 | |
| 7442 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7443 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7444 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7445 | |
| 7446 | final long identity = Binder.clearCallingIdentity(); |
| 7447 | try { |
| 7448 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7449 | TelephonyManager.class); |
| 7450 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7451 | if (subscriberId == null) { |
| 7452 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7453 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7454 | + subId); |
| 7455 | } |
| 7456 | return null; |
| 7457 | } |
| 7458 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7459 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7460 | .getSubscriptionInfo(subId); |
| 7461 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7462 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7463 | if (groupUuid == null) { |
| 7464 | return new String[]{subscriberId}; |
| 7465 | } |
| 7466 | |
| 7467 | // Get all subscriberIds from the group. |
| 7468 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7469 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7470 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7471 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7472 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7473 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7474 | if (subscriberId != null) { |
| 7475 | mergedSubscriberIds.add(subscriberId); |
| 7476 | } |
| 7477 | } |
| 7478 | |
| 7479 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7480 | } finally { |
| 7481 | Binder.restoreCallingIdentity(identity); |
| 7482 | |
| 7483 | } |
| 7484 | } |
| 7485 | |
| 7486 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7487 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7488 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7489 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7490 | |
| 7491 | final long identity = Binder.clearCallingIdentity(); |
| 7492 | try { |
| 7493 | final Phone phone = getPhone(subId); |
| 7494 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7495 | } finally { |
| 7496 | Binder.restoreCallingIdentity(identity); |
| 7497 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7498 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7499 | |
| 7500 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7501 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7502 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7503 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7504 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7505 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | |
| 7507 | final long identity = Binder.clearCallingIdentity(); |
| 7508 | try { |
| 7509 | final Phone phone = getPhone(subId); |
| 7510 | if (phone == null) { |
| 7511 | return false; |
| 7512 | } |
| 7513 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7514 | cdmaNonRoamingList); |
| 7515 | } finally { |
| 7516 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7517 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7518 | } |
| 7519 | |
| 7520 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7521 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7522 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7523 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7524 | if (phone == null) { |
| 7525 | return raf; |
| 7526 | } |
| 7527 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7528 | try { |
| 7529 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7530 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7531 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7532 | } catch (SecurityException e) { |
| 7533 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7534 | throw e; |
| 7535 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7537 | final long identity = Binder.clearCallingIdentity(); |
| 7538 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7539 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7540 | } finally { |
| 7541 | Binder.restoreCallingIdentity(identity); |
| 7542 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7543 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7544 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7545 | |
| 7546 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7547 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7548 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7549 | try { |
| 7550 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7551 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7552 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7553 | } |
| 7554 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7555 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7556 | } |
| 7557 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7558 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7559 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7560 | throw new SecurityException("App must be the dialer role holder to" |
| 7561 | + " upload a call composer pic"); |
| 7562 | } |
| 7563 | |
| 7564 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7565 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7566 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7567 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7568 | boolean readUntilEnd = false; |
| 7569 | int totalBytesRead = 0; |
| 7570 | byte[] buffer = new byte[16 * 1024]; |
| 7571 | while (true) { |
| 7572 | int numRead; |
| 7573 | try { |
| 7574 | numRead = input.read(buffer); |
| 7575 | } catch (IOException e) { |
| 7576 | try { |
| 7577 | fd.checkError(); |
| 7578 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7579 | null); |
| 7580 | } catch (IOException e1) { |
| 7581 | // This means that the other side closed explicitly with an error. If this |
| 7582 | // happens, log and ignore. |
| 7583 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7584 | } |
| 7585 | break; |
| 7586 | } |
| 7587 | if (numRead == -1) { |
| 7588 | readUntilEnd = true; |
| 7589 | break; |
| 7590 | } |
| 7591 | totalBytesRead += numRead; |
| 7592 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7593 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7594 | try { |
| 7595 | input.close(); |
| 7596 | } catch (IOException e) { |
| 7597 | // ignore |
| 7598 | } |
| 7599 | break; |
| 7600 | } |
| 7601 | output.write(buffer, 0, numRead); |
| 7602 | } |
| 7603 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7604 | // close is above, where the picture size is too big. |
| 7605 | |
| 7606 | try { |
| 7607 | fd.checkError(); |
| 7608 | } catch (IOException e) { |
| 7609 | loge("Remote end for call composer closed with an error: " + e); |
| 7610 | return; |
| 7611 | } |
| 7612 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7613 | if (!readUntilEnd) { |
| 7614 | loge("Did not finish reading entire image; aborting"); |
| 7615 | return; |
| 7616 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7617 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7618 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7619 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7620 | new CallComposerPictureTransfer.Factory() {}, |
| 7621 | imageData, |
| 7622 | (result) -> { |
| 7623 | if (result.first != null) { |
| 7624 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7625 | Bundle outputResult = new Bundle(); |
| 7626 | outputResult.putParcelable( |
| 7627 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7628 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7629 | outputResult); |
| 7630 | } else { |
| 7631 | callback.send(result.second, null); |
| 7632 | } |
| 7633 | } |
| 7634 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7635 | }); |
| 7636 | } |
| 7637 | |
| 7638 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7639 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7640 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7641 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | |
| 7643 | final long identity = Binder.clearCallingIdentity(); |
| 7644 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7645 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7646 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7647 | } finally { |
| 7648 | Binder.restoreCallingIdentity(identity); |
| 7649 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7650 | } |
| 7651 | |
| 7652 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7653 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7654 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7655 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7656 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7657 | return false; |
| 7658 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7659 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7660 | final long identity = Binder.clearCallingIdentity(); |
| 7661 | try { |
| 7662 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7663 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7664 | // In the long run, we may instead need to check if there exists a connection service |
| 7665 | // which can support video calling. |
| 7666 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7667 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7668 | return imsManager.isVtEnabledByPlatform() |
| 7669 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7670 | && imsManager.isVtEnabledByUser(); |
| 7671 | } finally { |
| 7672 | Binder.restoreCallingIdentity(identity); |
| 7673 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7674 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7675 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7676 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7677 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7678 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7679 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7680 | mApp, subId, callingPackage, callingFeatureId, |
| 7681 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7682 | return false; |
| 7683 | } |
| 7684 | |
| 7685 | final long identity = Binder.clearCallingIdentity(); |
| 7686 | try { |
| 7687 | CarrierConfigManager configManager = |
| 7688 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7689 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7690 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7691 | } finally { |
| 7692 | Binder.restoreCallingIdentity(identity); |
| 7693 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7694 | } |
| 7695 | |
| 7696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7697 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7698 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7699 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7700 | return false; |
| 7701 | } |
| 7702 | |
| 7703 | final long identity = Binder.clearCallingIdentity(); |
| 7704 | try { |
| 7705 | CarrierConfigManager configManager = |
| 7706 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7707 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7708 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7709 | } finally { |
| 7710 | Binder.restoreCallingIdentity(identity); |
| 7711 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7712 | } |
| 7713 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7714 | @Override |
| 7715 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7716 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7717 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7718 | } |
| 7719 | |
| 7720 | @Override |
| 7721 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7722 | final long identity = Binder.clearCallingIdentity(); |
| 7723 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7724 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7725 | } finally { |
| 7726 | Binder.restoreCallingIdentity(identity); |
| 7727 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7728 | } |
| 7729 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7730 | /** |
| 7731 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7732 | * support for the feature and device firmware support. |
| 7733 | * |
| 7734 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7735 | */ |
| 7736 | @Override |
| 7737 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7738 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7739 | final Phone phone = getPhone(subscriptionId); |
| 7740 | if (phone == null) { |
| 7741 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7742 | return false; |
| 7743 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7744 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7745 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7746 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7747 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7748 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7749 | return isCarrierSupported && isDeviceSupported; |
| 7750 | } finally { |
| 7751 | Binder.restoreCallingIdentity(identity); |
| 7752 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7753 | } |
| 7754 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7755 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7756 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7757 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7758 | * 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] | 7759 | */ |
| 7760 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7761 | final long identity = Binder.clearCallingIdentity(); |
| 7762 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7763 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7764 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7765 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7766 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7767 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7768 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7769 | } finally { |
| 7770 | Binder.restoreCallingIdentity(identity); |
| 7771 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7772 | } |
| 7773 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7774 | @Deprecated |
| 7775 | @Override |
| 7776 | public String getDeviceId(String callingPackage) { |
| 7777 | return getDeviceIdWithFeature(callingPackage, null); |
| 7778 | } |
| 7779 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7780 | /** |
| 7781 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7782 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7783 | * |
| 7784 | * <p>Requires Permission: |
| 7785 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7786 | */ |
| 7787 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7788 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7789 | try { |
| 7790 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7791 | } catch (SecurityException se) { |
| 7792 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7793 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7794 | + Binder.getCallingUid()); |
| 7795 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7796 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7797 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7798 | return null; |
| 7799 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7800 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7801 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7802 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7803 | return null; |
| 7804 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7805 | |
| 7806 | final long identity = Binder.clearCallingIdentity(); |
| 7807 | try { |
| 7808 | return phone.getDeviceId(); |
| 7809 | } finally { |
| 7810 | Binder.restoreCallingIdentity(identity); |
| 7811 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7812 | } |
| 7813 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7814 | /** |
| 7815 | * {@hide} |
| 7816 | * Returns the IMS Registration Status on a particular subid |
| 7817 | * |
| 7818 | * @param subId |
| 7819 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7820 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7821 | Phone phone = getPhone(subId); |
| 7822 | if (phone != null) { |
| 7823 | return phone.isImsRegistered(); |
| 7824 | } else { |
| 7825 | return false; |
| 7826 | } |
| 7827 | } |
| 7828 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7829 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7830 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7831 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7832 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7833 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7834 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7835 | } |
| 7836 | final long identity = Binder.clearCallingIdentity(); |
| 7837 | try { |
| 7838 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7839 | } finally { |
| 7840 | Binder.restoreCallingIdentity(identity); |
| 7841 | } |
| 7842 | } |
| 7843 | |
| 7844 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7845 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7846 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7847 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7848 | mApp, |
| 7849 | subscriptionId, |
| 7850 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7851 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7852 | final long identity = Binder.clearCallingIdentity(); |
| 7853 | try { |
| 7854 | Phone phone = getPhone(subscriptionId); |
| 7855 | if (phone == null) { |
| 7856 | return null; |
| 7857 | } |
| 7858 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7859 | } finally { |
| 7860 | Binder.restoreCallingIdentity(identity); |
| 7861 | } |
| 7862 | } |
| 7863 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7864 | /** |
| 7865 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7866 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7867 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7868 | final long identity = Binder.clearCallingIdentity(); |
| 7869 | try { |
| 7870 | Phone phone = getPhone(subId); |
| 7871 | if (phone != null) { |
| 7872 | return phone.isWifiCallingEnabled(); |
| 7873 | } else { |
| 7874 | return false; |
| 7875 | } |
| 7876 | } finally { |
| 7877 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7878 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7879 | } |
| 7880 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7881 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7882 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7883 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7884 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7885 | final long identity = Binder.clearCallingIdentity(); |
| 7886 | try { |
| 7887 | Phone phone = getPhone(subId); |
| 7888 | if (phone != null) { |
| 7889 | return phone.isVideoEnabled(); |
| 7890 | } else { |
| 7891 | return false; |
| 7892 | } |
| 7893 | } finally { |
| 7894 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7895 | } |
| 7896 | } |
| 7897 | |
| 7898 | /** |
| 7899 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7900 | * defined in {@link ImsRegistrationImplBase}. |
| 7901 | */ |
| 7902 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7903 | final long identity = Binder.clearCallingIdentity(); |
| 7904 | try { |
| 7905 | Phone phone = getPhone(subId); |
| 7906 | if (phone != null) { |
| 7907 | return phone.getImsRegistrationTech(); |
| 7908 | } else { |
| 7909 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7910 | } |
| 7911 | } finally { |
| 7912 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7913 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7914 | } |
| 7915 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7916 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7917 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7918 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7919 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7920 | return; |
| 7921 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7922 | Phone defaultPhone = getDefaultPhone(); |
| 7923 | if (defaultPhone != null) { |
| 7924 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7925 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7926 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7927 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7928 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7929 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7930 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7931 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7932 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7933 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7934 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7935 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7936 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7937 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7938 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7939 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7940 | // There has been issues when Sms raw table somehow stores orphan |
| 7941 | // fragments. They lead to garbled message when new fragments come |
| 7942 | // in and combined with those stale ones. In case this happens again, |
| 7943 | // user can reset all network settings which will clean up this table. |
| 7944 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7945 | // Clean up IMS settings as well here. |
| 7946 | int slotId = getSlotIndex(subId); |
| 7947 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7948 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7949 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7950 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7951 | if (defaultPhone == null) { |
| 7952 | return; |
| 7953 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7954 | // Erase modem config if erase modem on network setting is enabled. |
| 7955 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7956 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7957 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7958 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7959 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7960 | |
| 7961 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7962 | } finally { |
| 7963 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7964 | } |
| 7965 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7966 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7967 | @VisibleForTesting |
| 7968 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7969 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7970 | return; |
| 7971 | } |
| 7972 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7973 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7974 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7975 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7976 | "user=" + defaultNetworkType); |
| 7977 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7978 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7979 | defaultNetworkType, null); |
| 7980 | } |
| 7981 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7982 | private void cleanUpSmsRawTable(Context context) { |
| 7983 | ContentResolver resolver = context.getContentResolver(); |
| 7984 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7985 | resolver.delete(uri, null, null); |
| 7986 | } |
| 7987 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7988 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7989 | public String getSimLocaleForSubscriber(int subId) { |
| 7990 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7991 | final Phone phone = getPhone(subId); |
| 7992 | if (phone == null) { |
| 7993 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7994 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7996 | final long identity = Binder.clearCallingIdentity(); |
| 7997 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7998 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 7999 | phone.getContext().getOpPackageName(), |
| 8000 | phone.getContext().getAttributionTag()); |
| 8001 | if (info == null) { |
| 8002 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8003 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8004 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8005 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8006 | // preferences (EF-PL and EF-LI)... |
| 8007 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8008 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8009 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8010 | if (localeFromDefaultSim != null) { |
| 8011 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8012 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8013 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8014 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8015 | } else { |
| 8016 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8017 | } |
| 8018 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8020 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8021 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8022 | // the SIM and carrier preferences does not include a country we add the country |
| 8023 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8024 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8025 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8026 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8027 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8028 | } |
| 8029 | |
| 8030 | if (DBG) log("No locale found - returning null"); |
| 8031 | return null; |
| 8032 | } finally { |
| 8033 | Binder.restoreCallingIdentity(identity); |
| 8034 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8035 | } |
| 8036 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8037 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8038 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8039 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8040 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8041 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8042 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8043 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8044 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8045 | return localeTag; |
| 8046 | } |
| 8047 | } |
| 8048 | return inputLocale.toLanguageTag(); |
| 8049 | } |
| 8050 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8051 | /** |
| 8052 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8053 | */ |
| 8054 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8055 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8056 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8057 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8058 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8059 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8060 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8061 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8062 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8063 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8064 | * representing the state of the modem. |
| 8065 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8066 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8067 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8068 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8069 | */ |
| 8070 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8071 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8072 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8073 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8074 | |
| 8075 | final long identity = Binder.clearCallingIdentity(); |
| 8076 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8077 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8078 | } finally { |
| 8079 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8080 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8081 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8082 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8083 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8084 | // less than total activity duration. |
| 8085 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8086 | if (info == null) { |
| 8087 | return false; |
| 8088 | } |
| 8089 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8090 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8091 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8092 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8093 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8094 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8095 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8096 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8097 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8098 | } |
| 8099 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8100 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8101 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8102 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8103 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8104 | |
| 8105 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8106 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8107 | } |
| 8108 | |
| 8109 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8110 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8111 | rat, |
| 8112 | freq, |
| 8113 | info.getReceiveTimeMillis(rat, freq) |
| 8114 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8115 | } |
| 8116 | |
| 8117 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8118 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8119 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8120 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8121 | |
| 8122 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8123 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8124 | } |
| 8125 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8126 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8127 | rat, |
| 8128 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8129 | } |
| 8130 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8131 | /** |
| 8132 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8133 | * @param info recent ModemActivityInfo |
| 8134 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8135 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8136 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8137 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8138 | boolean matched; |
| 8139 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8140 | matched = false; |
| 8141 | int rat = info.getSpecificInfoRat(i); |
| 8142 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8143 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8144 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8145 | //if it already exists |
| 8146 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8147 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8148 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8149 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8150 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8151 | updateLastModemActivityInfo(info, rat, freq); |
| 8152 | matched = true; |
| 8153 | } |
| 8154 | } else { |
| 8155 | updateLastModemActivityInfo(info, rat); |
| 8156 | matched = true; |
| 8157 | } |
| 8158 | } |
| 8159 | } |
| 8160 | |
| 8161 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8162 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8163 | new ActivityStatsTechSpecificInfo( |
| 8164 | rat, |
| 8165 | freq, |
| 8166 | info.getTransmitTimeMillis(rat, freq), |
| 8167 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8168 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8169 | } |
| 8170 | } |
| 8171 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8172 | mLastModemActivitySpecificInfo = |
| 8173 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8174 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8175 | |
| 8176 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8177 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8178 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8179 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8180 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8181 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8182 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8183 | |
| 8184 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8185 | new ModemActivityInfo( |
| 8186 | mLastModemActivityInfo.getTimestampMillis(), |
| 8187 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8188 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8189 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8190 | } |
| 8191 | |
| 8192 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8193 | ActivityStatsTechSpecificInfo[] info) { |
| 8194 | int infoSize = info.length; |
| 8195 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8196 | for (int i = 0; i < infoSize; i++) { |
| 8197 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8198 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8199 | info[i].getTransmitTimeMillis(), |
| 8200 | (int) info[i].getReceiveTimeMillis()); |
| 8201 | } |
| 8202 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8203 | } |
| 8204 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8205 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8206 | * Returns the service state information on specified subscription. |
| 8207 | */ |
| 8208 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8209 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8210 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8211 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8212 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8213 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8214 | return null; |
| 8215 | } |
| 8216 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8217 | boolean hasFinePermission = false; |
| 8218 | boolean hasCoarsePermission = false; |
| 8219 | if (!renounceFineLocationAccess) { |
| 8220 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8221 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8222 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8223 | .setCallingPackage(callingPackage) |
| 8224 | .setCallingFeatureId(callingFeatureId) |
| 8225 | .setCallingPid(Binder.getCallingPid()) |
| 8226 | .setCallingUid(Binder.getCallingUid()) |
| 8227 | .setMethod("getServiceStateForSubscriber") |
| 8228 | .setLogAsInfo(true) |
| 8229 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8230 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8231 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8232 | .build()); |
| 8233 | hasFinePermission = |
| 8234 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8235 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8236 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8237 | if (!renounceCoarseLocationAccess) { |
| 8238 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8239 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8240 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8241 | .setCallingPackage(callingPackage) |
| 8242 | .setCallingFeatureId(callingFeatureId) |
| 8243 | .setCallingPid(Binder.getCallingPid()) |
| 8244 | .setCallingUid(Binder.getCallingUid()) |
| 8245 | .setMethod("getServiceStateForSubscriber") |
| 8246 | .setLogAsInfo(true) |
| 8247 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8248 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8249 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8250 | .build()); |
| 8251 | hasCoarsePermission = |
| 8252 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8253 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8254 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8255 | final Phone phone = getPhone(subId); |
| 8256 | if (phone == null) { |
| 8257 | return null; |
| 8258 | } |
| 8259 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8260 | final long identity = Binder.clearCallingIdentity(); |
| 8261 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8262 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8263 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8264 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8265 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8266 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8267 | .getSubscriptionInfoInternal(subId); |
| 8268 | if (subInfo == null || !subInfo.isActive()) { |
| 8269 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8270 | + "subId=" + subId); |
| 8271 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8272 | } |
| 8273 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8274 | ServiceState ss = phone.getServiceState(); |
| 8275 | |
| 8276 | // Scrub out the location info in ServiceState depending on what level of access |
| 8277 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8278 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8279 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8280 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8281 | } finally { |
| 8282 | Binder.restoreCallingIdentity(identity); |
| 8283 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8284 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8285 | |
| 8286 | /** |
| 8287 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8288 | * |
| 8289 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8290 | * voicemail ringtone. |
| 8291 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8292 | * PhoneAccount. |
| 8293 | */ |
| 8294 | @Override |
| 8295 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8296 | final long identity = Binder.clearCallingIdentity(); |
| 8297 | try { |
| 8298 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8299 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8300 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8302 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8303 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8304 | } finally { |
| 8305 | Binder.restoreCallingIdentity(identity); |
| 8306 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8307 | } |
| 8308 | |
| 8309 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8310 | * Sets the per-account voicemail ringtone. |
| 8311 | * |
| 8312 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8313 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8314 | * |
| 8315 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8316 | * voicemail ringtone. |
| 8317 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8318 | * PhoneAccount. |
| 8319 | */ |
| 8320 | @Override |
| 8321 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8322 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8323 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8324 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8325 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8326 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8327 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8328 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8329 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8330 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8331 | |
| 8332 | final long identity = Binder.clearCallingIdentity(); |
| 8333 | try { |
| 8334 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8335 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8336 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8337 | } |
| 8338 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8339 | } finally { |
| 8340 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8341 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8342 | } |
| 8343 | |
| 8344 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8345 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8346 | * |
| 8347 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8348 | * voicemail vibration setting. |
| 8349 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8350 | */ |
| 8351 | @Override |
| 8352 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8353 | final long identity = Binder.clearCallingIdentity(); |
| 8354 | try { |
| 8355 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8356 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8357 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8358 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8359 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8360 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8361 | } finally { |
| 8362 | Binder.restoreCallingIdentity(identity); |
| 8363 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8364 | } |
| 8365 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8366 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8367 | * Sets the per-account voicemail vibration. |
| 8368 | * |
| 8369 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8370 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8371 | * |
| 8372 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8373 | * voicemail vibration setting. |
| 8374 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8375 | * specific PhoneAccount. |
| 8376 | */ |
| 8377 | @Override |
| 8378 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8379 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8380 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8381 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8382 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8383 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8385 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8386 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8387 | } |
| 8388 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8389 | final long identity = Binder.clearCallingIdentity(); |
| 8390 | try { |
| 8391 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8392 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8393 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8394 | } |
| 8395 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8396 | } finally { |
| 8397 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8398 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8399 | } |
| 8400 | |
| 8401 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8402 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8403 | * |
| 8404 | * @throws SecurityException if the caller does not have the required permission |
| 8405 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8406 | @VisibleForTesting |
| 8407 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8408 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8409 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8410 | } |
| 8411 | |
| 8412 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8413 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8414 | * permission. |
| 8415 | * |
| 8416 | * @throws SecurityException if the caller does not have the required permission |
| 8417 | */ |
| 8418 | private void enforceSendSmsPermission() { |
| 8419 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8420 | } |
| 8421 | |
| 8422 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8423 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8424 | * users permission. |
| 8425 | * |
| 8426 | * @throws SecurityException if the caller does not have the required permission |
| 8427 | */ |
| 8428 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8429 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8430 | } |
| 8431 | |
| 8432 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8433 | * Make sure called from the package in charge of visual voicemail. |
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 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8436 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8437 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8438 | final long identity = Binder.clearCallingIdentity(); |
| 8439 | try { |
| 8440 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8441 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8442 | if (componentName == null) { |
| 8443 | throw new SecurityException( |
| 8444 | "Caller not current active visual voicemail package[null]"); |
| 8445 | } |
| 8446 | String vvmPackage = componentName.getPackageName(); |
| 8447 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8448 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8449 | } |
| 8450 | } finally { |
| 8451 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8452 | } |
| 8453 | } |
| 8454 | |
| 8455 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8456 | * Return the application ID for the app type. |
| 8457 | * |
| 8458 | * @param subId the subscription ID that this request applies to. |
| 8459 | * @param appType the uicc app type. |
| 8460 | * @return Application ID for specificied app type, or null if no uicc. |
| 8461 | */ |
| 8462 | @Override |
| 8463 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8464 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8465 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8466 | |
| 8467 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8468 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8469 | if (phone == null) { |
| 8470 | return null; |
| 8471 | } |
| 8472 | String aid = null; |
| 8473 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8474 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8475 | .getApplicationByType(appType).getAid(); |
| 8476 | } catch (Exception e) { |
| 8477 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8478 | } |
| 8479 | return aid; |
| 8480 | } finally { |
| 8481 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8482 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8483 | } |
| 8484 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8485 | /** |
| 8486 | * Return the Electronic Serial Number. |
| 8487 | * |
| 8488 | * @param subId the subscription ID that this request applies to. |
| 8489 | * @return ESN or null if error. |
| 8490 | */ |
| 8491 | @Override |
| 8492 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8493 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8494 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8495 | |
| 8496 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8497 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8498 | if (phone == null) { |
| 8499 | return null; |
| 8500 | } |
| 8501 | String esn = null; |
| 8502 | try { |
| 8503 | esn = phone.getEsn(); |
| 8504 | } catch (Exception e) { |
| 8505 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8506 | } |
| 8507 | return esn; |
| 8508 | } finally { |
| 8509 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8510 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8511 | } |
| 8512 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8513 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8514 | * Return the Preferred Roaming List Version. |
| 8515 | * |
| 8516 | * @param subId the subscription ID that this request applies to. |
| 8517 | * @return PRLVersion or null if error. |
| 8518 | */ |
| 8519 | @Override |
| 8520 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8521 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8522 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8523 | |
| 8524 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8525 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8526 | if (phone == null) { |
| 8527 | return null; |
| 8528 | } |
| 8529 | String cdmaPrlVersion = null; |
| 8530 | try { |
| 8531 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8532 | } catch (Exception e) { |
| 8533 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8534 | } |
| 8535 | return cdmaPrlVersion; |
| 8536 | } finally { |
| 8537 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8538 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8539 | } |
| 8540 | |
| 8541 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8542 | * Get snapshot of Telephony histograms |
| 8543 | * @return List of Telephony histograms |
| 8544 | * @hide |
| 8545 | */ |
| 8546 | @Override |
| 8547 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8549 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8550 | |
| 8551 | final long identity = Binder.clearCallingIdentity(); |
| 8552 | try { |
| 8553 | return RIL.getTelephonyRILTimingHistograms(); |
| 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
| 8556 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8557 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8558 | |
| 8559 | /** |
| 8560 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8561 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8562 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8563 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8564 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8565 | * @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] | 8566 | */ |
| 8567 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8568 | @TelephonyManager.SetCarrierRestrictionResult |
| 8569 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8570 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8571 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8572 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8573 | if (carrierRestrictionRules == null) { |
| 8574 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8575 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8577 | final long identity = Binder.clearCallingIdentity(); |
| 8578 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8579 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8580 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8581 | } finally { |
| 8582 | Binder.restoreCallingIdentity(identity); |
| 8583 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8584 | } |
| 8585 | |
| 8586 | /** |
| 8587 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8588 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8589 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8590 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8591 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8592 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8593 | */ |
| 8594 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8595 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8596 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8597 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8598 | |
| 8599 | final long identity = Binder.clearCallingIdentity(); |
| 8600 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8601 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8602 | if (response instanceof CarrierRestrictionRules) { |
| 8603 | return (CarrierRestrictionRules) response; |
| 8604 | } |
| 8605 | // Response is an Exception of some kind, |
| 8606 | // which is signalled to the user as a NULL retval |
| 8607 | return null; |
| 8608 | } catch (Exception e) { |
| 8609 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8610 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8611 | } finally { |
| 8612 | Binder.restoreCallingIdentity(identity); |
| 8613 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8614 | } |
| 8615 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8616 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8617 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8618 | * through the callback. |
| 8619 | * |
| 8620 | * @param callback The callback that will be used to send the result. |
| 8621 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8622 | * the caller is not allowlisted. |
| 8623 | */ |
| 8624 | @Override |
| 8625 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8626 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8627 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8628 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8629 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8630 | throw new SecurityException("Not an authorized caller"); |
| 8631 | } |
| 8632 | final long identity = Binder.clearCallingIdentity(); |
| 8633 | try { |
| 8634 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8635 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8636 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8637 | } finally { |
| 8638 | Binder.restoreCallingIdentity(identity); |
| 8639 | } |
| 8640 | } |
| 8641 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 8642 | @Override |
| 8643 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 8644 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 8645 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8646 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 8647 | } |
| 8648 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8649 | @VisibleForTesting |
| 8650 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8651 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8652 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8653 | } |
| 8654 | |
| 8655 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8656 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8657 | * @param subId the subscription ID that this action applies to. |
| 8658 | * @param enabled control enable or disable radio. |
| 8659 | * {@hide} |
| 8660 | */ |
| 8661 | @Override |
| 8662 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8663 | enforceModifyPermission(); |
| 8664 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8665 | |
| 8666 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8667 | if (phone == null) { |
| 8668 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8669 | return; |
| 8670 | } |
| 8671 | try { |
| 8672 | phone.carrierActionSetRadioEnabled(enabled); |
| 8673 | } catch (Exception e) { |
| 8674 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8675 | } finally { |
| 8676 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8677 | } |
| 8678 | } |
| 8679 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8680 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8681 | * Enable or disable Voice over NR (VoNR) |
| 8682 | * @param subId the subscription ID that this action applies to. |
| 8683 | * @param enabled enable or disable VoNR. |
| 8684 | * @return operation result. |
| 8685 | */ |
| 8686 | @Override |
| 8687 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8688 | enforceModifyPermission(); |
| 8689 | final Phone phone = getPhone(subId); |
| 8690 | |
| 8691 | final long identity = Binder.clearCallingIdentity(); |
| 8692 | if (phone == null) { |
| 8693 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8694 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8695 | } |
| 8696 | |
| 8697 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8698 | try { |
| 8699 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8700 | workSource); |
| 8701 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8702 | |
| 8703 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8704 | if (DBG) { |
| 8705 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8706 | } |
| 8707 | SubscriptionManager.setSubscriptionProperty( |
| 8708 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8709 | (enabled ? "1" : "0")); |
| 8710 | } |
| 8711 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8712 | return result; |
| 8713 | } finally { |
| 8714 | Binder.restoreCallingIdentity(identity); |
| 8715 | } |
| 8716 | } |
| 8717 | |
| 8718 | /** |
| 8719 | * Is voice over NR enabled |
| 8720 | * @return true if VoNR is enabled else false |
| 8721 | */ |
| 8722 | @Override |
| 8723 | public boolean isVoNrEnabled(int subId) { |
| 8724 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8725 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8726 | final long identity = Binder.clearCallingIdentity(); |
| 8727 | try { |
| 8728 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8729 | null, subId, workSource); |
| 8730 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8731 | return isEnabled; |
| 8732 | } finally { |
| 8733 | Binder.restoreCallingIdentity(identity); |
| 8734 | } |
| 8735 | } |
| 8736 | |
| 8737 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8738 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8739 | * network status based on which carrier apps could apply actions accordingly, |
| 8740 | * enable/disable default url handler for example. |
| 8741 | * |
| 8742 | * @param subId the subscription ID that this action applies to. |
| 8743 | * @param report control start/stop reporting the default network status. |
| 8744 | * {@hide} |
| 8745 | */ |
| 8746 | @Override |
| 8747 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8748 | enforceModifyPermission(); |
| 8749 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8750 | |
| 8751 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8752 | if (phone == null) { |
| 8753 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8754 | return; |
| 8755 | } |
| 8756 | try { |
| 8757 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8758 | } catch (Exception e) { |
| 8759 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8760 | } finally { |
| 8761 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8762 | } |
| 8763 | } |
| 8764 | |
| 8765 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8766 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8767 | * @param subId the subscription ID that this action applies to. |
| 8768 | * {@hide} |
| 8769 | */ |
| 8770 | @Override |
| 8771 | public void carrierActionResetAll(int subId) { |
| 8772 | enforceModifyPermission(); |
| 8773 | final Phone phone = getPhone(subId); |
| 8774 | if (phone == null) { |
| 8775 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8776 | return; |
| 8777 | } |
| 8778 | try { |
| 8779 | phone.carrierActionResetAll(); |
| 8780 | } catch (Exception e) { |
| 8781 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8782 | } |
| 8783 | } |
| 8784 | |
| 8785 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8786 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8787 | * bug report is being generated. |
| 8788 | */ |
| 8789 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8790 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8791 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8792 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8793 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8794 | + Binder.getCallingPid() |
| 8795 | + ", uid=" + Binder.getCallingUid() |
| 8796 | + "without permission " |
| 8797 | + android.Manifest.permission.DUMP); |
| 8798 | return; |
| 8799 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8800 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8801 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8802 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8803 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8804 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8805 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8806 | @NonNull String[] args) { |
| 8807 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8808 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8809 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8810 | } |
| 8811 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8812 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8813 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8814 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8815 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8816 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8817 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8818 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8819 | */ |
| 8820 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8821 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8822 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8823 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8824 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8825 | try { |
| 8826 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8827 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8828 | } catch (SecurityException se) { |
| 8829 | enforceModifyPermission(); |
| 8830 | } |
| 8831 | } else { |
| 8832 | enforceModifyPermission(); |
| 8833 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8834 | |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 8835 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 8836 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 8837 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(), |
| 8838 | callingPackage, null, null); |
| 8839 | } |
| 8840 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8841 | final long identity = Binder.clearCallingIdentity(); |
| 8842 | try { |
| 8843 | Phone phone = getPhone(subId); |
| 8844 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8845 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8846 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8847 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8848 | phone.getDataSettingsManager().setDataEnabled( |
| 8849 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8850 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8851 | } |
| 8852 | } finally { |
| 8853 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8854 | } |
| 8855 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8856 | |
| 8857 | /** |
| 8858 | * Get Client request stats |
| 8859 | * @return List of Client Request Stats |
| 8860 | * @hide |
| 8861 | */ |
| 8862 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8863 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8864 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8865 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8866 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8867 | return null; |
| 8868 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8869 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8870 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8871 | final long identity = Binder.clearCallingIdentity(); |
| 8872 | try { |
| 8873 | if (phone != null) { |
| 8874 | return phone.getClientRequestStats(); |
| 8875 | } |
| 8876 | |
| 8877 | return null; |
| 8878 | } finally { |
| 8879 | Binder.restoreCallingIdentity(identity); |
| 8880 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8881 | } |
| 8882 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8883 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8884 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8885 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8886 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8887 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8888 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8889 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8890 | // commands that plumb through the RIL as root, like so: |
| 8891 | // $ adb root |
| 8892 | // $ adb shell cmd phone ... |
| 8893 | packageName = "root"; |
| 8894 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8895 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8896 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8897 | |
| 8898 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8899 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8900 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8901 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8902 | * @param state State of SIM (power down, power up, pass through) |
| 8903 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8904 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8905 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8906 | * |
| 8907 | **/ |
| 8908 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8909 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8910 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8911 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8912 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8913 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8914 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8915 | final long identity = Binder.clearCallingIdentity(); |
| 8916 | try { |
| 8917 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8918 | phone.setSimPowerState(state, null, workSource); |
| 8919 | } |
| 8920 | } finally { |
| 8921 | Binder.restoreCallingIdentity(identity); |
| 8922 | } |
| 8923 | } |
| 8924 | |
| 8925 | /** |
| 8926 | * Set SIM card power state. |
| 8927 | * |
| 8928 | * @param slotIndex SIM slot id. |
| 8929 | * @param state State of SIM (power down, power up, pass through) |
| 8930 | * @param callback callback to trigger after success or failure |
| 8931 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8932 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8933 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8934 | * |
| 8935 | **/ |
| 8936 | @Override |
| 8937 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8938 | IIntegerConsumer callback) { |
| 8939 | enforceModifyPermission(); |
| 8940 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8941 | |
| 8942 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8943 | |
| 8944 | final long identity = Binder.clearCallingIdentity(); |
| 8945 | try { |
| 8946 | if (phone != null) { |
| 8947 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8948 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8949 | } |
| 8950 | } finally { |
| 8951 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8952 | } |
| 8953 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8954 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8955 | private boolean isUssdApiAllowed(int subId) { |
| 8956 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8957 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8958 | if (configManager == null) { |
| 8959 | return false; |
| 8960 | } |
| 8961 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8962 | if (pb == null) { |
| 8963 | return false; |
| 8964 | } |
| 8965 | return pb.getBoolean( |
| 8966 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8967 | } |
| 8968 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8969 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8970 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8971 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8972 | * @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] | 8973 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8974 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8975 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8976 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8977 | final long identity = Binder.clearCallingIdentity(); |
| 8978 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 8979 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8980 | } finally { |
| 8981 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8982 | } |
| 8983 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8984 | |
| 8985 | /** |
| 8986 | * Get the current signal strength information for the given subscription. |
| 8987 | * Because this information is not updated when the device is in a low power state |
| 8988 | * it should not be relied-upon to be current. |
| 8989 | * @param subId Subscription index |
| 8990 | * @return the most recent cached signal strength info from the modem |
| 8991 | */ |
| 8992 | @Override |
| 8993 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8994 | final long identity = Binder.clearCallingIdentity(); |
| 8995 | try { |
| 8996 | Phone p = getPhone(subId); |
| 8997 | if (p == null) { |
| 8998 | return null; |
| 8999 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9000 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9001 | return p.getSignalStrength(); |
| 9002 | } finally { |
| 9003 | Binder.restoreCallingIdentity(identity); |
| 9004 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9005 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9006 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9007 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9008 | * Get the current modem radio state for the given slot. |
| 9009 | * @param slotIndex slot index. |
| 9010 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9011 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9012 | * @return the current radio power state from the modem |
| 9013 | */ |
| 9014 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9015 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9016 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9017 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9018 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9019 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9020 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9021 | } |
| 9022 | |
| 9023 | final long identity = Binder.clearCallingIdentity(); |
| 9024 | try { |
| 9025 | return phone.getRadioPowerState(); |
| 9026 | } finally { |
| 9027 | Binder.restoreCallingIdentity(identity); |
| 9028 | } |
| 9029 | } |
| 9030 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9031 | } |
| 9032 | |
| 9033 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9034 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9035 | * |
| 9036 | * <p>Requires one of the following permissions: |
| 9037 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9038 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9039 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9040 | * privileges. |
| 9041 | * |
| 9042 | * @param subId subscription id |
| 9043 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9044 | * {@code false}. |
| 9045 | */ |
| 9046 | @Override |
| 9047 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9048 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9049 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9050 | try { |
| 9051 | mApp.enforceCallingOrSelfPermission( |
| 9052 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9053 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9054 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9055 | mApp.enforceCallingOrSelfPermission( |
| 9056 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9057 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9058 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9059 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9060 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9061 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9062 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9063 | boolean isEnabled = false; |
| 9064 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9065 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9066 | Phone phone = getPhone(subId); |
| 9067 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9068 | } finally { |
| 9069 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9070 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9071 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9072 | } |
| 9073 | |
| 9074 | |
| 9075 | /** |
| 9076 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9077 | * |
| 9078 | * <p> Requires permission: |
| 9079 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9080 | * privileges. |
| 9081 | * |
| 9082 | * @param subId subscription id |
| 9083 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9084 | */ |
| 9085 | @Override |
| 9086 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9087 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9088 | mApp, subId, "setDataRoamingEnabled"); |
| 9089 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9090 | final long identity = Binder.clearCallingIdentity(); |
| 9091 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9092 | Phone phone = getPhone(subId); |
| 9093 | if (phone != null) { |
| 9094 | phone.setDataRoamingEnabled(isEnabled); |
| 9095 | } |
| 9096 | } finally { |
| 9097 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9098 | } |
| 9099 | } |
| 9100 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9101 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9102 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9103 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9104 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9105 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9106 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9107 | boolean isAllowed = true; |
| 9108 | final long identity = Binder.clearCallingIdentity(); |
| 9109 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9110 | Phone phone = getPhone(subId); |
| 9111 | if (phone != null) { |
| 9112 | isAllowed = phone.isCspPlmnEnabled(); |
| 9113 | } |
| 9114 | } finally { |
| 9115 | Binder.restoreCallingIdentity(identity); |
| 9116 | } |
| 9117 | return isAllowed; |
| 9118 | } |
| 9119 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9120 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9121 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9122 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9123 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9124 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9125 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9126 | if (phone == null) { |
| 9127 | return false; |
| 9128 | } |
| 9129 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9130 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9131 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9132 | } |
| 9133 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9134 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9135 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9136 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9137 | mApp.getSystemService(AppOpsManager.class) |
| 9138 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9139 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9140 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9141 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9142 | try { |
| 9143 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9144 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9145 | } catch (SecurityException e) { |
| 9146 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9147 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9148 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9149 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9150 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9151 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9152 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9153 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9154 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9155 | Binder.getCallingUid())) { |
| 9156 | isIccIdAccessRestricted = true; |
| 9157 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9158 | final long identity = Binder.clearCallingIdentity(); |
| 9159 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9160 | UiccController uiccController = UiccController.getInstance(); |
| 9161 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9162 | if (hasReadPermission) { |
| 9163 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9164 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9165 | |
| 9166 | // Remove private info if the caller doesn't have access |
| 9167 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9168 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9169 | //setting the value after compatibility check |
| 9170 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9171 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9172 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9173 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9174 | if (card == null) { |
| 9175 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9176 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9177 | continue; |
| 9178 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9179 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9180 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9181 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9182 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9183 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9184 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9185 | for (UiccPortInfo portInfo : portInfos) { |
| 9186 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9187 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9188 | if (port == null) { |
| 9189 | // assume no access if port is null |
| 9190 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9191 | continue; |
| 9192 | } |
| 9193 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9194 | uiccPortInfos.add(portInfo); |
| 9195 | } else { |
| 9196 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9197 | } |
| 9198 | } |
| 9199 | filteredInfos.add(new UiccCardInfo( |
| 9200 | cardInfo.isEuicc(), |
| 9201 | cardInfo.getCardId(), |
| 9202 | null, |
| 9203 | cardInfo.getPhysicalSlotIndex(), |
| 9204 | cardInfo.isRemovable(), |
| 9205 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9206 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9207 | } |
| 9208 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9209 | } finally { |
| 9210 | Binder.restoreCallingIdentity(identity); |
| 9211 | } |
| 9212 | } |
| 9213 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9214 | /** |
| 9215 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9216 | * generally private and require carrier privileges to view. |
| 9217 | * |
| 9218 | * @hide |
| 9219 | */ |
| 9220 | @NonNull |
| 9221 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9222 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9223 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9224 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9225 | } |
| 9226 | return new UiccCardInfo( |
| 9227 | cardInfo.isEuicc(), |
| 9228 | cardInfo.getCardId(), |
| 9229 | null, |
| 9230 | cardInfo.getPhysicalSlotIndex(), |
| 9231 | cardInfo.isRemovable(), |
| 9232 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9233 | portinfo |
| 9234 | ); |
| 9235 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9236 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9237 | /** |
| 9238 | * @hide |
| 9239 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9240 | * These values are generally private and require carrier privileges to view. |
| 9241 | */ |
| 9242 | @NonNull |
| 9243 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9244 | return new UiccPortInfo( |
| 9245 | UiccPortInfo.ICCID_REDACTED, |
| 9246 | portInfo.getPortIndex(), |
| 9247 | portInfo.getLogicalSlotIndex(), |
| 9248 | portInfo.isActive() |
| 9249 | ); |
| 9250 | } |
| 9251 | @Override |
| 9252 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9253 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9254 | mApp.getSystemService(AppOpsManager.class) |
| 9255 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9256 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9257 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9258 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9259 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9260 | // we are reading iccId which is PII data. |
| 9261 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9262 | |
| 9263 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9264 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9265 | Binder.getCallingUid())) { |
| 9266 | isLogicalSlotAccessRestricted = true; |
| 9267 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9268 | final long identity = Binder.clearCallingIdentity(); |
| 9269 | try { |
| 9270 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9271 | if (slots == null || slots.length == 0) { |
| 9272 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9273 | return null; |
| 9274 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9275 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9276 | for (int i = 0; i < slots.length; i++) { |
| 9277 | UiccSlot slot = slots[i]; |
| 9278 | if (slot == null) { |
| 9279 | continue; |
| 9280 | } |
| 9281 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9282 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9283 | UiccCard card = slot.getUiccCard(); |
| 9284 | if (card != null) { |
| 9285 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9286 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9287 | cardId = slot.getEid(); |
| 9288 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9289 | // If cardId is null, use iccId of default port as cardId. |
| 9290 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9292 | } |
| 9293 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9294 | if (cardId != null) { |
| 9295 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9296 | // if cardId is an EID, it's all digits so this is fine |
| 9297 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9298 | } |
| 9299 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9300 | int cardState = 0; |
| 9301 | switch (slot.getCardState()) { |
| 9302 | case CARDSTATE_ABSENT: |
| 9303 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9304 | break; |
| 9305 | case CARDSTATE_PRESENT: |
| 9306 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9307 | break; |
| 9308 | case CARDSTATE_ERROR: |
| 9309 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9310 | break; |
| 9311 | case CARDSTATE_RESTRICTED: |
| 9312 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9313 | break; |
| 9314 | default: |
| 9315 | break; |
| 9316 | |
| 9317 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9318 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9319 | int[] portIndexes = slot.getPortList(); |
| 9320 | for (int portIdx : portIndexes) { |
| 9321 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9322 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9323 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9324 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9325 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9326 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9327 | slot.isEuicc(), |
| 9328 | cardId, |
| 9329 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9330 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9331 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9332 | //setting the value after compatibility check |
| 9333 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9334 | } |
| 9335 | return infos; |
| 9336 | } finally { |
| 9337 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9338 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9339 | } |
| 9340 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9341 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9342 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9343 | boolean hasReadPermission) { |
| 9344 | String iccId = slot.getIccId(portIndex); |
| 9345 | if (hasReadPermission) { // if has read permission |
| 9346 | return iccId; |
| 9347 | } else { |
| 9348 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9349 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9350 | // if no read permission, checking carrier privilege access |
| 9351 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9352 | return iccId; |
| 9353 | } |
| 9354 | } |
| 9355 | } |
| 9356 | // No read permission or carrier privilege access. |
| 9357 | return UiccPortInfo.ICCID_REDACTED; |
| 9358 | } |
| 9359 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9360 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9361 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9362 | public boolean switchSlots(int[] physicalSlots) { |
| 9363 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9364 | |
| 9365 | final long identity = Binder.clearCallingIdentity(); |
| 9366 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9367 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9368 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9369 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9370 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9371 | physicalSlots[i], i)); |
| 9372 | } |
| 9373 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9374 | } finally { |
| 9375 | Binder.restoreCallingIdentity(identity); |
| 9376 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9377 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9378 | |
| 9379 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9380 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9381 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9382 | enforceModifyPermission(); |
| 9383 | |
| 9384 | final long identity = Binder.clearCallingIdentity(); |
| 9385 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9386 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9387 | } finally { |
| 9388 | Binder.restoreCallingIdentity(identity); |
| 9389 | } |
| 9390 | } |
| 9391 | |
| 9392 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9393 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9394 | final long identity = Binder.clearCallingIdentity(); |
| 9395 | try { |
| 9396 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9397 | } finally { |
| 9398 | Binder.restoreCallingIdentity(identity); |
| 9399 | } |
| 9400 | } |
| 9401 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9402 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9403 | * A test API to reload the UICC profile. |
| 9404 | * |
| 9405 | * <p>Requires that the calling app has permission |
| 9406 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9407 | * @hide |
| 9408 | */ |
| 9409 | @Override |
| 9410 | public void refreshUiccProfile(int subId) { |
| 9411 | enforceModifyPermission(); |
| 9412 | |
| 9413 | final long identity = Binder.clearCallingIdentity(); |
| 9414 | try { |
| 9415 | Phone phone = getPhone(subId); |
| 9416 | if (phone == null) { |
| 9417 | return; |
| 9418 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9419 | UiccPort uiccPort = phone.getUiccPort(); |
| 9420 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9421 | return; |
| 9422 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9423 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9424 | if (uiccProfile == null) { |
| 9425 | return; |
| 9426 | } |
| 9427 | uiccProfile.refresh(); |
| 9428 | } finally { |
| 9429 | Binder.restoreCallingIdentity(identity); |
| 9430 | } |
| 9431 | } |
| 9432 | |
| 9433 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9434 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9435 | */ |
| 9436 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9437 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9438 | } |
| 9439 | |
| 9440 | /** |
| 9441 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9442 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9443 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9444 | */ |
| 9445 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9446 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9447 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9448 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9449 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9450 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9451 | return isDataRoamingEnabled; |
| 9452 | } |
| 9453 | |
| 9454 | /** |
| 9455 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9456 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9457 | */ |
| 9458 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9459 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9460 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9461 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9462 | return list.get(phoneId); |
| 9463 | } |
| 9464 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9465 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9466 | |
| 9467 | @Override |
| 9468 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9469 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9470 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9471 | |
| 9472 | final long identity = Binder.clearCallingIdentity(); |
| 9473 | try { |
| 9474 | final Phone phone = getPhone(subId); |
| 9475 | if (phone == null) { |
| 9476 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9477 | return; |
| 9478 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9479 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9480 | if (cpt != null) { |
| 9481 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9482 | } |
| 9483 | // 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] | 9484 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9485 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9486 | if (carrierPrivilegeRules == null) { |
| 9487 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9488 | } else { |
| 9489 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9490 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9491 | } finally { |
| 9492 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9493 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9494 | } |
| 9495 | |
| 9496 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9497 | public void setCarrierServicePackageOverride( |
| 9498 | int subId, String carrierServicePackage, String callingPackage) { |
| 9499 | TelephonyPermissions.enforceShellOnly( |
| 9500 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9501 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9502 | final long identity = Binder.clearCallingIdentity(); |
| 9503 | try { |
| 9504 | final Phone phone = getPhone(subId); |
| 9505 | if (phone == null || phone.getSubId() != subId) { |
| 9506 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9507 | throw new IllegalArgumentException("No phone for subid"); |
| 9508 | } |
| 9509 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9510 | if (cpt == null) { |
| 9511 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9512 | throw new IllegalStateException("No CPT for phone"); |
| 9513 | } |
| 9514 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9515 | } finally { |
| 9516 | Binder.restoreCallingIdentity(identity); |
| 9517 | } |
| 9518 | } |
| 9519 | |
| 9520 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9521 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9522 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9523 | |
| 9524 | final long identity = Binder.clearCallingIdentity(); |
| 9525 | try { |
| 9526 | final Phone phone = getPhone(subId); |
| 9527 | if (phone == null) { |
| 9528 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9529 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9530 | } |
| 9531 | return phone.getCarrierIdListVersion(); |
| 9532 | } finally { |
| 9533 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9534 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9535 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9536 | |
| 9537 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9538 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9539 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9540 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9541 | mApp, subId, callingPackage, callingFeatureId, |
| 9542 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9543 | return -1; |
| 9544 | } |
| 9545 | |
| 9546 | final long identity = Binder.clearCallingIdentity(); |
| 9547 | try { |
| 9548 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9549 | } finally { |
| 9550 | Binder.restoreCallingIdentity(identity); |
| 9551 | } |
| 9552 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9553 | |
| 9554 | @Override |
| 9555 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9556 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9557 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9558 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9559 | |
| 9560 | final long identity = Binder.clearCallingIdentity(); |
| 9561 | try { |
| 9562 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9563 | } finally { |
| 9564 | Binder.restoreCallingIdentity(identity); |
| 9565 | } |
| 9566 | } |
| 9567 | |
| 9568 | @Override |
| 9569 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9570 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9571 | mApp, subId, "setCdmaRoamingMode"); |
| 9572 | |
| 9573 | final long identity = Binder.clearCallingIdentity(); |
| 9574 | try { |
| 9575 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9576 | } finally { |
| 9577 | Binder.restoreCallingIdentity(identity); |
| 9578 | } |
| 9579 | } |
| 9580 | |
| 9581 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9582 | public int getCdmaSubscriptionMode(int subId) { |
| 9583 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9584 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9585 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9586 | |
| 9587 | final long identity = Binder.clearCallingIdentity(); |
| 9588 | try { |
| 9589 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9590 | } finally { |
| 9591 | Binder.restoreCallingIdentity(identity); |
| 9592 | } |
| 9593 | } |
| 9594 | |
| 9595 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9596 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9598 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9599 | |
| 9600 | final long identity = Binder.clearCallingIdentity(); |
| 9601 | try { |
| 9602 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9603 | } finally { |
| 9604 | Binder.restoreCallingIdentity(identity); |
| 9605 | } |
| 9606 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9607 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9608 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9609 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9610 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9611 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9612 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9613 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9614 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9615 | } |
| 9616 | final long identity = Binder.clearCallingIdentity(); |
| 9617 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9618 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9619 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9620 | if (phone.getEmergencyNumberTracker() != null |
| 9621 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9622 | emergencyNumberListInternal.put( |
| 9623 | phone.getSubId(), |
| 9624 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9625 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9626 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9627 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9628 | } finally { |
| 9629 | Binder.restoreCallingIdentity(identity); |
| 9630 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9631 | } |
| 9632 | |
| 9633 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9634 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9635 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9636 | if (!exactMatch) { |
| 9637 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9638 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9639 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9640 | } |
| 9641 | final long identity = Binder.clearCallingIdentity(); |
| 9642 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9643 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9644 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9645 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9646 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9647 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9648 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9649 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9650 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9651 | } |
| 9652 | return false; |
| 9653 | } finally { |
| 9654 | Binder.restoreCallingIdentity(identity); |
| 9655 | } |
| 9656 | } |
| 9657 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9658 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9659 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9660 | */ |
| 9661 | @Override |
| 9662 | public void startEmergencyCallbackMode() { |
| 9663 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9664 | "startEmergencyCallbackMode"); |
| 9665 | enforceModifyPermission(); |
| 9666 | final long identity = Binder.clearCallingIdentity(); |
| 9667 | try { |
| 9668 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9669 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9670 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9671 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9672 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9673 | gsmCdmaPhone.obtainMessage( |
| 9674 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9675 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9676 | } |
| 9677 | } |
| 9678 | } finally { |
| 9679 | Binder.restoreCallingIdentity(identity); |
| 9680 | } |
| 9681 | } |
| 9682 | |
| 9683 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9684 | * Update emergency number list for test mode. |
| 9685 | */ |
| 9686 | @Override |
| 9687 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9688 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9689 | "updateEmergencyNumberListTestMode"); |
| 9690 | |
| 9691 | final long identity = Binder.clearCallingIdentity(); |
| 9692 | try { |
| 9693 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9694 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9695 | if (tracker != null) { |
| 9696 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9697 | } |
| 9698 | } |
| 9699 | } finally { |
| 9700 | Binder.restoreCallingIdentity(identity); |
| 9701 | } |
| 9702 | } |
| 9703 | |
| 9704 | /** |
| 9705 | * Get the full emergency number list for test mode. |
| 9706 | */ |
| 9707 | @Override |
| 9708 | public List<String> getEmergencyNumberListTestMode() { |
| 9709 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9710 | "getEmergencyNumberListTestMode"); |
| 9711 | |
| 9712 | final long identity = Binder.clearCallingIdentity(); |
| 9713 | try { |
| 9714 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9715 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9716 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9717 | if (tracker != null) { |
| 9718 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9719 | emergencyNumbers.add(num.getNumber()); |
| 9720 | } |
| 9721 | } |
| 9722 | } |
| 9723 | return new ArrayList<>(emergencyNumbers); |
| 9724 | } finally { |
| 9725 | Binder.restoreCallingIdentity(identity); |
| 9726 | } |
| 9727 | } |
| 9728 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9729 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9730 | public int getEmergencyNumberDbVersion(int subId) { |
| 9731 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9732 | |
| 9733 | final long identity = Binder.clearCallingIdentity(); |
| 9734 | try { |
| 9735 | final Phone phone = getPhone(subId); |
| 9736 | if (phone == null) { |
| 9737 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9738 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9739 | } |
| 9740 | return phone.getEmergencyNumberDbVersion(); |
| 9741 | } finally { |
| 9742 | Binder.restoreCallingIdentity(identity); |
| 9743 | } |
| 9744 | } |
| 9745 | |
| 9746 | @Override |
| 9747 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9748 | enforceModifyPermission(); |
| 9749 | |
| 9750 | final long identity = Binder.clearCallingIdentity(); |
| 9751 | try { |
| 9752 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9753 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9754 | if (tracker != null) { |
| 9755 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9756 | } |
| 9757 | } |
| 9758 | } finally { |
| 9759 | Binder.restoreCallingIdentity(identity); |
| 9760 | } |
| 9761 | } |
| 9762 | |
| 9763 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9764 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9765 | enforceActiveEmergencySessionPermission(); |
| 9766 | |
| 9767 | final long identity = Binder.clearCallingIdentity(); |
| 9768 | try { |
| 9769 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9770 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9771 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9772 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9773 | } |
| 9774 | } |
| 9775 | } finally { |
| 9776 | Binder.restoreCallingIdentity(identity); |
| 9777 | } |
| 9778 | } |
| 9779 | |
| 9780 | @Override |
| 9781 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9782 | enforceActiveEmergencySessionPermission(); |
| 9783 | |
| 9784 | final long identity = Binder.clearCallingIdentity(); |
| 9785 | try { |
| 9786 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9787 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9788 | if (tracker != null) { |
| 9789 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9790 | } |
| 9791 | } |
| 9792 | } finally { |
| 9793 | Binder.restoreCallingIdentity(identity); |
| 9794 | } |
| 9795 | } |
| 9796 | |
| 9797 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9798 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9799 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9800 | Phone phone = getPhone(subId); |
| 9801 | if (phone == null) { |
| 9802 | return null; |
| 9803 | } |
| 9804 | final long identity = Binder.clearCallingIdentity(); |
| 9805 | try { |
| 9806 | UiccProfile profile = UiccController.getInstance() |
| 9807 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9808 | if (profile != null) { |
| 9809 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9810 | } |
| 9811 | } finally { |
| 9812 | Binder.restoreCallingIdentity(identity); |
| 9813 | } |
| 9814 | return null; |
| 9815 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9816 | |
| 9817 | /** |
| 9818 | * Enable or disable a modem stack. |
| 9819 | */ |
| 9820 | @Override |
| 9821 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9822 | enforceModifyPermission(); |
| 9823 | |
| 9824 | final long identity = Binder.clearCallingIdentity(); |
| 9825 | try { |
| 9826 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9827 | if (phone == null) { |
| 9828 | return false; |
| 9829 | } else { |
| 9830 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9831 | } |
| 9832 | } finally { |
| 9833 | Binder.restoreCallingIdentity(identity); |
| 9834 | } |
| 9835 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9836 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9837 | /** |
| 9838 | * Whether a modem stack is enabled or not. |
| 9839 | */ |
| 9840 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9841 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9842 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9843 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9844 | if (phone == null) return false; |
| 9845 | |
| 9846 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9847 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9848 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9849 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9850 | } |
| 9851 | |
| 9852 | final long identity = Binder.clearCallingIdentity(); |
| 9853 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9854 | try { |
| 9855 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9856 | } catch (NoSuchElementException ex) { |
| 9857 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9858 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9859 | } finally { |
| 9860 | Binder.restoreCallingIdentity(identity); |
| 9861 | } |
| 9862 | } |
| 9863 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9864 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9865 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9866 | enforceModifyPermission(); |
| 9867 | |
| 9868 | final long identity = Binder.clearCallingIdentity(); |
| 9869 | try { |
| 9870 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9871 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9872 | .commit(); |
| 9873 | } finally { |
| 9874 | Binder.restoreCallingIdentity(identity); |
| 9875 | } |
| 9876 | } |
| 9877 | |
| 9878 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9879 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9880 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9881 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9882 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9883 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9884 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9885 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9886 | |
| 9887 | final long identity = Binder.clearCallingIdentity(); |
| 9888 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9889 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9890 | } finally { |
| 9891 | Binder.restoreCallingIdentity(identity); |
| 9892 | } |
| 9893 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9894 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9895 | @TelephonyManager.IsMultiSimSupportedResult |
| 9896 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9897 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9898 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9899 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9900 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9901 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9902 | } |
| 9903 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9904 | // supported by the modem, indicate that it is restricted. |
| 9905 | PhoneCapability staticCapability = |
| 9906 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9907 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9908 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9909 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9910 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9911 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9912 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9913 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9914 | } |
| 9915 | // Check if support of multiple SIMs is restricted by carrier |
| 9916 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9917 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9918 | } |
| 9919 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9920 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9921 | } |
| 9922 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9923 | /** |
| 9924 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9925 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9926 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9927 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9928 | * @param numOfSims number of active sims we want to switch to |
| 9929 | */ |
| 9930 | @Override |
| 9931 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9932 | if (numOfSims == 1) { |
| 9933 | enforceModifyPermission(); |
| 9934 | } else { |
| 9935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9936 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9937 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9938 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9939 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9940 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9941 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9942 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9943 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9944 | return; |
| 9945 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9946 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9947 | } finally { |
| 9948 | Binder.restoreCallingIdentity(identity); |
| 9949 | } |
| 9950 | } |
| 9951 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9952 | @Override |
| 9953 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9954 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9955 | Phone phone = getPhone(subId); |
| 9956 | if (phone == null) { |
| 9957 | return false; |
| 9958 | } |
| 9959 | final long identity = Binder.clearCallingIdentity(); |
| 9960 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9961 | UiccPort uiccPort = phone.getUiccPort(); |
| 9962 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9963 | return false; |
| 9964 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9965 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9966 | if (uiccProfile == null) { |
| 9967 | return false; |
| 9968 | } |
| 9969 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9970 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9971 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9972 | } |
| 9973 | return false; |
| 9974 | } finally { |
| 9975 | Binder.restoreCallingIdentity(identity); |
| 9976 | } |
| 9977 | } |
| 9978 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9979 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9980 | * Get whether making changes to modem configurations will trigger reboot. |
| 9981 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9982 | */ |
| 9983 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9984 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9985 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9986 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9987 | mApp, subId, callingPackage, callingFeatureId, |
| 9988 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9989 | return false; |
| 9990 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9991 | final long identity = Binder.clearCallingIdentity(); |
| 9992 | try { |
| 9993 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9994 | } finally { |
| 9995 | Binder.restoreCallingIdentity(identity); |
| 9996 | } |
| 9997 | } |
| 9998 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9999 | private void updateModemStateMetrics() { |
| 10000 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10001 | // TODO: check the state for each modem if the api is ready. |
| 10002 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10003 | } |
| 10004 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10005 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10006 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10007 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10008 | // Verify that the callingPackage belongs to the calling UID |
| 10009 | mApp.getSystemService(AppOpsManager.class) |
| 10010 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10011 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10012 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10013 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10014 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10015 | if (slotInfos != null) { |
| 10016 | for (int i = 0; i < slotInfos.length; i++) { |
| 10017 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10018 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10019 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10020 | portInfo.getLogicalSlotIndex())); |
| 10021 | } |
| 10022 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10023 | } |
| 10024 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10025 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10026 | } finally { |
| 10027 | Binder.restoreCallingIdentity(identity); |
| 10028 | } |
| 10029 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10030 | |
| 10031 | /** |
| 10032 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10033 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10034 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10035 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10036 | @Override |
| 10037 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10038 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10039 | } |
| 10040 | |
| 10041 | /** |
| 10042 | * Get the HAL Version of a specific service |
| 10043 | */ |
| 10044 | @Override |
| 10045 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10046 | Phone phone = getDefaultPhone(); |
| 10047 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10048 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10049 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10050 | return hv.major * 100 + hv.minor; |
| 10051 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10052 | |
| 10053 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10054 | * Get the current calling package name. |
| 10055 | * @return the current calling package name |
| 10056 | */ |
| 10057 | @Override |
| 10058 | public String getCurrentPackageName() { |
| 10059 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10060 | } |
| 10061 | |
| 10062 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10063 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10064 | * corresponding network requests on a subId. |
| 10065 | * |
| 10066 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10067 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10068 | * 2) APN is un-metered for this subscription, or |
| 10069 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10070 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10071 | * |
| 10072 | * @return whether data is allowed for a apn type. |
| 10073 | * |
| 10074 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10075 | */ |
| 10076 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10077 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10078 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10079 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10080 | |
| 10081 | // Now that all security checks passes, perform the operation as ourselves. |
| 10082 | final long identity = Binder.clearCallingIdentity(); |
| 10083 | try { |
| 10084 | Phone phone = getPhone(subId); |
| 10085 | if (phone == null) return false; |
| 10086 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10087 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10088 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10089 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10090 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10091 | phone.getServiceState().getDataRoaming()); |
| 10092 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10093 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10094 | } finally { |
| 10095 | Binder.restoreCallingIdentity(identity); |
| 10096 | } |
| 10097 | } |
| 10098 | |
| 10099 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10100 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10101 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10102 | |
| 10103 | // Now that all security checks passes, perform the operation as ourselves. |
| 10104 | final long identity = Binder.clearCallingIdentity(); |
| 10105 | try { |
| 10106 | Phone phone = getPhone(subId); |
| 10107 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10108 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10109 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10110 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10111 | } finally { |
| 10112 | Binder.restoreCallingIdentity(identity); |
| 10113 | } |
| 10114 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10115 | |
| 10116 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10117 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10118 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10119 | enforceModifyPermission(); |
| 10120 | long token = Binder.clearCallingIdentity(); |
| 10121 | try { |
| 10122 | Phone phone = getPhone(subscriptionId); |
| 10123 | if (phone == null) { |
| 10124 | try { |
| 10125 | if (resultCallback != null) { |
| 10126 | resultCallback.accept(false); |
| 10127 | } |
| 10128 | } catch (RemoteException e) { |
| 10129 | // ignore |
| 10130 | } |
| 10131 | return; |
| 10132 | } |
| 10133 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10134 | Pair.create(specifiers, (x) -> { |
| 10135 | try { |
| 10136 | if (resultCallback != null) { |
| 10137 | resultCallback.accept(x); |
| 10138 | } |
| 10139 | } catch (RemoteException e) { |
| 10140 | // ignore |
| 10141 | } |
| 10142 | }); |
| 10143 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10144 | } finally { |
| 10145 | Binder.restoreCallingIdentity(token); |
| 10146 | } |
| 10147 | } |
| 10148 | |
| 10149 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10150 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10151 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10152 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10153 | mApp, subId, "getSystemSelectionChannels"); |
| 10154 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10155 | final long identity = Binder.clearCallingIdentity(); |
| 10156 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10157 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10158 | if (result instanceof IllegalStateException) { |
| 10159 | throw (IllegalStateException) result; |
| 10160 | } |
| 10161 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10162 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10163 | return specifiers; |
| 10164 | } finally { |
| 10165 | Binder.restoreCallingIdentity(identity); |
| 10166 | } |
| 10167 | } |
| 10168 | |
| 10169 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10170 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10171 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10172 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10173 | } |
| 10174 | |
| 10175 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10176 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10177 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10178 | if (callingPackage == null) { |
| 10179 | callingPackage = getCurrentPackageName(); |
| 10180 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10181 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10182 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10183 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10184 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10185 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10186 | } |
| 10187 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10188 | Intent intent = new Intent(); |
| 10189 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10190 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10191 | // Bring up choose default SMS subscription dialog right now |
| 10192 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10193 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10194 | mApp.startActivity(intent); |
| 10195 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10196 | |
| 10197 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10198 | public void showSwitchToManagedProfileDialog() { |
| 10199 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10200 | try { |
| 10201 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10202 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10203 | // for work telephony. |
| 10204 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10205 | intent.setData(Uri.parse("smsto:")); |
| 10206 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10207 | mApp.startActivity(intent); |
| 10208 | } catch (ActivityNotFoundException e) { |
| 10209 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10210 | Intent intent = new Intent(); |
| 10211 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10212 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10213 | mApp.startActivity(intent); |
| 10214 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10215 | } |
| 10216 | |
| 10217 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10218 | public String getMmsUAProfUrl(int subId) { |
| 10219 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10220 | final long identity = Binder.clearCallingIdentity(); |
| 10221 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10222 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10223 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10224 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10225 | return carrierUAProfUrl; |
| 10226 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10227 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10228 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10229 | } finally { |
| 10230 | Binder.restoreCallingIdentity(identity); |
| 10231 | } |
| 10232 | } |
| 10233 | |
| 10234 | @Override |
| 10235 | public String getMmsUserAgent(int subId) { |
| 10236 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10237 | final long identity = Binder.clearCallingIdentity(); |
| 10238 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10239 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10240 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10241 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10242 | return carrierUserAgent; |
| 10243 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10244 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10245 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10246 | } finally { |
| 10247 | Binder.restoreCallingIdentity(identity); |
| 10248 | } |
| 10249 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10250 | |
| 10251 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10252 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10253 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10254 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10255 | final long identity = Binder.clearCallingIdentity(); |
| 10256 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10257 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10258 | if (phone == null) return false; |
| 10259 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10260 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10261 | } finally { |
| 10262 | Binder.restoreCallingIdentity(identity); |
| 10263 | } |
| 10264 | } |
| 10265 | |
| 10266 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10267 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10268 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10269 | enforceModifyPermission(); |
| 10270 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10271 | final long identity = Binder.clearCallingIdentity(); |
| 10272 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10273 | Phone phone = getPhone(subscriptionId); |
| 10274 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10275 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10276 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10277 | } finally { |
| 10278 | Binder.restoreCallingIdentity(identity); |
| 10279 | } |
| 10280 | } |
| 10281 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10282 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10283 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10284 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10285 | * otherwise. |
| 10286 | */ |
| 10287 | @Override |
| 10288 | public void setCepEnabled(boolean isCepEnabled) { |
| 10289 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10290 | |
| 10291 | final long identity = Binder.clearCallingIdentity(); |
| 10292 | try { |
| 10293 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10294 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10295 | Phone defaultPhone = phone.getImsPhone(); |
| 10296 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10297 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10298 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10299 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10300 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10301 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10302 | + imsPhone.getMsisdn()); |
| 10303 | } |
| 10304 | } |
| 10305 | } finally { |
| 10306 | Binder.restoreCallingIdentity(identity); |
| 10307 | } |
| 10308 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10309 | |
| 10310 | /** |
| 10311 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10312 | * |
| 10313 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10314 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10315 | * before being read. |
| 10316 | */ |
| 10317 | @Override |
| 10318 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10319 | isCompressed) { |
| 10320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10321 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10322 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10323 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10324 | } |
| 10325 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10326 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10327 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10328 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10329 | } |
| 10330 | |
| 10331 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10332 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10333 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10334 | } finally { |
| 10335 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10336 | } |
| 10337 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10338 | |
| 10339 | @Override |
| 10340 | public boolean isIccLockEnabled(int subId) { |
| 10341 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10342 | |
| 10343 | // Now that all security checks passes, perform the operation as ourselves. |
| 10344 | final long identity = Binder.clearCallingIdentity(); |
| 10345 | try { |
| 10346 | Phone phone = getPhone(subId); |
| 10347 | if (phone != null && phone.getIccCard() != null) { |
| 10348 | return phone.getIccCard().getIccLockEnabled(); |
| 10349 | } else { |
| 10350 | return false; |
| 10351 | } |
| 10352 | } finally { |
| 10353 | Binder.restoreCallingIdentity(identity); |
| 10354 | } |
| 10355 | } |
| 10356 | |
| 10357 | /** |
| 10358 | * Set the ICC pin lock enabled or disabled. |
| 10359 | * |
| 10360 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10361 | * three cases: |
| 10362 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10363 | * successfully. |
| 10364 | * - Positive number and zero for remaining password attempts. |
| 10365 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10366 | * |
| 10367 | */ |
| 10368 | @Override |
| 10369 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10370 | enforceModifyPermission(); |
| 10371 | |
| 10372 | Phone phone = getPhone(subId); |
| 10373 | if (phone == null) { |
| 10374 | return 0; |
| 10375 | } |
| 10376 | // Now that all security checks passes, perform the operation as ourselves. |
| 10377 | final long identity = Binder.clearCallingIdentity(); |
| 10378 | try { |
| 10379 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10380 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10381 | return attemptsRemaining; |
| 10382 | |
| 10383 | } catch (Exception e) { |
| 10384 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10385 | } finally { |
| 10386 | Binder.restoreCallingIdentity(identity); |
| 10387 | } |
| 10388 | return 0; |
| 10389 | } |
| 10390 | |
| 10391 | /** |
| 10392 | * Change the ICC password used in ICC pin lock. |
| 10393 | * |
| 10394 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10395 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10396 | * - Positive number and zero for remaining password attempts. |
| 10397 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10398 | * |
| 10399 | */ |
| 10400 | @Override |
| 10401 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10402 | enforceModifyPermission(); |
| 10403 | |
| 10404 | Phone phone = getPhone(subId); |
| 10405 | if (phone == null) { |
| 10406 | return 0; |
| 10407 | } |
| 10408 | // Now that all security checks passes, perform the operation as ourselves. |
| 10409 | final long identity = Binder.clearCallingIdentity(); |
| 10410 | try { |
| 10411 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10412 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10413 | return attemptsRemaining; |
| 10414 | |
| 10415 | } catch (Exception e) { |
| 10416 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10417 | } finally { |
| 10418 | Binder.restoreCallingIdentity(identity); |
| 10419 | } |
| 10420 | return 0; |
| 10421 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10422 | |
| 10423 | /** |
| 10424 | * Request for receiving user activity notification |
| 10425 | */ |
| 10426 | @Override |
| 10427 | public void requestUserActivityNotification() { |
| 10428 | if (!mNotifyUserActivity.get() |
| 10429 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10430 | mNotifyUserActivity.set(true); |
| 10431 | } |
| 10432 | } |
| 10433 | |
| 10434 | /** |
| 10435 | * Called when userActivity is signalled in the power manager. |
| 10436 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10437 | */ |
| 10438 | @Override |
| 10439 | public void userActivity() { |
| 10440 | // *************************************** |
| 10441 | // * Inherited from PhoneWindowManager * |
| 10442 | // *************************************** |
| 10443 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10444 | // WITH ITS LOCKS HELD. |
| 10445 | // |
| 10446 | // This code must be VERY careful about the locks |
| 10447 | // it acquires. |
| 10448 | // In fact, the current code acquires way too many, |
| 10449 | // and probably has lurking deadlocks. |
| 10450 | |
| 10451 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10452 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10453 | } |
| 10454 | |
| 10455 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10456 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10457 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10458 | } |
| 10459 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10460 | |
| 10461 | @Override |
| 10462 | public boolean canConnectTo5GInDsdsMode() { |
| 10463 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10464 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10465 | |
| 10466 | @Override |
| 10467 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10468 | String callingFeatureId) { |
| 10469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10470 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10471 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10472 | } |
| 10473 | |
| 10474 | Phone phone = getPhone(subId); |
| 10475 | if (phone == null) { |
| 10476 | throw new RuntimeException("phone is not available"); |
| 10477 | } |
| 10478 | // Now that all security checks passes, perform the operation as ourselves. |
| 10479 | final long identity = Binder.clearCallingIdentity(); |
| 10480 | try { |
| 10481 | return phone.getEquivalentHomePlmns(); |
| 10482 | } finally { |
| 10483 | Binder.restoreCallingIdentity(identity); |
| 10484 | } |
| 10485 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10486 | |
| 10487 | @Override |
| 10488 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10489 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10490 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10491 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10492 | if (radioInterfaceCapabilities == null) { |
| 10493 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10494 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10495 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10496 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10497 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10498 | @Override |
| 10499 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10500 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10501 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10502 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10503 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10504 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10505 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10506 | if (DBG) { |
| 10507 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10508 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10509 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10510 | } |
| 10511 | |
| 10512 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10513 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10514 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10515 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10516 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10517 | if (callback != null) { |
| 10518 | try { |
| 10519 | callback.onAuthenticationFailure( |
| 10520 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10521 | } catch (RemoteException exception) { |
| 10522 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10523 | } |
| 10524 | return; |
| 10525 | } |
| 10526 | } |
| 10527 | |
| 10528 | final long token = Binder.clearCallingIdentity(); |
| 10529 | try { |
| 10530 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10531 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10532 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10533 | } finally { |
| 10534 | Binder.restoreCallingIdentity(token); |
| 10535 | } |
| 10536 | } |
| 10537 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10538 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10539 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10540 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10541 | * requested radio power state will actually be set. See {@link |
| 10542 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10543 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10544 | * @param enable {@code true} if trying to turn radio on. |
| 10545 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10546 | * false}. |
| 10547 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10548 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10549 | boolean isPhoneAvailable = false; |
| 10550 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10551 | Phone phone = PhoneFactory.getPhone(i); |
| 10552 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10553 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10554 | isPhoneAvailable = true; |
| 10555 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10556 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10557 | |
| 10558 | // return true if successfully informed the phone object about the thermal radio power |
| 10559 | // request. |
| 10560 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10561 | } |
| 10562 | |
| 10563 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10564 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10565 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10566 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10567 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10568 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10569 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10570 | } |
| 10571 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10572 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10573 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10574 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10575 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10576 | } |
| 10577 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10578 | setDataEnabledForReason( |
| 10579 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10580 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10581 | if (isDataThrottlingSupported) { |
| 10582 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10583 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10584 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10585 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10586 | } else if (thermalMitigationResult |
| 10587 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10588 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10589 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10590 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10591 | } |
| 10592 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10593 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10594 | |
| 10595 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10596 | } |
| 10597 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10598 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10599 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10600 | for (String pckg : context.getResources() |
| 10601 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10602 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10603 | } |
| 10604 | } |
| 10605 | |
| 10606 | return sThermalMitigationAllowlistedPackages; |
| 10607 | } |
| 10608 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10609 | private boolean isAnyPhoneInEmergencyState() { |
| 10610 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10611 | if (tm.isInEmergencyCall()) { |
| 10612 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10613 | return true; |
| 10614 | } |
| 10615 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10616 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10617 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10618 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10619 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10620 | return true; |
| 10621 | } |
| 10622 | } |
| 10623 | |
| 10624 | return false; |
| 10625 | } |
| 10626 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10627 | /** |
| 10628 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10629 | * @param packageName name of package to be allowlisted |
| 10630 | * @param context |
| 10631 | */ |
| 10632 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10633 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10634 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10635 | } |
| 10636 | |
| 10637 | /** |
| 10638 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10639 | * @param packageName name of package to remove from allowlist |
| 10640 | * @param context |
| 10641 | */ |
| 10642 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10643 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10644 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10645 | } |
| 10646 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10647 | /** |
| 10648 | * Thermal mitigation request to control functionalities at modem. |
| 10649 | * |
| 10650 | * @param subId the id of the subscription. |
| 10651 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10652 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10653 | * |
| 10654 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10655 | */ |
| 10656 | @Override |
| 10657 | @ThermalMitigationResult |
| 10658 | public int sendThermalMitigationRequest( |
| 10659 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10660 | ThermalMitigationRequest thermalMitigationRequest, |
| 10661 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10662 | enforceModifyPermission(); |
| 10663 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10664 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10665 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10666 | .contains(callingPackage)) { |
| 10667 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10668 | + "calling package: " + callingPackage); |
| 10669 | } |
| 10670 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10671 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10672 | final long identity = Binder.clearCallingIdentity(); |
| 10673 | |
| 10674 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10675 | try { |
| 10676 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10677 | switch (thermalMitigationAction) { |
| 10678 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10679 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10680 | handleDataThrottlingRequest(subId, |
| 10681 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10682 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10683 | break; |
| 10684 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10685 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10686 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10687 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10688 | } |
| 10689 | |
| 10690 | // Ensure that radio is on. If not able to power on due to phone being |
| 10691 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10692 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10693 | thermalMitigationResult = |
| 10694 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10695 | break; |
| 10696 | } |
| 10697 | |
| 10698 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10699 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10700 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10701 | break; |
| 10702 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10703 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10704 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10705 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10706 | } |
| 10707 | |
| 10708 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10709 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10710 | Phone phone = getPhone(subId); |
| 10711 | if (phone == null) { |
| 10712 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10713 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10714 | break; |
| 10715 | } |
| 10716 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10717 | TelephonyConnectionService service = |
| 10718 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10719 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10720 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10721 | thermalMitigationResult = |
| 10722 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10723 | break; |
| 10724 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10725 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10726 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10727 | break; |
| 10728 | } |
| 10729 | } else { |
| 10730 | thermalMitigationResult = |
| 10731 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10732 | break; |
| 10733 | } |
| 10734 | |
| 10735 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10736 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10737 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10738 | thermalMitigationResult = |
| 10739 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10740 | break; |
| 10741 | } |
| 10742 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10743 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10744 | break; |
| 10745 | default: |
| 10746 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10747 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10748 | } |
| 10749 | } catch (IllegalArgumentException e) { |
| 10750 | throw e; |
| 10751 | } catch (Exception e) { |
| 10752 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10753 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10754 | } finally { |
| 10755 | Binder.restoreCallingIdentity(identity); |
| 10756 | } |
| 10757 | |
| 10758 | if (DBG) { |
| 10759 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10760 | + thermalMitigationResult); |
| 10761 | } |
| 10762 | |
| 10763 | return thermalMitigationResult; |
| 10764 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10765 | |
| 10766 | /** |
| 10767 | * Set the GbaService Package Name that Telephony will bind to. |
| 10768 | * |
| 10769 | * @param subId The sim that the GbaService is associated with. |
| 10770 | * @param packageName The name of the package to be replaced with. |
| 10771 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10772 | */ |
| 10773 | @Override |
| 10774 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10775 | enforceModifyPermission(); |
| 10776 | |
| 10777 | final long identity = Binder.clearCallingIdentity(); |
| 10778 | try { |
| 10779 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10780 | } finally { |
| 10781 | Binder.restoreCallingIdentity(identity); |
| 10782 | } |
| 10783 | } |
| 10784 | |
| 10785 | /** |
| 10786 | * Return the package name of the currently bound GbaService. |
| 10787 | * |
| 10788 | * @param subId The sim that the GbaService is associated with. |
| 10789 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10790 | */ |
| 10791 | @Override |
| 10792 | public String getBoundGbaService(int subId) { |
| 10793 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10794 | |
| 10795 | final long identity = Binder.clearCallingIdentity(); |
| 10796 | try { |
| 10797 | return getGbaManager(subId).getServicePackage(); |
| 10798 | } finally { |
| 10799 | Binder.restoreCallingIdentity(identity); |
| 10800 | } |
| 10801 | } |
| 10802 | |
| 10803 | /** |
| 10804 | * Set the release time for telephony to unbind GbaService. |
| 10805 | * |
| 10806 | * @param subId The sim that the GbaService is associated with. |
| 10807 | * @param interval The release time to unbind GbaService by millisecond. |
| 10808 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10809 | */ |
| 10810 | @Override |
| 10811 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10812 | enforceModifyPermission(); |
| 10813 | |
| 10814 | final long identity = Binder.clearCallingIdentity(); |
| 10815 | try { |
| 10816 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10817 | } finally { |
| 10818 | Binder.restoreCallingIdentity(identity); |
| 10819 | } |
| 10820 | } |
| 10821 | |
| 10822 | /** |
| 10823 | * Return the release time for telephony to unbind GbaService. |
| 10824 | * |
| 10825 | * @param subId The sim that the GbaService is associated with. |
| 10826 | * @return The release time to unbind GbaService by millisecond. |
| 10827 | */ |
| 10828 | @Override |
| 10829 | public int getGbaReleaseTime(int subId) { |
| 10830 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10831 | |
| 10832 | final long identity = Binder.clearCallingIdentity(); |
| 10833 | try { |
| 10834 | return getGbaManager(subId).getReleaseTime(); |
| 10835 | } finally { |
| 10836 | Binder.restoreCallingIdentity(identity); |
| 10837 | } |
| 10838 | } |
| 10839 | |
| 10840 | private GbaManager getGbaManager(int subId) { |
| 10841 | GbaManager instance = GbaManager.getInstance(subId); |
| 10842 | if (instance == null) { |
| 10843 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10844 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10845 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10846 | } |
| 10847 | return instance; |
| 10848 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10849 | |
| 10850 | /** |
| 10851 | * indicate whether the device and the carrier can support |
| 10852 | * RCS VoLTE single registration. |
| 10853 | */ |
| 10854 | @Override |
| 10855 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10856 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10857 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10858 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10859 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10860 | |
| 10861 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10862 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10863 | } |
| 10864 | |
| 10865 | final long identity = Binder.clearCallingIdentity(); |
| 10866 | try { |
| 10867 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10868 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10869 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10870 | if (isCapable != null) { |
| 10871 | return isCapable; |
| 10872 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10873 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10874 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10875 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10876 | } finally { |
| 10877 | Binder.restoreCallingIdentity(identity); |
| 10878 | } |
| 10879 | } |
| 10880 | |
| 10881 | /** |
| 10882 | * Register RCS provisioning callback. |
| 10883 | */ |
| 10884 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10885 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10886 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10887 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10888 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10889 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10890 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10891 | |
| 10892 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10893 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10894 | } |
| 10895 | if (!isImsAvailableOnDevice()) { |
| 10896 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10897 | "IMS not available on device."); |
| 10898 | } |
| 10899 | |
| 10900 | final long identity = Binder.clearCallingIdentity(); |
| 10901 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10902 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10903 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10904 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10905 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10906 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10907 | } finally { |
| 10908 | Binder.restoreCallingIdentity(identity); |
| 10909 | } |
| 10910 | } |
| 10911 | |
| 10912 | /** |
| 10913 | * Unregister RCS provisioning callback. |
| 10914 | */ |
| 10915 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10916 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10917 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10918 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10919 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10920 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10921 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10922 | |
| 10923 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10924 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10925 | } |
| 10926 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10927 | // operation failed silently |
| 10928 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10929 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10930 | } |
| 10931 | |
| 10932 | final long identity = Binder.clearCallingIdentity(); |
| 10933 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10934 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10935 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10936 | } finally { |
| 10937 | Binder.restoreCallingIdentity(identity); |
| 10938 | } |
| 10939 | } |
| 10940 | |
| 10941 | /** |
| 10942 | * trigger RCS reconfiguration. |
| 10943 | */ |
| 10944 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10945 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10946 | "triggerRcsReconfiguration", |
| 10947 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10948 | |
| 10949 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10950 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10951 | } |
| 10952 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10953 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10954 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10955 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10956 | } |
| 10957 | |
| 10958 | final long identity = Binder.clearCallingIdentity(); |
| 10959 | try { |
| 10960 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10961 | } finally { |
| 10962 | Binder.restoreCallingIdentity(identity); |
| 10963 | } |
| 10964 | } |
| 10965 | |
| 10966 | /** |
| 10967 | * Provide the client configuration parameters of the RCS application. |
| 10968 | */ |
| 10969 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10970 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10971 | "setRcsClientConfiguration", |
| 10972 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10973 | |
| 10974 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10975 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10976 | } |
| 10977 | if (!isImsAvailableOnDevice()) { |
| 10978 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10979 | "IMS not available on device."); |
| 10980 | } |
| 10981 | |
| 10982 | final long identity = Binder.clearCallingIdentity(); |
| 10983 | |
| 10984 | try { |
| 10985 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10986 | if (configBinder == null) { |
| 10987 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10988 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10989 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10990 | } else { |
| 10991 | configBinder.setRcsClientConfiguration(rcc); |
| 10992 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10993 | |
| 10994 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10995 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10996 | } catch (RemoteException e) { |
| 10997 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10998 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10999 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11000 | } finally { |
| 11001 | Binder.restoreCallingIdentity(identity); |
| 11002 | } |
| 11003 | } |
| 11004 | |
| 11005 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11006 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11007 | */ |
| 11008 | @Override |
| 11009 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11010 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11011 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11012 | |
| 11013 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11014 | } |
| 11015 | |
| 11016 | /** |
| 11017 | * Gets the test mode for RCS VoLTE single registration. |
| 11018 | */ |
| 11019 | @Override |
| 11020 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11021 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11022 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11023 | |
| 11024 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11025 | } |
| 11026 | |
| 11027 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11028 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11029 | */ |
| 11030 | @Override |
| 11031 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11032 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11033 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11034 | enforceModifyPermission(); |
| 11035 | |
| 11036 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11037 | : Boolean.parseBoolean(enabledStr); |
| 11038 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11039 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11040 | } |
| 11041 | |
| 11042 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11043 | * Sends a device to device communication message. Only usable via shell. |
| 11044 | * @param message message to send. |
| 11045 | * @param value message value. |
| 11046 | */ |
| 11047 | @Override |
| 11048 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11049 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11050 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11051 | enforceModifyPermission(); |
| 11052 | |
| 11053 | final long identity = Binder.clearCallingIdentity(); |
| 11054 | try { |
| 11055 | TelephonyConnectionService service = |
| 11056 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11057 | if (service == null) { |
| 11058 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11059 | return; |
| 11060 | } |
| 11061 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11062 | } finally { |
| 11063 | Binder.restoreCallingIdentity(identity); |
| 11064 | } |
| 11065 | } |
| 11066 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11067 | /** |
| 11068 | * Sets the specified device to device transport active. |
| 11069 | * @param transport The transport to set active. |
| 11070 | */ |
| 11071 | @Override |
| 11072 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11073 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11074 | "setActiveDeviceToDeviceTransport"); |
| 11075 | enforceModifyPermission(); |
| 11076 | |
| 11077 | final long identity = Binder.clearCallingIdentity(); |
| 11078 | try { |
| 11079 | TelephonyConnectionService service = |
| 11080 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11081 | if (service == null) { |
| 11082 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11083 | return; |
| 11084 | } |
| 11085 | service.setActiveDeviceToDeviceTransport(transport); |
| 11086 | } finally { |
| 11087 | Binder.restoreCallingIdentity(identity); |
| 11088 | } |
| 11089 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11090 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11091 | @Override |
| 11092 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11093 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11094 | "setDeviceToDeviceForceEnabled"); |
| 11095 | |
| 11096 | final long identity = Binder.clearCallingIdentity(); |
| 11097 | try { |
| 11098 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11099 | p -> { |
| 11100 | Phone thePhone = p.getImsPhone(); |
| 11101 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11102 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11103 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11104 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11105 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11106 | (ImsPhoneCallTracker) tracker; |
| 11107 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11108 | } |
| 11109 | } |
| 11110 | } |
| 11111 | ); |
| 11112 | } finally { |
| 11113 | Binder.restoreCallingIdentity(identity); |
| 11114 | } |
| 11115 | } |
| 11116 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11117 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11118 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11119 | */ |
| 11120 | @Override |
| 11121 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11122 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11123 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11124 | } |
| 11125 | |
| 11126 | /** |
| 11127 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11128 | */ |
| 11129 | @Override |
| 11130 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11131 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11132 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11133 | enforceModifyPermission(); |
| 11134 | |
| 11135 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11136 | : Boolean.parseBoolean(enabledStr); |
| 11137 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11138 | subId, enabled); |
| 11139 | } |
| 11140 | |
| 11141 | /** |
| 11142 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11143 | */ |
| 11144 | @Override |
| 11145 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11146 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11147 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11148 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11149 | |
| 11150 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11151 | * Overrides the ims feature validation result |
| 11152 | */ |
| 11153 | @Override |
| 11154 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11155 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11156 | "setImsFeatureValidationOverride"); |
| 11157 | |
| 11158 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11159 | : Boolean.parseBoolean(enabledStr); |
| 11160 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11161 | subId, enabled); |
| 11162 | } |
| 11163 | |
| 11164 | /** |
| 11165 | * Gets the ims feature validation override value |
| 11166 | */ |
| 11167 | @Override |
| 11168 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11169 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11170 | "getImsFeatureValidationOverride"); |
| 11171 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11172 | } |
| 11173 | |
| 11174 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11175 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11176 | * their mobile plan. |
| 11177 | */ |
| 11178 | @Override |
| 11179 | public String getMobileProvisioningUrl() { |
| 11180 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11181 | final long identity = Binder.clearCallingIdentity(); |
| 11182 | try { |
| 11183 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11184 | } finally { |
| 11185 | Binder.restoreCallingIdentity(identity); |
| 11186 | } |
| 11187 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11188 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11189 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11190 | * Get the EAB contact from the EAB database. |
| 11191 | */ |
| 11192 | @Override |
| 11193 | public String getContactFromEab(String contact) { |
| 11194 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11195 | enforceModifyPermission(); |
| 11196 | final long identity = Binder.clearCallingIdentity(); |
| 11197 | try { |
| 11198 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11199 | } finally { |
| 11200 | Binder.restoreCallingIdentity(identity); |
| 11201 | } |
| 11202 | } |
| 11203 | |
| 11204 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11205 | * Get the EAB capability from the EAB database. |
| 11206 | */ |
| 11207 | @Override |
| 11208 | public String getCapabilityFromEab(String contact) { |
| 11209 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11210 | enforceModifyPermission(); |
| 11211 | final long identity = Binder.clearCallingIdentity(); |
| 11212 | try { |
| 11213 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11214 | } finally { |
| 11215 | Binder.restoreCallingIdentity(identity); |
| 11216 | } |
| 11217 | } |
| 11218 | |
| 11219 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11220 | * Remove the EAB contacts from the EAB database. |
| 11221 | */ |
| 11222 | @Override |
| 11223 | public int removeContactFromEab(int subId, String contacts) { |
| 11224 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11225 | enforceModifyPermission(); |
| 11226 | final long identity = Binder.clearCallingIdentity(); |
| 11227 | try { |
| 11228 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11229 | } finally { |
| 11230 | Binder.restoreCallingIdentity(identity); |
| 11231 | } |
| 11232 | } |
| 11233 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11234 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11235 | public boolean getDeviceUceEnabled() { |
| 11236 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11237 | final long identity = Binder.clearCallingIdentity(); |
| 11238 | try { |
| 11239 | return mApp.getDeviceUceEnabled(); |
| 11240 | } finally { |
| 11241 | Binder.restoreCallingIdentity(identity); |
| 11242 | } |
| 11243 | } |
| 11244 | |
| 11245 | @Override |
| 11246 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11247 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11248 | final long identity = Binder.clearCallingIdentity(); |
| 11249 | try { |
| 11250 | mApp.setDeviceUceEnabled(isEnabled); |
| 11251 | } finally { |
| 11252 | Binder.restoreCallingIdentity(identity); |
| 11253 | } |
| 11254 | } |
| 11255 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11256 | /** |
| 11257 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11258 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11259 | */ |
| 11260 | // Used for SHELL command only right now. |
| 11261 | @Override |
| 11262 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11263 | List<String> featureTags) { |
| 11264 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11265 | "addUceRegistrationOverrideShell"); |
| 11266 | final long identity = Binder.clearCallingIdentity(); |
| 11267 | try { |
| 11268 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11269 | new ArraySet<>(featureTags)); |
| 11270 | } catch (ImsException e) { |
| 11271 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11272 | } finally { |
| 11273 | Binder.restoreCallingIdentity(identity); |
| 11274 | } |
| 11275 | } |
| 11276 | |
| 11277 | /** |
| 11278 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11279 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11280 | */ |
| 11281 | // Used for SHELL command only right now. |
| 11282 | @Override |
| 11283 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11284 | List<String> featureTags) { |
| 11285 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11286 | "removeUceRegistrationOverrideShell"); |
| 11287 | final long identity = Binder.clearCallingIdentity(); |
| 11288 | try { |
| 11289 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11290 | new ArraySet<>(featureTags)); |
| 11291 | } catch (ImsException e) { |
| 11292 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11293 | } finally { |
| 11294 | Binder.restoreCallingIdentity(identity); |
| 11295 | } |
| 11296 | } |
| 11297 | |
| 11298 | /** |
| 11299 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11300 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11301 | */ |
| 11302 | // Used for SHELL command only right now. |
| 11303 | @Override |
| 11304 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11305 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11306 | "clearUceRegistrationOverrideShell"); |
| 11307 | final long identity = Binder.clearCallingIdentity(); |
| 11308 | try { |
| 11309 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11310 | } catch (ImsException e) { |
| 11311 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11312 | } finally { |
| 11313 | Binder.restoreCallingIdentity(identity); |
| 11314 | } |
| 11315 | } |
| 11316 | |
| 11317 | /** |
| 11318 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11319 | */ |
| 11320 | // Used for SHELL command only right now. |
| 11321 | @Override |
| 11322 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11323 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11324 | "getLatestRcsContactUceCapabilityShell"); |
| 11325 | final long identity = Binder.clearCallingIdentity(); |
| 11326 | try { |
| 11327 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11328 | } catch (ImsException e) { |
| 11329 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11330 | } finally { |
| 11331 | Binder.restoreCallingIdentity(identity); |
| 11332 | } |
| 11333 | } |
| 11334 | |
| 11335 | /** |
| 11336 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11337 | * device does not have an active PUBLISH. |
| 11338 | */ |
| 11339 | // Used for SHELL command only right now. |
| 11340 | @Override |
| 11341 | public String getLastUcePidfXmlShell(int subId) { |
| 11342 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11343 | final long identity = Binder.clearCallingIdentity(); |
| 11344 | try { |
| 11345 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11346 | } catch (ImsException e) { |
| 11347 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11348 | } finally { |
| 11349 | Binder.restoreCallingIdentity(identity); |
| 11350 | } |
| 11351 | } |
| 11352 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11353 | /** |
| 11354 | * Remove UCE requests cannot be sent to the network status. |
| 11355 | */ |
| 11356 | // Used for SHELL command only right now. |
| 11357 | @Override |
| 11358 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11359 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11360 | final long identity = Binder.clearCallingIdentity(); |
| 11361 | try { |
| 11362 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11363 | } catch (ImsException e) { |
| 11364 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11365 | } finally { |
| 11366 | Binder.restoreCallingIdentity(identity); |
| 11367 | } |
| 11368 | } |
| 11369 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11370 | /** |
| 11371 | * Remove UCE requests cannot be sent to the network status. |
| 11372 | */ |
| 11373 | // Used for SHELL command only. |
| 11374 | @Override |
| 11375 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11376 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11377 | final long identity = Binder.clearCallingIdentity(); |
| 11378 | try { |
| 11379 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11380 | } catch (ImsException e) { |
| 11381 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11382 | } finally { |
| 11383 | Binder.restoreCallingIdentity(identity); |
| 11384 | } |
| 11385 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11386 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11387 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11388 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11389 | String callingPackage) { |
| 11390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11391 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11392 | |
| 11393 | final int callingUid = Binder.getCallingUid(); |
| 11394 | // Verify that tha callingPackage belongs to the calling UID |
| 11395 | mApp.getSystemService(AppOpsManager.class) |
| 11396 | .checkPackage(callingUid, callingPackage); |
| 11397 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11398 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11399 | |
| 11400 | final long identity = Binder.clearCallingIdentity(); |
| 11401 | try { |
| 11402 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11403 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11404 | |
| 11405 | if (result instanceof IllegalStateException) { |
| 11406 | throw (IllegalStateException) result; |
| 11407 | } |
| 11408 | } finally { |
| 11409 | Binder.restoreCallingIdentity(identity); |
| 11410 | } |
| 11411 | } |
| 11412 | |
| 11413 | @Override |
| 11414 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11415 | String callingPackage) { |
| 11416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11417 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11418 | |
| 11419 | final int callingUid = Binder.getCallingUid(); |
| 11420 | // Verify that tha callingPackage belongs to the calling UID |
| 11421 | mApp.getSystemService(AppOpsManager.class) |
| 11422 | .checkPackage(callingUid, callingPackage); |
| 11423 | |
| 11424 | final long identity = Binder.clearCallingIdentity(); |
| 11425 | try { |
| 11426 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11427 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11428 | |
| 11429 | if (result instanceof IllegalStateException) { |
| 11430 | throw (IllegalStateException) result; |
| 11431 | } |
| 11432 | } finally { |
| 11433 | Binder.restoreCallingIdentity(identity); |
| 11434 | } |
| 11435 | } |
| 11436 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11437 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11438 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11439 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11440 | // phone/system process do not have further restriction on request |
| 11441 | return; |
| 11442 | } |
| 11443 | |
| 11444 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11445 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11446 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11447 | context.enforceCallingOrSelfPermission( |
| 11448 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11449 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11450 | } |
| 11451 | |
| 11452 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11453 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11454 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11455 | || info.isEnabled()) { |
| 11456 | throw new IllegalArgumentException( |
| 11457 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11458 | } |
| 11459 | |
| 11460 | // Thresholds length for each RAN need in range. This has been validated in |
| 11461 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11462 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11463 | final int[] thresholds = info.getThresholds(); |
| 11464 | Objects.requireNonNull(thresholds); |
| 11465 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11466 | || thresholds.length |
| 11467 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11468 | throw new IllegalArgumentException( |
| 11469 | "thresholds length is out of range: " + thresholds.length); |
| 11470 | } |
| 11471 | } |
| 11472 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11473 | |
| 11474 | /** |
| 11475 | * Gets the current phone capability. |
| 11476 | * |
| 11477 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11478 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11479 | * It's used to evaluate possible phone config change, for example from single |
| 11480 | * SIM device to multi-SIM device. |
| 11481 | */ |
| 11482 | @Override |
| 11483 | public PhoneCapability getPhoneCapability() { |
| 11484 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11485 | final long identity = Binder.clearCallingIdentity(); |
| 11486 | try { |
| 11487 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11488 | } finally { |
| 11489 | Binder.restoreCallingIdentity(identity); |
| 11490 | } |
| 11491 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11492 | |
| 11493 | /** |
| 11494 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11495 | * required to be done shortly after the API is invoked. |
| 11496 | */ |
| 11497 | @Override |
| 11498 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11499 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11500 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11501 | enforceRebootPermission(); |
| 11502 | |
| 11503 | final long identity = Binder.clearCallingIdentity(); |
| 11504 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11505 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11506 | } finally { |
| 11507 | Binder.restoreCallingIdentity(identity); |
| 11508 | } |
| 11509 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11510 | |
| 11511 | /** |
| 11512 | * Request to get the current slicing configuration including URSP rules and |
| 11513 | * NSSAIs (configured, allowed and rejected). |
| 11514 | * |
| 11515 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11516 | */ |
| 11517 | @Override |
| 11518 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11519 | TelephonyPermissions |
| 11520 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11521 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11522 | |
| 11523 | final long identity = Binder.clearCallingIdentity(); |
| 11524 | try { |
| 11525 | Phone phone = getDefaultPhone(); |
| 11526 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11527 | } finally { |
| 11528 | Binder.restoreCallingIdentity(identity); |
| 11529 | } |
| 11530 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11531 | |
| 11532 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11533 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11534 | * |
| 11535 | * @param capability The premium capability to check. |
| 11536 | * @param subId The subId to check the premium capability for. |
| 11537 | * |
| 11538 | * @return Whether the given premium capability is available to purchase. |
| 11539 | */ |
| 11540 | @Override |
| 11541 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11542 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11543 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11544 | log("Premium capability " |
| 11545 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11546 | + " is not available for purchase due to missing permissions."); |
| 11547 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11548 | + "permission READ_BASIC_PHONE_STATE."); |
| 11549 | } |
| 11550 | |
| 11551 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11552 | if (phone == null) { |
| 11553 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11554 | return false; |
| 11555 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11556 | final long identity = Binder.clearCallingIdentity(); |
| 11557 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 11558 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11559 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11560 | } finally { |
| 11561 | Binder.restoreCallingIdentity(identity); |
| 11562 | } |
| 11563 | } |
| 11564 | |
| 11565 | /** |
| 11566 | * Purchase the given premium capability from the carrier. |
| 11567 | * |
| 11568 | * @param capability The premium capability to purchase. |
| 11569 | * @param callback The result of the purchase request. |
| 11570 | * @param subId The subId to purchase the premium capability for. |
| 11571 | */ |
| 11572 | @Override |
| 11573 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11574 | log("purchasePremiumCapability: capability=" |
| 11575 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11576 | + getCurrentPackageName()); |
| 11577 | |
| 11578 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11579 | mApp, "purchasePremiumCapability")) { |
| 11580 | log("purchasePremiumCapability " |
| 11581 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11582 | + " failed due to missing permissions."); |
| 11583 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11584 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11585 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11586 | mApp, "purchasePremiumCapability")) { |
| 11587 | log("purchasePremiumCapability " |
| 11588 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11589 | + " failed due to missing permissions."); |
| 11590 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11591 | } |
| 11592 | |
| 11593 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11594 | if (phone == null) { |
| 11595 | try { |
| 11596 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11597 | callback.accept(result); |
| 11598 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11599 | } catch (RemoteException e) { |
| 11600 | String logStr = "Purchase premium capability " |
| 11601 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11602 | + " failed due to RemoteException handling null phone: " + e; |
| 11603 | if (DBG) log(logStr); |
| 11604 | AnomalyReporter.reportAnomaly( |
| 11605 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11606 | } |
| 11607 | return; |
| 11608 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11609 | |
| 11610 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11611 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11612 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11613 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11614 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11615 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11616 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11617 | |
| 11618 | boolean isVisible = false; |
| 11619 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11620 | if (am != null) { |
| 11621 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11622 | if (processes != null) { |
| 11623 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11624 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 11625 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11626 | if (process.processName.equals(callingProcess) && process.importance |
| 11627 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11628 | isVisible = true; |
| 11629 | break; |
| 11630 | } |
| 11631 | } |
| 11632 | } |
| 11633 | } |
| 11634 | |
| 11635 | if (!isVisible) { |
| 11636 | try { |
| 11637 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11638 | callback.accept(result); |
| 11639 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11640 | } catch (RemoteException e) { |
| 11641 | String logStr = "Purchase premium capability " |
| 11642 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11643 | + " failed due to RemoteException handling background application: " + e; |
| 11644 | if (DBG) log(logStr); |
| 11645 | AnomalyReporter.reportAnomaly( |
| 11646 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11647 | } |
| 11648 | return; |
| 11649 | } |
| 11650 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11651 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11652 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11653 | } |
| 11654 | |
| 11655 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11656 | * Register an IMS connection state callback |
| 11657 | */ |
| 11658 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11659 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11660 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11661 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11662 | // ImsMmTelManager |
| 11663 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11664 | TelephonyPermissions |
| 11665 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11666 | mApp, subId, "registerImsStateCallback"); |
| 11667 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11668 | // ImsRcsManager or SipDelegateManager |
| 11669 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11670 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11671 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11672 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11673 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11674 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11675 | } |
| 11676 | |
| 11677 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11678 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11679 | "IMS not available on device."); |
| 11680 | } |
| 11681 | |
| 11682 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11683 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11684 | } |
| 11685 | |
| 11686 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11687 | if (controller == null) { |
| 11688 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11689 | "IMS not available on device."); |
| 11690 | } |
| 11691 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11692 | if (callingPackage == null) { |
| 11693 | callingPackage = getCurrentPackageName(); |
| 11694 | } |
| 11695 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11696 | final long token = Binder.clearCallingIdentity(); |
| 11697 | try { |
| 11698 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11699 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11700 | } catch (ImsException e) { |
| 11701 | throw new ServiceSpecificException(e.getCode()); |
| 11702 | } finally { |
| 11703 | Binder.restoreCallingIdentity(token); |
| 11704 | } |
| 11705 | } |
| 11706 | |
| 11707 | /** |
| 11708 | * Unregister an IMS connection state callback |
| 11709 | */ |
| 11710 | @Override |
| 11711 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11712 | final long token = Binder.clearCallingIdentity(); |
| 11713 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11714 | if (controller == null) { |
| 11715 | return; |
| 11716 | } |
| 11717 | try { |
| 11718 | controller.unregisterImsStateCallback(cb); |
| 11719 | } finally { |
| 11720 | Binder.restoreCallingIdentity(token); |
| 11721 | } |
| 11722 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11723 | |
| 11724 | /** |
| 11725 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11726 | * |
| 11727 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11728 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11729 | * SecurityException. |
| 11730 | * If there is current registered network this value will be same as the registered cell |
| 11731 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11732 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11733 | * it will be cleared and null will be returned. |
| 11734 | * |
| 11735 | */ |
| 11736 | @Override |
| 11737 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11738 | String callingFeatureId) { |
| 11739 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11740 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11741 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11742 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11743 | .setCallingPackage(callingPackage) |
| 11744 | .setCallingFeatureId(callingFeatureId) |
| 11745 | .setCallingPid(Binder.getCallingPid()) |
| 11746 | .setCallingUid(Binder.getCallingUid()) |
| 11747 | .setMethod("getLastKnownCellIdentity") |
| 11748 | .setLogAsInfo(true) |
| 11749 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11750 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11751 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11752 | .build()); |
| 11753 | |
| 11754 | boolean hasFinePermission = |
| 11755 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11756 | if (!hasFinePermission |
| 11757 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11758 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11759 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11760 | } |
| 11761 | |
| 11762 | final long identity = Binder.clearCallingIdentity(); |
| 11763 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11764 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11765 | if (sst == null) return null; |
| 11766 | return sst.getLastKnownCellIdentity(); |
| 11767 | } finally { |
| 11768 | Binder.restoreCallingIdentity(identity); |
| 11769 | } |
| 11770 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11771 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11772 | /** |
| 11773 | * Sets the modem service class Name that Telephony will bind to. |
| 11774 | * |
| 11775 | * @param serviceName The class name of the modem service. |
| 11776 | * @return true if the operation is succeed, otherwise false. |
| 11777 | */ |
| 11778 | public boolean setModemService(String serviceName) { |
| 11779 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11780 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11782 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11783 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11784 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11785 | } |
| 11786 | |
| 11787 | /** |
| 11788 | * Return the class name of the currently bounded modem service. |
| 11789 | * |
| 11790 | * @return the class name of the modem service. |
| 11791 | */ |
| 11792 | public String getModemService() { |
| 11793 | String result; |
| 11794 | Log.d(LOG_TAG, "getModemService"); |
| 11795 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11796 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11797 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11798 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11799 | "getModemService"); |
| 11800 | result = mPhoneConfigurationManager.getModemService(); |
| 11801 | Log.d(LOG_TAG, "result = " + result); |
| 11802 | return result; |
| 11803 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11804 | |
| 11805 | @Override |
| 11806 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11807 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11808 | mApp.enforceCallingOrSelfPermission( |
| 11809 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11810 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11811 | |
| 11812 | final long identity = Binder.clearCallingIdentity(); |
| 11813 | try { |
| 11814 | Phone phone = getPhone(subId); |
| 11815 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11816 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11817 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11818 | phone.setVoiceServiceStateOverride(hasService); |
| 11819 | } finally { |
| 11820 | Binder.restoreCallingIdentity(identity); |
| 11821 | } |
| 11822 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11823 | |
| 11824 | /** |
| 11825 | * set removable eSIM as default eUICC. |
| 11826 | * |
| 11827 | * @hide |
| 11828 | */ |
| 11829 | @Override |
| 11830 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11831 | enforceModifyPermission(); |
| 11832 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11833 | |
| 11834 | final long identity = Binder.clearCallingIdentity(); |
| 11835 | try { |
| 11836 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11837 | } finally { |
| 11838 | Binder.restoreCallingIdentity(identity); |
| 11839 | } |
| 11840 | } |
| 11841 | |
| 11842 | /** |
| 11843 | * Returns whether the removable eSIM is default eUICC or not. |
| 11844 | * |
| 11845 | * @hide |
| 11846 | */ |
| 11847 | @Override |
| 11848 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11849 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11850 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11851 | |
| 11852 | final long identity = Binder.clearCallingIdentity(); |
| 11853 | try { |
| 11854 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11855 | } finally { |
| 11856 | Binder.restoreCallingIdentity(identity); |
| 11857 | } |
| 11858 | } |
| 11859 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11860 | /** |
| 11861 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11862 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11863 | * application currently configured for this user. |
| 11864 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11865 | * {@code null} if the functionality is not supported. |
| 11866 | * @hide |
| 11867 | */ |
| 11868 | @Override |
| 11869 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11870 | boolean updateIfNeeded) { |
| 11871 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11872 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11873 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11874 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11875 | UserHandle userHandle = null; |
| 11876 | final long identity = Binder.clearCallingIdentity(); |
| 11877 | try { |
| 11878 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11879 | } finally { |
| 11880 | Binder.restoreCallingIdentity(identity); |
| 11881 | } |
| 11882 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11883 | updateIfNeeded, userHandle); |
| 11884 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11885 | |
| 11886 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11887 | * Set whether the device is able to connect with null ciphering or integrity |
| 11888 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11889 | * and all new subscriptions after this. |
| 11890 | * |
| 11891 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11892 | * @hide |
| 11893 | */ |
| 11894 | @Override |
| 11895 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11896 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11897 | enforceModifyPermission(); |
| 11898 | checkForNullCipherAndIntegritySupport(); |
| 11899 | |
| 11900 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11901 | // for listening to these preference changes and applying them immediately. |
| 11902 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11903 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11904 | editor.apply(); |
| 11905 | |
| 11906 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11907 | phone.handleNullCipherEnabledChange(); |
| 11908 | } |
| 11909 | } |
| 11910 | |
| 11911 | |
| 11912 | /** |
| 11913 | * Get whether the device is able to connect with null ciphering or integrity |
| 11914 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11915 | * the state of the radio. |
| 11916 | * |
| 11917 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11918 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11919 | * version for this feature. |
| 11920 | * @hide |
| 11921 | */ |
| 11922 | @Override |
| 11923 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11924 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11925 | enforceReadPermission(); |
| 11926 | checkForNullCipherAndIntegritySupport(); |
| 11927 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11928 | } |
| 11929 | |
| 11930 | private void checkForNullCipherAndIntegritySupport() { |
| 11931 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11932 | throw new UnsupportedOperationException( |
| 11933 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11934 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11935 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11936 | throw new UnsupportedOperationException( |
| 11937 | "Null cipher and integrity operations unsupported by modem"); |
| 11938 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11939 | } |
| 11940 | |
| 11941 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11942 | * Get the SIM state for the slot index. |
| 11943 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11944 | * |
| 11945 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11946 | */ |
| 11947 | @Override |
| 11948 | @SimState |
| 11949 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11950 | IccCardConstants.State simState; |
| 11951 | if (slotIndex < 0) { |
| 11952 | simState = IccCardConstants.State.UNKNOWN; |
| 11953 | } else { |
| 11954 | Phone phone = null; |
| 11955 | try { |
| 11956 | phone = PhoneFactory.getPhone(slotIndex); |
| 11957 | } catch (IllegalStateException e) { |
| 11958 | // ignore |
| 11959 | } |
| 11960 | if (phone == null) { |
| 11961 | simState = IccCardConstants.State.UNKNOWN; |
| 11962 | } else { |
| 11963 | IccCard icc = phone.getIccCard(); |
| 11964 | if (icc == null) { |
| 11965 | simState = IccCardConstants.State.UNKNOWN; |
| 11966 | } else { |
| 11967 | simState = icc.getState(); |
| 11968 | } |
| 11969 | } |
| 11970 | } |
| 11971 | return simState.ordinal(); |
| 11972 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11973 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 11974 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 11975 | boolean enableLogcat, |
| 11976 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 11977 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 11978 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 11979 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 11980 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 11981 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 11982 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 11983 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 11984 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 11985 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 11986 | Executors.newCachedThreadPool(), db, |
| 11987 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 11988 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 11989 | } |
| 11990 | |
| 11991 | /** |
| 11992 | * Request telephony to persist state for debugging emergency call failures. |
| 11993 | * |
| 11994 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 11995 | * @param enableLogcat whether to collect logcat output |
| 11996 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 11997 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 11998 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 11999 | */ |
| 12000 | @Override |
| 12001 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12002 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12003 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12004 | boolean enableTelephonyDump) { |
| 12005 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12006 | "persistEmergencyCallDiagnosticData"); |
| 12007 | final long identity = Binder.clearCallingIdentity(); |
| 12008 | try { |
| 12009 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12010 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12011 | |
| 12012 | } finally { |
| 12013 | Binder.restoreCallingIdentity(identity); |
| 12014 | } |
| 12015 | } |
| 12016 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12017 | /** |
| 12018 | * Get current cell broadcast ranges. |
| 12019 | */ |
| 12020 | @Override |
| 12021 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12022 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12023 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12024 | "getCellBroadcastIdRanges"); |
| 12025 | final long identity = Binder.clearCallingIdentity(); |
| 12026 | try { |
| 12027 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12028 | } finally { |
| 12029 | Binder.restoreCallingIdentity(identity); |
| 12030 | } |
| 12031 | } |
| 12032 | |
| 12033 | /** |
| 12034 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12035 | * |
| 12036 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12037 | */ |
| 12038 | @Override |
| 12039 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12040 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12041 | @Nullable IIntegerConsumer callback) { |
| 12042 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12043 | "setCellBroadcastIdRanges"); |
| 12044 | final long identity = Binder.clearCallingIdentity(); |
| 12045 | try { |
| 12046 | Phone phone = getPhoneFromSubId(subId); |
| 12047 | if (DBG) { |
| 12048 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12049 | } |
| 12050 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12051 | if (callback != null) { |
| 12052 | try { |
| 12053 | callback.accept(result); |
| 12054 | } catch (RemoteException e) { |
| 12055 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12056 | } |
| 12057 | } |
| 12058 | }); |
| 12059 | } finally { |
| 12060 | Binder.restoreCallingIdentity(identity); |
| 12061 | } |
| 12062 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12063 | |
| 12064 | /** |
| 12065 | * Returns whether the device supports the domain selection service. |
| 12066 | * |
| 12067 | * @return {@code true} if the device supports the domain selection service. |
| 12068 | */ |
| 12069 | @Override |
| 12070 | public boolean isDomainSelectionSupported() { |
| 12071 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12072 | "isDomainSelectionSupported"); |
| 12073 | |
| 12074 | final long identity = Binder.clearCallingIdentity(); |
| 12075 | try { |
| 12076 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12077 | } finally { |
| 12078 | Binder.restoreCallingIdentity(identity); |
| 12079 | } |
| 12080 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12081 | |
| 12082 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12083 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12084 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12085 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12086 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12087 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12088 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12089 | * {@code false} to disable. |
| 12090 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12091 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12092 | * |
| 12093 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12094 | */ |
| 12095 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12096 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12097 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12098 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12099 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12100 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12101 | } |
| 12102 | |
| 12103 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12104 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12105 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12106 | * @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] | 12107 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12108 | * 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] | 12109 | * |
| 12110 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12111 | */ |
| 12112 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12113 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12114 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12115 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12116 | } |
| 12117 | |
| 12118 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12119 | * Request to get whether the satellite service demo mode is enabled. |
| 12120 | * |
| 12121 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12122 | * is enabled for. |
| 12123 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12124 | * if the request is successful or an error code if the request failed. |
| 12125 | * |
| 12126 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12127 | */ |
| 12128 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12129 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12130 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12131 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12132 | } |
| 12133 | |
| 12134 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12135 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12136 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12137 | * @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] | 12138 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12139 | * 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] | 12140 | */ |
| 12141 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12142 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12143 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12144 | } |
| 12145 | |
| 12146 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12147 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12148 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12149 | * @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] | 12150 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12151 | * 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] | 12152 | * |
| 12153 | * @throws SecurityException if the caller doesn't have required permission. |
| 12154 | */ |
| 12155 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12156 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12157 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12158 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12159 | } |
| 12160 | |
| 12161 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12162 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12163 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12164 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12165 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12166 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12167 | * @param resultCallback The callback to get the result of the request. |
| 12168 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12169 | * |
| 12170 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12171 | */ |
| 12172 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12173 | public void startSatelliteTransmissionUpdates(int subId, |
| 12174 | @NonNull IIntegerConsumer resultCallback, |
| 12175 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12176 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12177 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12178 | } |
| 12179 | |
| 12180 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12181 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12182 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12183 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12184 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12185 | * @param resultCallback The callback to get the result of the request. |
| 12186 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12187 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12188 | * |
| 12189 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12190 | */ |
| 12191 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12192 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12193 | @NonNull IIntegerConsumer resultCallback, |
| 12194 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12195 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12196 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12197 | } |
| 12198 | |
| 12199 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12200 | * Register the subscription with a satellite provider. |
| 12201 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12202 | * |
| 12203 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12204 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12205 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12206 | * @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] | 12207 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12208 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12209 | * @return The signal transport used by the caller to cancel the provision request, |
| 12210 | * or {@code null} if the request failed. |
| 12211 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12212 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12213 | */ |
| 12214 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12215 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12216 | @NonNull String token, @NonNull byte[] provisionData, |
| 12217 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12218 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12219 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 12220 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12221 | } |
| 12222 | |
| 12223 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12224 | * Unregister the device/subscription with the satellite provider. |
| 12225 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12226 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12227 | * should report as deprovisioned. |
| 12228 | * |
| 12229 | * @param subId The subId of the subscription to be deprovisioned. |
| 12230 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12231 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12232 | * |
| 12233 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12234 | */ |
| 12235 | @Override |
| 12236 | public void deprovisionSatelliteService(int subId, |
| 12237 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12238 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12239 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12240 | } |
| 12241 | |
| 12242 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12243 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12244 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12245 | * @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] | 12246 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12247 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12248 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12249 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12250 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12251 | */ |
| 12252 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12253 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 12254 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12255 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12256 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12257 | } |
| 12258 | |
| 12259 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12260 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12261 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12262 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12263 | * @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] | 12264 | * @param callback The callback that was passed to |
| 12265 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12266 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12267 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12268 | */ |
| 12269 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12270 | public void unregisterForSatelliteProvisionStateChanged( |
| 12271 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12272 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12273 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12274 | } |
| 12275 | |
| 12276 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12277 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12278 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12279 | * @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] | 12280 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12281 | * satellite provider if the request is successful or an error code if the |
| 12282 | * request failed. |
| 12283 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12284 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12285 | */ |
| 12286 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12287 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12288 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12289 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12290 | } |
| 12291 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12292 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12293 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12294 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12295 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12296 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12297 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12298 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12299 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12300 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12301 | */ |
| 12302 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12303 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12304 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12305 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12306 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12307 | } |
| 12308 | |
| 12309 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12310 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12311 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12312 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12313 | * @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] | 12314 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12315 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12316 | * |
| 12317 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12318 | */ |
| 12319 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12320 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12321 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12322 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12323 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12324 | } |
| 12325 | |
| 12326 | /** |
| 12327 | * Register to receive incoming datagrams over satellite. |
| 12328 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12329 | * @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] | 12330 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12331 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12332 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12333 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12334 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12335 | */ |
| 12336 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12337 | @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12338 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12339 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12340 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12341 | } |
| 12342 | |
| 12343 | /** |
| 12344 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12345 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12346 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12347 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12348 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12349 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12350 | * |
| 12351 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12352 | */ |
| 12353 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12354 | public void unregisterForSatelliteDatagram(int subId, |
| 12355 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12356 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12357 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12358 | } |
| 12359 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12360 | /** |
| 12361 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12362 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12363 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12364 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 12365 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12366 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12367 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12368 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12369 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12370 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12371 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12372 | @Override |
| 12373 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12374 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12375 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12376 | } |
| 12377 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12378 | /** |
| 12379 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12380 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12381 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 12382 | * input to this method. Datagram received here will be passed down to modem without any |
| 12383 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12384 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12385 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 12386 | * @param datagramType datagram type indicating whether the datagram is of type |
| 12387 | * SOS_SMS or LOCATION_SHARING. |
| 12388 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 12389 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12390 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 12391 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12392 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12393 | * |
| 12394 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12395 | */ |
| 12396 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12397 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 12398 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 12399 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12400 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12401 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 12402 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12403 | } |
| 12404 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12405 | /** |
| 12406 | * Request to get whether satellite communication is allowed for the current location. |
| 12407 | * |
| 12408 | * @param subId The subId of the subscription to check whether satellite communication is |
| 12409 | * allowed for the current location for. |
| 12410 | * @param result The result receiver that returns whether satellite communication is allowed |
| 12411 | * for the current location if the request is successful or an error code |
| 12412 | * if the request failed. |
| 12413 | * |
| 12414 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12415 | */ |
| 12416 | @Override |
| 12417 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 12418 | @NonNull ResultReceiver result) { |
| 12419 | enforceSatelliteCommunicationPermission( |
| 12420 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12421 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 12422 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12423 | } |
| 12424 | |
| 12425 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12426 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12427 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12428 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12429 | * @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] | 12430 | * be visible if the request is successful or an error code if the request failed. |
| 12431 | * |
| 12432 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12433 | */ |
| 12434 | @Override |
| 12435 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 12436 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12437 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12438 | } |
| 12439 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12440 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12441 | * Inform that Device is aligned to satellite for demo mode. |
| 12442 | * |
| 12443 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12444 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 12445 | * {@code false} Device fails to align with the satellite for demo mode. |
| 12446 | * |
| 12447 | * @throws SecurityException if the caller doesn't have required permission. |
| 12448 | */ |
| 12449 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 12450 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12451 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12452 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12453 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12454 | } |
| 12455 | |
| 12456 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 12457 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12458 | * by modem. |
| 12459 | * |
| 12460 | * @param subId The subId of the subscription to request for. |
| 12461 | * @param reason Reason for disallowing satellite communication for carrier. |
| 12462 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12463 | * operation. |
| 12464 | * |
| 12465 | * @throws SecurityException if the caller doesn't have required permission. |
| 12466 | */ |
| 12467 | public void addSatelliteAttachRestrictionForCarrier(int subId, |
| 12468 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12469 | @NonNull IIntegerConsumer callback) { |
| 12470 | enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier"); |
| 12471 | final long identity = Binder.clearCallingIdentity(); |
| 12472 | try { |
| 12473 | mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback); |
| 12474 | } finally { |
| 12475 | Binder.restoreCallingIdentity(identity); |
| 12476 | } |
| 12477 | } |
| 12478 | |
| 12479 | /** |
| 12480 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12481 | * by modem. |
| 12482 | * |
| 12483 | * @param subId The subId of the subscription to request for. |
| 12484 | * @param reason Reason for disallowing satellite communication. |
| 12485 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12486 | * operation. |
| 12487 | * |
| 12488 | * @throws SecurityException if the caller doesn't have required permission. |
| 12489 | */ |
| 12490 | public void removeSatelliteAttachRestrictionForCarrier(int subId, |
| 12491 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12492 | @NonNull IIntegerConsumer callback) { |
| 12493 | enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier"); |
| 12494 | final long identity = Binder.clearCallingIdentity(); |
| 12495 | try { |
| 12496 | mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason, |
| 12497 | callback); |
| 12498 | } finally { |
| 12499 | Binder.restoreCallingIdentity(identity); |
| 12500 | } |
| 12501 | } |
| 12502 | |
| 12503 | /** |
| 12504 | * Get reasons for disallowing satellite communication, as requested by |
| 12505 | * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
| 12506 | * |
| 12507 | * @param subId The subId of the subscription to request for. |
| 12508 | * |
| 12509 | * @return Integer array of reasons for disallowing satellite communication. |
| 12510 | * |
| 12511 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12512 | */ |
| 12513 | public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier( |
| 12514 | int subId) { |
| 12515 | enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier"); |
| 12516 | final long identity = Binder.clearCallingIdentity(); |
| 12517 | try { |
| 12518 | Set<Integer> reasonSet = |
| 12519 | mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId); |
| 12520 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 12521 | } finally { |
| 12522 | Binder.restoreCallingIdentity(identity); |
| 12523 | } |
| 12524 | } |
| 12525 | |
| 12526 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12527 | * Request to get the signal strength of the satellite connection. |
| 12528 | * |
| 12529 | * @param subId The subId of the subscription to request for. |
| 12530 | * @param result Result receiver to get the error code of the request and the current signal |
| 12531 | * strength of the satellite connection. |
| 12532 | * |
| 12533 | * @throws SecurityException if the caller doesn't have required permission. |
| 12534 | */ |
| 12535 | @Override |
| 12536 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 12537 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 12538 | final long identity = Binder.clearCallingIdentity(); |
| 12539 | try { |
| 12540 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 12541 | } finally { |
| 12542 | Binder.restoreCallingIdentity(identity); |
| 12543 | } |
| 12544 | } |
| 12545 | |
| 12546 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame^] | 12547 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 12548 | * is not successful, a {@link ServiceSpecificException} that contains |
| 12549 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12550 | * |
| 12551 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame^] | 12552 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 12553 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 12554 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 12555 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 12556 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12557 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame^] | 12558 | * @throws SecurityException If the caller doesn't have the required permission. |
| 12559 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12560 | */ |
| 12561 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame^] | 12562 | public void registerForNtnSignalStrengthChanged(int subId, |
| 12563 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12564 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 12565 | final long identity = Binder.clearCallingIdentity(); |
| 12566 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame^] | 12567 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12568 | } finally { |
| 12569 | Binder.restoreCallingIdentity(identity); |
| 12570 | } |
| 12571 | } |
| 12572 | |
| 12573 | /** |
| 12574 | * Unregisters for NTN signal strength changed from satellite modem. |
| 12575 | * If callback was not registered before, the request will be ignored. |
| 12576 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12577 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 12578 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12579 | * @param callback The callback that was passed to |
| 12580 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 12581 | * |
| 12582 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12583 | */ |
| 12584 | @Override |
| 12585 | public void unregisterForNtnSignalStrengthChanged( |
| 12586 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 12587 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 12588 | final long identity = Binder.clearCallingIdentity(); |
| 12589 | try { |
| 12590 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 12591 | } finally { |
| 12592 | Binder.restoreCallingIdentity(identity); |
| 12593 | } |
| 12594 | } |
| 12595 | |
| 12596 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12597 | * Registers for satellite capabilities change event from the satellite service. |
| 12598 | * |
| 12599 | * @param subId The subId of the subscription to request for. |
| 12600 | * @param callback The callback to handle the satellite capabilities changed event. |
| 12601 | * |
| 12602 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 12603 | * |
| 12604 | * @throws SecurityException if the caller doesn't have required permission. |
| 12605 | */ |
| 12606 | @Override |
| 12607 | @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged( |
| 12608 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12609 | enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged"); |
| 12610 | final long identity = Binder.clearCallingIdentity(); |
| 12611 | try { |
| 12612 | return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback); |
| 12613 | } finally { |
| 12614 | Binder.restoreCallingIdentity(identity); |
| 12615 | } |
| 12616 | } |
| 12617 | |
| 12618 | /** |
| 12619 | * Unregisters for satellite capabilities change event from the satellite service. |
| 12620 | * If callback was not registered before, the request will be ignored. |
| 12621 | * |
| 12622 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 12623 | * @param callback The callback that was passed to. |
| 12624 | * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
| 12625 | * |
| 12626 | * @throws SecurityException if the caller doesn't have required permission. |
| 12627 | */ |
| 12628 | @Override |
| 12629 | public void unregisterForSatelliteCapabilitiesChanged( |
| 12630 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12631 | enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged"); |
| 12632 | final long identity = Binder.clearCallingIdentity(); |
| 12633 | try { |
| 12634 | mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback); |
| 12635 | } finally { |
| 12636 | Binder.restoreCallingIdentity(identity); |
| 12637 | } |
| 12638 | } |
| 12639 | |
| 12640 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 12641 | * This API can be used by only CTS to update satellite vendor service package name. |
| 12642 | * |
| 12643 | * @param servicePackageName The package name of the satellite vendor service. |
| 12644 | * @return {@code true} if the satellite vendor service is set successfully, |
| 12645 | * {@code false} otherwise. |
| 12646 | */ |
| 12647 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 12648 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 12649 | TelephonyPermissions.enforceShellOnly( |
| 12650 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 12651 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12652 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12653 | "setSatelliteServicePackageName"); |
| 12654 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 12655 | } |
| 12656 | |
| 12657 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 12658 | * This API can be used by only CTS to update satellite gateway service package name. |
| 12659 | * |
| 12660 | * @param servicePackageName The package name of the satellite gateway service. |
| 12661 | * @return {@code true} if the satellite gateway service is set successfully, |
| 12662 | * {@code false} otherwise. |
| 12663 | */ |
| 12664 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 12665 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 12666 | TelephonyPermissions.enforceShellOnly( |
| 12667 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 12668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12669 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12670 | "setSatelliteGatewayServicePackageName"); |
| 12671 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 12672 | } |
| 12673 | |
| 12674 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 12675 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 12676 | * |
| 12677 | * @param packageName The package name of the satellite pointing UI app. |
| 12678 | * @param className The class name of the satellite pointing UI app. |
| 12679 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 12680 | * {@code false} otherwise. |
| 12681 | */ |
| 12682 | public boolean setSatellitePointingUiClassName( |
| 12683 | @Nullable String packageName, @Nullable String className) { |
| 12684 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 12685 | + ", className=" + className); |
| 12686 | TelephonyPermissions.enforceShellOnly( |
| 12687 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 12688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12689 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12690 | "setSatelliteGatewayServicePackageName"); |
| 12691 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 12692 | } |
| 12693 | |
| 12694 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 12695 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 12696 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 12697 | * listening mode. |
| 12698 | * |
| 12699 | * @param timeoutMillis The timeout duration in millisecond. |
| 12700 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12701 | */ |
| 12702 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 12703 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 12704 | TelephonyPermissions.enforceShellOnly( |
| 12705 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 12706 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12707 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12708 | "setSatelliteListeningTimeoutDuration"); |
| 12709 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 12710 | } |
| 12711 | |
| 12712 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12713 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 12714 | * the device is aligned with the satellite for demo mode |
| 12715 | * |
| 12716 | * @param timeoutMillis The timeout duration in millisecond. |
| 12717 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12718 | */ |
| 12719 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 12720 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 12721 | TelephonyPermissions.enforceShellOnly( |
| 12722 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 12723 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12724 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12725 | "setDeviceAlignedTimeoutDuration"); |
| 12726 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 12727 | } |
| 12728 | |
| 12729 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 12730 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 12731 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 12732 | * |
| 12733 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 12734 | * of the following values to enable the override: |
| 12735 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 12736 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 12737 | * To disable the override, use -1 for handoverType. |
| 12738 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 12739 | * delaySeconds after the emergency call starts. |
| 12740 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 12741 | */ |
| 12742 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 12743 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 12744 | TelephonyPermissions.enforceShellOnly( |
| 12745 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 12746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12747 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12748 | "setEmergencyCallToSatelliteHandoverType"); |
| 12749 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 12750 | handoverType, delaySeconds); |
| 12751 | } |
| 12752 | |
| 12753 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 12754 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 12755 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 12756 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 12757 | * |
| 12758 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 12759 | * satellite modem or not. |
| 12760 | * |
| 12761 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 12762 | */ |
| 12763 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 12764 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 12765 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 12766 | + "disabled"); |
| 12767 | return false; |
| 12768 | } |
| 12769 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 12770 | TelephonyPermissions.enforceShellOnly( |
| 12771 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 12772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12773 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12774 | "setShouldSendDatagramToModemInDemoMode"); |
| 12775 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 12776 | shouldSendToModemInDemoMode); |
| 12777 | } |
| 12778 | |
| 12779 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12780 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12781 | * |
| 12782 | * <p>This method behaves in one of the following ways: |
| 12783 | * <ul> |
| 12784 | * <li>return true : if the calling package has the appop permission {@link |
| 12785 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12786 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12787 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12788 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12789 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12790 | * </ul> |
| 12791 | */ |
| 12792 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12793 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12794 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12795 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12796 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12797 | return true; |
| 12798 | } |
| 12799 | } |
| 12800 | return false; |
| 12801 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12802 | |
| 12803 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12804 | * @return The subscription manager service instance. |
| 12805 | */ |
| 12806 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12807 | return SubscriptionManagerService.getInstance(); |
| 12808 | } |
| 12809 | |
| 12810 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12811 | * Class binds the consumer[callback] and carrierId. |
| 12812 | */ |
| 12813 | private static class CallerCallbackInfo { |
| 12814 | private final Consumer<Integer> mConsumer; |
| 12815 | private final int mCarrierId; |
| 12816 | |
| 12817 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12818 | mConsumer = consumer; |
| 12819 | mCarrierId = carrierId; |
| 12820 | } |
| 12821 | |
| 12822 | public Consumer<Integer> getConsumer() { |
| 12823 | return mConsumer; |
| 12824 | } |
| 12825 | |
| 12826 | public int getCarrierId() { |
| 12827 | return mCarrierId; |
| 12828 | } |
| 12829 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12830 | } |