Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 20 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 22 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 23 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 27 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 28 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 29 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 30 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 32 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 33 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 34 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 35 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 37 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 38 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 39 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 40 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 41 | import android.compat.annotation.ChangeId; |
| 42 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 43 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 44 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 45 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.content.Context; |
| 47 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 48 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 49 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 50 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.net.Uri; |
| 52 | import android.os.AsyncResult; |
| 53 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 54 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 56 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 58 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 59 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 60 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.os.Looper; |
| 62 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 63 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 64 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 65 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 66 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 67 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 68 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 69 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 70 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 71 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 73 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 74 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 75 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 76 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 77 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 78 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 79 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 80 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 81 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 82 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 83 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 84 | import android.telephony.AccessNetworkConstants; |
| 85 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 86 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 87 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 88 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 89 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 90 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 91 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 92 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 93 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 94 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 95 | import android.telephony.CellIdentityCdma; |
| 96 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 97 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 98 | import android.telephony.CellInfoGsm; |
| 99 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 100 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 101 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 102 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 103 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 104 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 105 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 106 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 107 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 108 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 109 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 110 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 111 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 112 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 114 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 115 | import android.telephony.SignalStrengthUpdateRequest; |
| 116 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 117 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 118 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 119 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 120 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 121 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 122 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 123 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 124 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 125 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 126 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 127 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 128 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 129 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 130 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 131 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 132 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 133 | import android.telephony.gba.GbaAuthRequest; |
| 134 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 135 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 136 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 137 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 138 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 139 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 145 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 146 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 147 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 148 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 149 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 150 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 151 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 152 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 153 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 154 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 156 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 157 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 158 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 159 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 160 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 161 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 162 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 163 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 164 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 165 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 166 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 167 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 168 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 169 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 170 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 185 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 202 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 205 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.SmsPermissions; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 208 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 211 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 212 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 215 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 217 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 218 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 219 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 220 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 222 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.uicc.IccIoResult; |
| 225 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 229 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 230 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 231 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 232 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 233 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 234 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 235 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 236 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 237 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 238 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 239 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 240 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 241 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 242 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 243 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 244 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 245 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 246 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 247 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 248 | import com.android.services.telephony.TelecomAccountRegistry; |
| 249 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 250 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 251 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 252 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 253 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 254 | import java.io.IOException; |
| 255 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 256 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 258 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 259 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 260 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 261 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 262 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 263 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 264 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 265 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 266 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 267 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 268 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 269 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 270 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 271 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 272 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 273 | |
| 274 | /** |
| 275 | * Implementation of the ITelephony interface. |
| 276 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 277 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 278 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 279 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 280 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 281 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 282 | |
| 283 | // Message codes used with mMainThreadHandler |
| 284 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 285 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 286 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 287 | private static final int CMD_OPEN_CHANNEL = 9; |
| 288 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 289 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 290 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 291 | private static final int CMD_NV_READ_ITEM = 13; |
| 292 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 293 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 294 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 295 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 296 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 297 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 298 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 299 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 300 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 301 | private static final int CMD_SEND_ENVELOPE = 25; |
| 302 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 303 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 304 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 305 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 306 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 307 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 308 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 309 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 310 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 311 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 312 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 313 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 314 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 315 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 316 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 317 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 318 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 319 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 320 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 321 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 322 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 323 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 324 | private static final int CMD_SWITCH_SLOTS = 50; |
| 325 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 326 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 327 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 328 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 329 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 330 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 331 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 332 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 333 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 334 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 335 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 336 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 337 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 338 | private static final int CMD_MODEM_REBOOT = 64; |
| 339 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 340 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 341 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 342 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 343 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 344 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 345 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 346 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 347 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 348 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 349 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 350 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 351 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 352 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 353 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 354 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 355 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 356 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 357 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 358 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 359 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 360 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 361 | private static final int CMD_GET_CALL_WAITING = 87; |
| 362 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 363 | private static final int CMD_SET_CALL_WAITING = 89; |
| 364 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 365 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 366 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 367 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 368 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 369 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 370 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 371 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 372 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 373 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 374 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 375 | private static final int CMD_SET_SIM_POWER = 101; |
| 376 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 377 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 378 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 379 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 380 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 381 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 382 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 383 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 384 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 385 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 386 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 387 | private static final int CMD_ENABLE_VONR = 113; |
| 388 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 389 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 390 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 391 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 392 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 393 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 394 | // Parameters of select command. |
| 395 | private static final int SELECT_COMMAND = 0xA4; |
| 396 | private static final int SELECT_P1 = 0x04; |
| 397 | private static final int SELECT_P2 = 0; |
| 398 | private static final int SELECT_P3 = 0x10; |
| 399 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 400 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 401 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 402 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 403 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 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 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame^] | 4392 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4393 | * @param subId The subscription to use to check the configuration. |
| 4394 | * @param c The callback that will be used to send the result. |
| 4395 | */ |
| 4396 | @Override |
| 4397 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4398 | throws RemoteException { |
| 4399 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4400 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4401 | |
| 4402 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4403 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4404 | "IMS not available on device."); |
| 4405 | } |
| 4406 | final long token = Binder.clearCallingIdentity(); |
| 4407 | try { |
| 4408 | int slotId = getSlotIndexOrException(subId); |
| 4409 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4410 | |
| 4411 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4412 | if (controller != null) { |
| 4413 | ImsManager imsManager = controller.getImsManager(subId); |
| 4414 | if (imsManager != null) { |
| 4415 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4416 | } else { |
| 4417 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4418 | } |
| 4419 | } else { |
| 4420 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4421 | } |
| 4422 | } catch (ImsException e) { |
| 4423 | throw new ServiceSpecificException(e.getCode()); |
| 4424 | } finally { |
| 4425 | Binder.restoreCallingIdentity(token); |
| 4426 | } |
| 4427 | } |
| 4428 | |
| 4429 | /** |
| 4430 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4431 | * @param subId The subscription to use to check the configuration. |
| 4432 | * @param c The callback that will be used to send the result. |
| 4433 | */ |
| 4434 | @Override |
| 4435 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4436 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4437 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4438 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4439 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4440 | } |
| 4441 | final long token = Binder.clearCallingIdentity(); |
| 4442 | |
| 4443 | try { |
| 4444 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4445 | if (controller != null) { |
| 4446 | ImsManager imsManager = controller.getImsManager(subId); |
| 4447 | if (imsManager != null) { |
| 4448 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4449 | } else { |
| 4450 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4451 | + "is inactive, ignoring unregister."); |
| 4452 | // If the ImsManager is not valid, just return, since the callback |
| 4453 | // will already have been removed internally. |
| 4454 | } |
| 4455 | } |
| 4456 | } finally { |
| 4457 | Binder.restoreCallingIdentity(token); |
| 4458 | } |
| 4459 | } |
| 4460 | |
| 4461 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4462 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4463 | */ |
| 4464 | @Override |
| 4465 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4466 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4467 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4468 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4469 | "IMS not available on device."); |
| 4470 | } |
| 4471 | final long token = Binder.clearCallingIdentity(); |
| 4472 | try { |
| 4473 | Phone phone = getPhone(subId); |
| 4474 | if (phone == null) { |
| 4475 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4476 | + subId + "'"); |
| 4477 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4478 | } |
| 4479 | phone.getImsRegistrationState(regState -> { |
| 4480 | try { |
| 4481 | consumer.accept((regState == null) |
| 4482 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4483 | } catch (RemoteException e) { |
| 4484 | // Ignore if the remote process is no longer available to call back. |
| 4485 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4486 | } |
| 4487 | }); |
| 4488 | } finally { |
| 4489 | Binder.restoreCallingIdentity(token); |
| 4490 | } |
| 4491 | } |
| 4492 | |
| 4493 | /** |
| 4494 | * Get the transport type for the IMS service registration state. |
| 4495 | */ |
| 4496 | @Override |
| 4497 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4498 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4499 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4500 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4501 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4502 | "IMS not available on device."); |
| 4503 | } |
| 4504 | final long token = Binder.clearCallingIdentity(); |
| 4505 | try { |
| 4506 | Phone phone = getPhone(subId); |
| 4507 | if (phone == null) { |
| 4508 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4509 | + subId + "'"); |
| 4510 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4511 | } |
| 4512 | phone.getImsRegistrationTech(regTech -> { |
| 4513 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4514 | int regTechConverted = (regTech == null) |
| 4515 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4516 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4517 | regTechConverted); |
| 4518 | try { |
| 4519 | consumer.accept(regTechConverted); |
| 4520 | } catch (RemoteException e) { |
| 4521 | // Ignore if the remote process is no longer available to call back. |
| 4522 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4523 | } |
| 4524 | }); |
| 4525 | } finally { |
| 4526 | Binder.restoreCallingIdentity(token); |
| 4527 | } |
| 4528 | } |
| 4529 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4530 | /** |
| 4531 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4532 | * @param subId The subscription to use to check the configuration. |
| 4533 | * @param c The callback that will be used to send the result. |
| 4534 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4535 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4536 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4537 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4538 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4539 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4540 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4541 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4542 | "IMS not available on device."); |
| 4543 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4544 | final long token = Binder.clearCallingIdentity(); |
| 4545 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4546 | int slotId = getSlotIndexOrException(subId); |
| 4547 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4548 | |
| 4549 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4550 | if (controller != null) { |
| 4551 | ImsManager imsManager = controller.getImsManager(subId); |
| 4552 | if (imsManager != null) { |
| 4553 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4554 | } else { |
| 4555 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4556 | } |
| 4557 | } else { |
| 4558 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4559 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4560 | } catch (ImsException e) { |
| 4561 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4562 | } finally { |
| 4563 | Binder.restoreCallingIdentity(token); |
| 4564 | } |
| 4565 | } |
| 4566 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4567 | /** |
| 4568 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4569 | * @param subId The subscription to use to check the configuration. |
| 4570 | * @param c The callback that will be used to send the result. |
| 4571 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4572 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4573 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4574 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4575 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4576 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4577 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4578 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4579 | |
| 4580 | final long token = Binder.clearCallingIdentity(); |
| 4581 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4582 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4583 | if (controller != null) { |
| 4584 | ImsManager imsManager = controller.getImsManager(subId); |
| 4585 | if (imsManager != null) { |
| 4586 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4587 | } else { |
| 4588 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4589 | + " is inactive, ignoring unregister."); |
| 4590 | // If the ImsManager is not valid, just return, since the callback |
| 4591 | // will already have been removed internally. |
| 4592 | } |
| 4593 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4594 | } finally { |
| 4595 | Binder.restoreCallingIdentity(token); |
| 4596 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4600 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4601 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4602 | final long token = Binder.clearCallingIdentity(); |
| 4603 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4604 | int slotId = getSlotIndexOrException(subId); |
| 4605 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4606 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4607 | } catch (com.android.ims.ImsException e) { |
| 4608 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4609 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4610 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4611 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4612 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4613 | } finally { |
| 4614 | Binder.restoreCallingIdentity(token); |
| 4615 | } |
| 4616 | } |
| 4617 | |
| 4618 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4619 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4620 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4621 | final long token = Binder.clearCallingIdentity(); |
| 4622 | try { |
| 4623 | Phone phone = getPhone(subId); |
| 4624 | if (phone == null) return false; |
| 4625 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4626 | } catch (com.android.ims.ImsException e) { |
| 4627 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4628 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(token); |
| 4631 | } |
| 4632 | } |
| 4633 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4634 | /** |
| 4635 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4636 | * subscription. |
| 4637 | * @param subId The subscription to use to check the configuration. |
| 4638 | * @param callback The callback that will be used to send the result. |
| 4639 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4640 | * @param transportType The transport type of the MmTelFeature capability. |
| 4641 | */ |
| 4642 | @Override |
| 4643 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4644 | int transportType) { |
| 4645 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4646 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4647 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4648 | "IMS not available on device."); |
| 4649 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4650 | final long token = Binder.clearCallingIdentity(); |
| 4651 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4652 | int slotId = getSlotIndex(subId); |
| 4653 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4654 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4655 | + subId + "'"); |
| 4656 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4657 | } |
| 4658 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4659 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4660 | transportType, aBoolean -> { |
| 4661 | try { |
| 4662 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4663 | } catch (RemoteException e) { |
| 4664 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4665 | + "running. Ignore"); |
| 4666 | } |
| 4667 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4668 | } catch (ImsException e) { |
| 4669 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4670 | } finally { |
| 4671 | Binder.restoreCallingIdentity(token); |
| 4672 | } |
| 4673 | } |
| 4674 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4675 | /** |
| 4676 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4677 | * @param subId The subscription to use to check the configuration. |
| 4678 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4679 | @Override |
| 4680 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4681 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4682 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4683 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4684 | final long token = Binder.clearCallingIdentity(); |
| 4685 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4686 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4687 | // 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] | 4688 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4689 | } catch (ImsException e) { |
| 4690 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(token); |
| 4693 | } |
| 4694 | } |
| 4695 | |
| 4696 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4697 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4699 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4702 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4703 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4704 | // 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] | 4705 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4706 | } catch (ImsException e) { |
| 4707 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4708 | } finally { |
| 4709 | Binder.restoreCallingIdentity(identity); |
| 4710 | } |
| 4711 | } |
| 4712 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4713 | /** |
| 4714 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4715 | * @param subId The subscription to use to check the configuration. |
| 4716 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4717 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4718 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4719 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4720 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4721 | final long identity = Binder.clearCallingIdentity(); |
| 4722 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4723 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4724 | // 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] | 4725 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4726 | } catch (ImsException e) { |
| 4727 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4728 | } finally { |
| 4729 | Binder.restoreCallingIdentity(identity); |
| 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4734 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4736 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4737 | final long identity = Binder.clearCallingIdentity(); |
| 4738 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4739 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4740 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4741 | // 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] | 4742 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4743 | } catch (ImsException e) { |
| 4744 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4745 | } finally { |
| 4746 | Binder.restoreCallingIdentity(identity); |
| 4747 | } |
| 4748 | } |
| 4749 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4750 | /** |
| 4751 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4752 | * @param subId The subscription to use to check the configuration. |
| 4753 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4754 | @Override |
| 4755 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4756 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4757 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4758 | final long identity = Binder.clearCallingIdentity(); |
| 4759 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4760 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4761 | // 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] | 4762 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4763 | } catch (ImsException e) { |
| 4764 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4765 | } finally { |
| 4766 | Binder.restoreCallingIdentity(identity); |
| 4767 | } |
| 4768 | } |
| 4769 | |
| 4770 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4771 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4773 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4774 | final long identity = Binder.clearCallingIdentity(); |
| 4775 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4776 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4777 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4778 | // 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] | 4779 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4780 | } catch (ImsException e) { |
| 4781 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4782 | } finally { |
| 4783 | Binder.restoreCallingIdentity(identity); |
| 4784 | } |
| 4785 | } |
| 4786 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4787 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4788 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4789 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4790 | * @param subId The subscription to use to check the configuration. |
| 4791 | */ |
| 4792 | @Override |
| 4793 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4794 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4795 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4796 | final long identity = Binder.clearCallingIdentity(); |
| 4797 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4798 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4799 | // 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] | 4800 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4801 | } catch (ImsException e) { |
| 4802 | throw new ServiceSpecificException(e.getCode()); |
| 4803 | } finally { |
| 4804 | Binder.restoreCallingIdentity(identity); |
| 4805 | } |
| 4806 | } |
| 4807 | |
| 4808 | /** |
| 4809 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4810 | * Requires MODIFY_PHONE_STATE permission. |
| 4811 | * @param subId The subscription to use to check the configuration. |
| 4812 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4813 | * false otherwise |
| 4814 | */ |
| 4815 | @Override |
| 4816 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4817 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4818 | "setCrossSimCallingEnabled"); |
| 4819 | final long identity = Binder.clearCallingIdentity(); |
| 4820 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4821 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4822 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4823 | // 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] | 4824 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4825 | } catch (ImsException e) { |
| 4826 | throw new ServiceSpecificException(e.getCode()); |
| 4827 | } finally { |
| 4828 | Binder.restoreCallingIdentity(identity); |
| 4829 | } |
| 4830 | } |
| 4831 | |
| 4832 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4833 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4834 | * @param subId The subscription to use to check the configuration. |
| 4835 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4836 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4837 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4838 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4839 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4840 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4841 | final long identity = Binder.clearCallingIdentity(); |
| 4842 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4843 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4844 | // 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] | 4845 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
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 |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4854 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4856 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4857 | final long identity = Binder.clearCallingIdentity(); |
| 4858 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4859 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4860 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4861 | // 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] | 4862 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4863 | } catch (ImsException e) { |
| 4864 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4865 | } finally { |
| 4866 | Binder.restoreCallingIdentity(identity); |
| 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | @Override |
| 4871 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4873 | "setVoWiFiNonPersistent"); |
| 4874 | final long identity = Binder.clearCallingIdentity(); |
| 4875 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4876 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4877 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4878 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4879 | } catch (ImsException e) { |
| 4880 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4881 | } finally { |
| 4882 | Binder.restoreCallingIdentity(identity); |
| 4883 | } |
| 4884 | } |
| 4885 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4886 | /** |
| 4887 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4888 | * @param subId The subscription to use to check the configuration. |
| 4889 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4890 | @Override |
| 4891 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4892 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4893 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4896 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4897 | // 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] | 4898 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4899 | } catch (ImsException e) { |
| 4900 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4901 | } finally { |
| 4902 | Binder.restoreCallingIdentity(identity); |
| 4903 | } |
| 4904 | } |
| 4905 | |
| 4906 | @Override |
| 4907 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4908 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4909 | "setVoWiFiModeSetting"); |
| 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. The |
| 4914 | // 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] | 4915 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4916 | } catch (ImsException e) { |
| 4917 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4918 | } finally { |
| 4919 | Binder.restoreCallingIdentity(identity); |
| 4920 | } |
| 4921 | } |
| 4922 | |
| 4923 | @Override |
| 4924 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4925 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4926 | final long identity = Binder.clearCallingIdentity(); |
| 4927 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4928 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4929 | // 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] | 4930 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4931 | } catch (ImsException e) { |
| 4932 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4933 | } finally { |
| 4934 | Binder.restoreCallingIdentity(identity); |
| 4935 | } |
| 4936 | } |
| 4937 | |
| 4938 | @Override |
| 4939 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4940 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4941 | "setVoWiFiRoamingModeSetting"); |
| 4942 | final long identity = Binder.clearCallingIdentity(); |
| 4943 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4944 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4945 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4946 | // 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] | 4947 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4948 | } catch (ImsException e) { |
| 4949 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4950 | } finally { |
| 4951 | Binder.restoreCallingIdentity(identity); |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | @Override |
| 4956 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4958 | "setRttCapabilityEnabled"); |
| 4959 | final long identity = Binder.clearCallingIdentity(); |
| 4960 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4961 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4962 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4963 | // 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] | 4964 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4965 | } catch (ImsException e) { |
| 4966 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4967 | } finally { |
| 4968 | Binder.restoreCallingIdentity(identity); |
| 4969 | } |
| 4970 | } |
| 4971 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4972 | /** |
| 4973 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4974 | * @param subId The subscription to use to check the configuration. |
| 4975 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4976 | @Override |
| 4977 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4978 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4979 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4980 | final long identity = Binder.clearCallingIdentity(); |
| 4981 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4982 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4983 | // 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] | 4984 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4985 | } catch (ImsException e) { |
| 4986 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4987 | } finally { |
| 4988 | Binder.restoreCallingIdentity(identity); |
| 4989 | } |
| 4990 | } |
| 4991 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4992 | @Override |
| 4993 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4994 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4995 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4996 | final long identity = Binder.clearCallingIdentity(); |
| 4997 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4998 | if (!isImsAvailableOnDevice()) { |
| 4999 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5000 | "IMS not available on device."); |
| 5001 | } |
| 5002 | int slotId = getSlotIndexOrException(subId); |
| 5003 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5004 | |
| 5005 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5006 | if (controller != null) { |
| 5007 | ImsManager imsManager = controller.getImsManager(subId); |
| 5008 | if (imsManager != null) { |
| 5009 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5010 | } else { |
| 5011 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5012 | } |
| 5013 | } else { |
| 5014 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5015 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5016 | } catch (ImsException e) { |
| 5017 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5018 | } finally { |
| 5019 | Binder.restoreCallingIdentity(identity); |
| 5020 | } |
| 5021 | } |
| 5022 | |
| 5023 | @Override |
| 5024 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5025 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5026 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5027 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5028 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5029 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5030 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5031 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5032 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5033 | if (controller != null) { |
| 5034 | ImsManager imsManager = controller.getImsManager(subId); |
| 5035 | if (imsManager != null) { |
| 5036 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5037 | } else { |
| 5038 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5039 | + " is inactive, ignoring unregister."); |
| 5040 | // If the ImsManager is not valid, just return, since the callback will already |
| 5041 | // have been removed internally. |
| 5042 | } |
| 5043 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5044 | } finally { |
| 5045 | Binder.restoreCallingIdentity(identity); |
| 5046 | } |
| 5047 | } |
| 5048 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5049 | @Override |
| 5050 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5051 | IFeatureProvisioningCallback callback) { |
| 5052 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5053 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5054 | |
| 5055 | final long identity = Binder.clearCallingIdentity(); |
| 5056 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5057 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5058 | } |
| 5059 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5060 | try { |
| 5061 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5062 | if (controller == null) { |
| 5063 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5064 | "Device does not support IMS"); |
| 5065 | } |
| 5066 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
| 5069 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | @Override |
| 5073 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5074 | IFeatureProvisioningCallback callback) { |
| 5075 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5076 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5077 | |
| 5078 | final long identity = Binder.clearCallingIdentity(); |
| 5079 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5080 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5081 | } |
| 5082 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5083 | try { |
| 5084 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5085 | if (controller == null) { |
| 5086 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5087 | return; |
| 5088 | } |
| 5089 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
| 5092 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5093 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5094 | |
| 5095 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5096 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5097 | message); |
| 5098 | } |
| 5099 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5100 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5101 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5102 | boolean isProvisioned) { |
| 5103 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5104 | |
| 5105 | final long identity = Binder.clearCallingIdentity(); |
| 5106 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5107 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5108 | if (controller == null) { |
| 5109 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5110 | return; |
| 5111 | } |
| 5112 | controller.setRcsProvisioningStatusForCapability( |
| 5113 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5114 | } finally { |
| 5115 | Binder.restoreCallingIdentity(identity); |
| 5116 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | |
| 5120 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5121 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5122 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5123 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5124 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5125 | final long identity = Binder.clearCallingIdentity(); |
| 5126 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5127 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5128 | if (controller == null) { |
| 5129 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5130 | |
| 5131 | // device does not support IMS, this method will return true always. |
| 5132 | return true; |
| 5133 | } |
| 5134 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5135 | } finally { |
| 5136 | Binder.restoreCallingIdentity(identity); |
| 5137 | } |
| 5138 | } |
| 5139 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5140 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5141 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5142 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5143 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5144 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5145 | final long identity = Binder.clearCallingIdentity(); |
| 5146 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5147 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5148 | if (controller == null) { |
| 5149 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5150 | return; |
| 5151 | } |
| 5152 | controller.setImsProvisioningStatusForCapability( |
| 5153 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5154 | } finally { |
| 5155 | Binder.restoreCallingIdentity(identity); |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | @Override |
| 5160 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5161 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5162 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5163 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5164 | final long identity = Binder.clearCallingIdentity(); |
| 5165 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5166 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5167 | if (controller == null) { |
| 5168 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5169 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5170 | // device does not support IMS, this method will return true always. |
| 5171 | return true; |
| 5172 | } |
| 5173 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
| 5176 | } |
| 5177 | } |
| 5178 | |
| 5179 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5180 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5181 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5182 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5183 | |
| 5184 | final long identity = Binder.clearCallingIdentity(); |
| 5185 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5186 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5187 | if (controller == null) { |
| 5188 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5189 | |
| 5190 | // device does not support IMS, this method will return false |
| 5191 | return false; |
| 5192 | } |
| 5193 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5194 | } finally { |
| 5195 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5196 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5200 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5201 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5202 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5203 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5204 | final long identity = Binder.clearCallingIdentity(); |
| 5205 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5206 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5207 | if (controller == null) { |
| 5208 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5209 | |
| 5210 | // device does not support IMS, this method will return false |
| 5211 | return false; |
| 5212 | } |
| 5213 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5214 | } finally { |
| 5215 | Binder.restoreCallingIdentity(identity); |
| 5216 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5217 | } |
| 5218 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5219 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5220 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5221 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5222 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5223 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5224 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5225 | mApp, subId, "getImsProvisioningInt"); |
| 5226 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5227 | final long identity = Binder.clearCallingIdentity(); |
| 5228 | try { |
| 5229 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5230 | int slotId = getSlotIndex(subId); |
| 5231 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5232 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5233 | + subId + "' for key:" + key); |
| 5234 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5235 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5236 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5237 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5238 | if (controller == null) { |
| 5239 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5240 | |
| 5241 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5242 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5243 | } |
| 5244 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5245 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5246 | return retVal; |
| 5247 | } |
| 5248 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5249 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5250 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5251 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5252 | + subId + "' for key:" + key); |
| 5253 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5254 | } finally { |
| 5255 | Binder.restoreCallingIdentity(identity); |
| 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | @Override |
| 5260 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5261 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5262 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5263 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5264 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5265 | mApp, subId, "getImsProvisioningString"); |
| 5266 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5267 | final long identity = Binder.clearCallingIdentity(); |
| 5268 | try { |
| 5269 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5270 | int slotId = getSlotIndex(subId); |
| 5271 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5272 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5273 | + subId + "' for key:" + key); |
| 5274 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5275 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5276 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5277 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5278 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5279 | + subId + "' for key:" + key); |
| 5280 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5281 | } finally { |
| 5282 | Binder.restoreCallingIdentity(identity); |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | @Override |
| 5287 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5288 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5289 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5290 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5291 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5292 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5293 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5294 | final long identity = Binder.clearCallingIdentity(); |
| 5295 | try { |
| 5296 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5297 | int slotId = getSlotIndex(subId); |
| 5298 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5299 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5300 | + subId + "' for key:" + key); |
| 5301 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5302 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5303 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5304 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5305 | if (controller == null) { |
| 5306 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5307 | |
| 5308 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5309 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5310 | } |
| 5311 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5312 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5313 | return retVal; |
| 5314 | } |
| 5315 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5316 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5317 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5318 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5319 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5320 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5321 | } finally { |
| 5322 | Binder.restoreCallingIdentity(identity); |
| 5323 | } |
| 5324 | } |
| 5325 | |
| 5326 | @Override |
| 5327 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5328 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5329 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5330 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5331 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5332 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5333 | final long identity = Binder.clearCallingIdentity(); |
| 5334 | try { |
| 5335 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5336 | int slotId = getSlotIndex(subId); |
| 5337 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5338 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5339 | + subId + "' for key:" + key); |
| 5340 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5341 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5342 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5343 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5344 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5345 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5346 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5347 | } finally { |
| 5348 | Binder.restoreCallingIdentity(identity); |
| 5349 | } |
| 5350 | } |
| 5351 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5352 | /** |
| 5353 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5354 | * for the given slot ID or no ImsResolver instance has been created. |
| 5355 | * @param slotId The slot ID that the IMS service is created for. |
| 5356 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5357 | */ |
| 5358 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5359 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5360 | ImsFeature.FEATURE_MMTEL)) { |
| 5361 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5362 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5363 | } |
| 5364 | } |
| 5365 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5366 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5367 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5368 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5369 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5370 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5371 | } |
| 5372 | return slotId; |
| 5373 | } |
| 5374 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5375 | private int getSlotIndex(int subId) { |
| 5376 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5377 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5378 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5379 | } |
| 5380 | return slotId; |
| 5381 | } |
| 5382 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5383 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5384 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5385 | */ |
| 5386 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5387 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5388 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5389 | try { |
| 5390 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5391 | } catch (SecurityException se) { |
| 5392 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5393 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5394 | + Binder.getCallingUid()); |
| 5395 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5396 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5397 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5398 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5399 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5400 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5401 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5402 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5403 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5404 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5405 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | final long identity = Binder.clearCallingIdentity(); |
| 5407 | try { |
| 5408 | final Phone phone = getPhone(subId); |
| 5409 | if (phone != null) { |
| 5410 | return phone.getServiceState().getDataNetworkType(); |
| 5411 | } else { |
| 5412 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5413 | } |
| 5414 | } finally { |
| 5415 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5417 | } |
| 5418 | |
| 5419 | /** |
| 5420 | * Returns the data network type |
| 5421 | */ |
| 5422 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5423 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5424 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5425 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | /** |
| 5429 | * Returns the data network type for a subId |
| 5430 | */ |
| 5431 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5432 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5433 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5434 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5435 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5436 | mApp, functionName)) { |
| 5437 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5438 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5439 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5440 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5441 | } |
| 5442 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5443 | final long identity = Binder.clearCallingIdentity(); |
| 5444 | try { |
| 5445 | final Phone phone = getPhone(subId); |
| 5446 | if (phone != null) { |
| 5447 | return phone.getServiceState().getDataNetworkType(); |
| 5448 | } else { |
| 5449 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5450 | } |
| 5451 | } finally { |
| 5452 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5453 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5457 | * Returns the Voice network type for a subId |
| 5458 | */ |
| 5459 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5460 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5461 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5462 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5463 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5464 | mApp, functionName)) { |
| 5465 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5466 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5467 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5468 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5469 | } |
| 5470 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | final long identity = Binder.clearCallingIdentity(); |
| 5472 | try { |
| 5473 | final Phone phone = getPhone(subId); |
| 5474 | if (phone != null) { |
| 5475 | return phone.getServiceState().getVoiceNetworkType(); |
| 5476 | } else { |
| 5477 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5478 | } |
| 5479 | } finally { |
| 5480 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5481 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | /** |
| 5485 | * @return true if a ICC card is present |
| 5486 | */ |
| 5487 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5488 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5489 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5490 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5494 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5495 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5496 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5497 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5498 | final long identity = Binder.clearCallingIdentity(); |
| 5499 | try { |
| 5500 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5501 | if (phone != null) { |
| 5502 | return phone.getIccCard().hasIccCard(); |
| 5503 | } else { |
| 5504 | return false; |
| 5505 | } |
| 5506 | } finally { |
| 5507 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5508 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | /** |
| 5512 | * Return if the current radio is LTE on CDMA. This |
| 5513 | * is a tri-state return value as for a period of time |
| 5514 | * the mode may be unknown. |
| 5515 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5516 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5517 | * @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] | 5518 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5519 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5520 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5521 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5522 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5523 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5524 | } |
| 5525 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5526 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5527 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5528 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5529 | try { |
| 5530 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5531 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5532 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5533 | } |
| 5534 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5535 | final long identity = Binder.clearCallingIdentity(); |
| 5536 | try { |
| 5537 | final Phone phone = getPhone(subId); |
| 5538 | if (phone == null) { |
| 5539 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5540 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5541 | return TelephonyProperties.lte_on_cdma_device() |
| 5542 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5543 | } |
| 5544 | } finally { |
| 5545 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5546 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5549 | /** |
| 5550 | * {@hide} |
| 5551 | * Returns Default subId, 0 in the case of single standby. |
| 5552 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5553 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5554 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5555 | } |
| 5556 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5557 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5558 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5559 | } |
| 5560 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5561 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5562 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5563 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5564 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5565 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5566 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5567 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5568 | } |
| 5569 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5570 | /** |
| 5571 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5572 | */ |
| 5573 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 | final long identity = Binder.clearCallingIdentity(); |
| 5575 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5576 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5577 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5578 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5579 | } finally { |
| 5580 | Binder.restoreCallingIdentity(identity); |
| 5581 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | /** |
| 5585 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5586 | */ |
| 5587 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | final long identity = Binder.clearCallingIdentity(); |
| 5589 | try { |
| 5590 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5591 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5592 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5593 | } finally { |
| 5594 | Binder.restoreCallingIdentity(identity); |
| 5595 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5596 | } |
| 5597 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5598 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5599 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5600 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5601 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5602 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5603 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5604 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5605 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5606 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5607 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5608 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5609 | } |
| 5610 | return PhoneFactory.getPhone(phoneId); |
| 5611 | } |
| 5612 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5613 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5614 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5615 | @NonNull IccLogicalChannelRequest request) { |
| 5616 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5617 | /*message=*/ "iccOpenLogicalChannel"); |
| 5618 | |
| 5619 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5620 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5621 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5622 | |
| 5623 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5624 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5625 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5626 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5627 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5628 | Phone phone; |
| 5629 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5631 | mApp, request.subId, message); |
| 5632 | phone = getPhoneFromSubId(request.subId); |
| 5633 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5634 | enforceModifyPermission(); |
| 5635 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5636 | } else { |
| 5637 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5638 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5639 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5643 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | final long identity = Binder.clearCallingIdentity(); |
| 5645 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5646 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5647 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5648 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5649 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5650 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5651 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5652 | loge("The calling package is not allowed to access ISD-R."); |
| 5653 | throw new SecurityException( |
| 5654 | "The calling package is not allowed to access ISD-R."); |
| 5655 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5656 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5659 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5660 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5661 | return response; |
| 5662 | } finally { |
| 5663 | Binder.restoreCallingIdentity(identity); |
| 5664 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5668 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5669 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5670 | /*message=*/"iccCloseLogicalChannel"); |
| 5671 | |
| 5672 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5673 | |
| 5674 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5675 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5676 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5677 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5678 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5679 | // before this feature is enabled, this API should only return false if |
| 5680 | // the operation fails instead of throwing runtime exception for |
| 5681 | // backward-compatibility. |
| 5682 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5683 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5684 | final long identity = Binder.clearCallingIdentity(); |
| 5685 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5686 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5687 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5688 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5689 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5690 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5691 | Boolean success = false; |
| 5692 | if (result instanceof RuntimeException) { |
| 5693 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5694 | if (shouldThrowExceptionOnFailure) { |
| 5695 | throw (RuntimeException) result; |
| 5696 | } else { |
| 5697 | return false; |
| 5698 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5699 | } else if (result instanceof Boolean) { |
| 5700 | success = (Boolean) result; |
| 5701 | } else { |
| 5702 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5703 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5704 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | return success; |
| 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5708 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5712 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5713 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5715 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5716 | if (DBG) { |
| 5717 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5718 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5719 | + p3 + " data=" + data); |
| 5720 | } |
| 5721 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5722 | command, p1, p2, p3, data); |
| 5723 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5724 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5725 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5726 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5727 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5728 | enforceModifyPermission(); |
| 5729 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5730 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5731 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5732 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5733 | } |
| 5734 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5735 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5736 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5740 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5741 | final long identity = Binder.clearCallingIdentity(); |
| 5742 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5743 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5744 | return ""; |
| 5745 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5748 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5749 | null /* workSource */); |
| 5750 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5751 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5752 | // Append the returned status code to the end of the response payload. |
| 5753 | String s = Integer.toHexString( |
| 5754 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5755 | if (response.payload != null) { |
| 5756 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5757 | } |
| 5758 | return s; |
| 5759 | } finally { |
| 5760 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5761 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5762 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5763 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5764 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5765 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5766 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5767 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5768 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5770 | if (DBG) { |
| 5771 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5772 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5773 | } |
| 5774 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5775 | cla, command, p1, p2, p3, data); |
| 5776 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5777 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5778 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5779 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5780 | 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] | 5781 | enforceModifyPermission(); |
| 5782 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5783 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5784 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5785 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5786 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5790 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5791 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5792 | } |
| 5793 | |
| 5794 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5795 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5796 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | final long identity = Binder.clearCallingIdentity(); |
| 5798 | try { |
| 5799 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5800 | && TextUtils.equals(ISDR_AID, data)) { |
| 5801 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5802 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5803 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5804 | if (bestComponent == null |
| 5805 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5806 | loge("The calling package is not allowed to select ISD-R."); |
| 5807 | throw new SecurityException( |
| 5808 | "The calling package is not allowed to select ISD-R."); |
| 5809 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5810 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5811 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5812 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5813 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5814 | null /* workSource */); |
| 5815 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5816 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5817 | // Append the returned status code to the end of the response payload. |
| 5818 | String s = Integer.toHexString( |
| 5819 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5820 | if (response.payload != null) { |
| 5821 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5822 | } |
| 5823 | return s; |
| 5824 | } finally { |
| 5825 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5826 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5830 | 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] | 5831 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5832 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5833 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5834 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5835 | final long identity = Binder.clearCallingIdentity(); |
| 5836 | try { |
| 5837 | if (DBG) { |
| 5838 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5839 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5840 | } |
| 5841 | |
| 5842 | IccIoResult response = |
| 5843 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5844 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5845 | subId); |
| 5846 | |
| 5847 | if (DBG) { |
| 5848 | log("Exchange SIM_IO [R]" + response); |
| 5849 | } |
| 5850 | |
| 5851 | byte[] result = null; |
| 5852 | int length = 2; |
| 5853 | if (response.payload != null) { |
| 5854 | length = 2 + response.payload.length; |
| 5855 | result = new byte[length]; |
| 5856 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5857 | } else { |
| 5858 | result = new byte[length]; |
| 5859 | } |
| 5860 | |
| 5861 | result[length - 1] = (byte) response.sw2; |
| 5862 | result[length - 2] = (byte) response.sw1; |
| 5863 | return result; |
| 5864 | } finally { |
| 5865 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5866 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5867 | } |
| 5868 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5869 | /** |
| 5870 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5871 | * on a particular subscription |
| 5872 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5873 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5874 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5875 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5876 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5877 | return null; |
| 5878 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | |
| 5880 | final long identity = Binder.clearCallingIdentity(); |
| 5881 | try { |
| 5882 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5883 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5884 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5885 | return null; |
| 5886 | } |
| 5887 | Object response = sendRequest( |
| 5888 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5889 | if (response instanceof String[]) { |
| 5890 | return (String[]) response; |
| 5891 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5892 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5893 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5894 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5895 | } finally { |
| 5896 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5897 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5898 | } |
| 5899 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5900 | /** |
| 5901 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5902 | * subscription. |
| 5903 | * |
| 5904 | * @param subId the id of the subscription. |
| 5905 | * @param appType the uicc app type, must be USIM or SIM. |
| 5906 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5907 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5908 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5909 | * @return number of fplmns that is successfully written to the SIM. |
| 5910 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5911 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5912 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5914 | mApp, subId, "setForbiddenPlmns"); |
| 5915 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5916 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5917 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5918 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5919 | } |
| 5920 | if (fplmns == null) { |
| 5921 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5922 | } |
| 5923 | for (String fplmn : fplmns) { |
| 5924 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5925 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5926 | } |
| 5927 | } |
| 5928 | final long identity = Binder.clearCallingIdentity(); |
| 5929 | try { |
| 5930 | Object response = sendRequest( |
| 5931 | CMD_SET_FORBIDDEN_PLMNS, |
| 5932 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5933 | subId); |
| 5934 | return (int) response; |
| 5935 | } finally { |
| 5936 | Binder.restoreCallingIdentity(identity); |
| 5937 | } |
| 5938 | } |
| 5939 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5940 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5941 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5943 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5944 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5945 | final long identity = Binder.clearCallingIdentity(); |
| 5946 | try { |
| 5947 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5948 | if (response.payload == null) { |
| 5949 | return ""; |
| 5950 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | // Append the returned status code to the end of the response payload. |
| 5953 | String s = Integer.toHexString( |
| 5954 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5955 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5956 | return s; |
| 5957 | } finally { |
| 5958 | Binder.restoreCallingIdentity(identity); |
| 5959 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5960 | } |
| 5961 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5962 | /** |
| 5963 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5964 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5965 | * |
| 5966 | * @param itemID the ID of the item to read |
| 5967 | * @return the NV item as a String, or null on error. |
| 5968 | */ |
| 5969 | @Override |
| 5970 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5971 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5972 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5973 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | |
| 5975 | final long identity = Binder.clearCallingIdentity(); |
| 5976 | try { |
| 5977 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5978 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5979 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5980 | return value; |
| 5981 | } finally { |
| 5982 | Binder.restoreCallingIdentity(identity); |
| 5983 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5984 | } |
| 5985 | |
| 5986 | /** |
| 5987 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5988 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5989 | * |
| 5990 | * @param itemID the ID of the item to read |
| 5991 | * @param itemValue the value to write, as a String |
| 5992 | * @return true on success; false on any failure |
| 5993 | */ |
| 5994 | @Override |
| 5995 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5996 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5997 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5998 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5999 | |
| 6000 | final long identity = Binder.clearCallingIdentity(); |
| 6001 | try { |
| 6002 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6003 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6004 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6005 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6006 | return success; |
| 6007 | } finally { |
| 6008 | Binder.restoreCallingIdentity(identity); |
| 6009 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6010 | } |
| 6011 | |
| 6012 | /** |
| 6013 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6014 | * Used for device configuration by some CDMA operators. |
| 6015 | * |
| 6016 | * @param preferredRoamingList byte array containing the new PRL |
| 6017 | * @return true on success; false on any failure |
| 6018 | */ |
| 6019 | @Override |
| 6020 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6021 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6022 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6023 | |
| 6024 | final long identity = Binder.clearCallingIdentity(); |
| 6025 | try { |
| 6026 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6027 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6028 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6029 | return success; |
| 6030 | } finally { |
| 6031 | Binder.restoreCallingIdentity(identity); |
| 6032 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6033 | } |
| 6034 | |
| 6035 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6036 | * 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] | 6037 | * Used for device configuration by some CDMA operators. |
| 6038 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6039 | * @param slotIndex - device slot. |
| 6040 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6041 | * @return true on success; false on any failure |
| 6042 | */ |
| 6043 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6044 | public boolean resetModemConfig(int slotIndex) { |
| 6045 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6046 | if (phone != null) { |
| 6047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6048 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6049 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6050 | final long identity = Binder.clearCallingIdentity(); |
| 6051 | try { |
| 6052 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6053 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6054 | return success; |
| 6055 | } finally { |
| 6056 | Binder.restoreCallingIdentity(identity); |
| 6057 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6058 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6059 | return false; |
| 6060 | } |
| 6061 | |
| 6062 | /** |
| 6063 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6064 | * |
| 6065 | * @param slotIndex - device slot. |
| 6066 | * |
| 6067 | * @return true on success; false on any failure |
| 6068 | */ |
| 6069 | @Override |
| 6070 | public boolean rebootModem(int slotIndex) { |
| 6071 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6072 | if (phone != null) { |
| 6073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6074 | mApp, phone.getSubId(), "rebootModem"); |
| 6075 | |
| 6076 | final long identity = Binder.clearCallingIdentity(); |
| 6077 | try { |
| 6078 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6079 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6080 | return success; |
| 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
| 6083 | } |
| 6084 | } |
| 6085 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6086 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6087 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6088 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6089 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6090 | * {@link #disableIms(int)}. |
| 6091 | * @param slotIndex device slot. |
| 6092 | */ |
| 6093 | public void resetIms(int slotIndex) { |
| 6094 | enforceModifyPermission(); |
| 6095 | |
| 6096 | final long identity = Binder.clearCallingIdentity(); |
| 6097 | try { |
| 6098 | if (mImsResolver == null) { |
| 6099 | // may happen if the does not support IMS. |
| 6100 | return; |
| 6101 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6102 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6103 | } finally { |
| 6104 | Binder.restoreCallingIdentity(identity); |
| 6105 | } |
| 6106 | } |
| 6107 | |
| 6108 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6109 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6110 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6111 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6112 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6113 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6114 | |
| 6115 | final long identity = Binder.clearCallingIdentity(); |
| 6116 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6117 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6118 | // may happen if the device does not support IMS. |
| 6119 | return; |
| 6120 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6121 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6122 | } finally { |
| 6123 | Binder.restoreCallingIdentity(identity); |
| 6124 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6128 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6129 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6130 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6131 | public void disableIms(int slotId) { |
| 6132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | |
| 6134 | final long identity = Binder.clearCallingIdentity(); |
| 6135 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6136 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6137 | // may happen if the device does not support IMS. |
| 6138 | return; |
| 6139 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6140 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6141 | } finally { |
| 6142 | Binder.restoreCallingIdentity(identity); |
| 6143 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6147 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6148 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6149 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6150 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6151 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6152 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6153 | |
| 6154 | final long identity = Binder.clearCallingIdentity(); |
| 6155 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6156 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6157 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6158 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6159 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6160 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6161 | } finally { |
| 6162 | Binder.restoreCallingIdentity(identity); |
| 6163 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6164 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6165 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6166 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6167 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6168 | @Override |
| 6169 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6170 | enforceModifyPermission(); |
| 6171 | |
| 6172 | final long identity = Binder.clearCallingIdentity(); |
| 6173 | try { |
| 6174 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6175 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6176 | } finally { |
| 6177 | Binder.restoreCallingIdentity(identity); |
| 6178 | } |
| 6179 | } |
| 6180 | |
| 6181 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6182 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6183 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6184 | */ |
| 6185 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6186 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6187 | |
| 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6190 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6191 | // may happen if the device does not support IMS. |
| 6192 | return null; |
| 6193 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6194 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6195 | } finally { |
| 6196 | Binder.restoreCallingIdentity(identity); |
| 6197 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6198 | } |
| 6199 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6200 | /** |
| 6201 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6202 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6203 | */ |
| 6204 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6205 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6206 | |
| 6207 | final long identity = Binder.clearCallingIdentity(); |
| 6208 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6209 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6210 | // may happen if the device does not support IMS. |
| 6211 | return null; |
| 6212 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6213 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | } finally { |
| 6215 | Binder.restoreCallingIdentity(identity); |
| 6216 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6217 | } |
| 6218 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6219 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6220 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6221 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6222 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6223 | * @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] | 6224 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6225 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6226 | * @param packageName The name of the package that the current configuration will be replaced |
| 6227 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6228 | * @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] | 6229 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6230 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6231 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6232 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6233 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6234 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6235 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6236 | final long identity = Binder.clearCallingIdentity(); |
| 6237 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6238 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6239 | // may happen if the device does not support IMS. |
| 6240 | return false; |
| 6241 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6242 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6243 | for (int featureType : featureTypes) { |
| 6244 | featureConfig.put(featureType, packageName); |
| 6245 | } |
| 6246 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6247 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6248 | } finally { |
| 6249 | Binder.restoreCallingIdentity(identity); |
| 6250 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6251 | } |
| 6252 | |
| 6253 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6254 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6255 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6256 | * |
| 6257 | * This should only be used for testing. |
| 6258 | * |
| 6259 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6260 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6261 | */ |
| 6262 | @Override |
| 6263 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6264 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6265 | "clearCarrierImsServiceOverride"); |
| 6266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6267 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6268 | |
| 6269 | final long identity = Binder.clearCallingIdentity(); |
| 6270 | try { |
| 6271 | if (mImsResolver == null) { |
| 6272 | // may happen if the device does not support IMS. |
| 6273 | return false; |
| 6274 | } |
| 6275 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6276 | } finally { |
| 6277 | Binder.restoreCallingIdentity(identity); |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6282 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6283 | * |
| 6284 | * @param slotId The slot that the ImsService is associated with. |
| 6285 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6286 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6287 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6288 | * @return the package name of the ImsService configuration. |
| 6289 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6290 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6291 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6292 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6293 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6294 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6295 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6296 | final long identity = Binder.clearCallingIdentity(); |
| 6297 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6298 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6299 | // may happen if the device does not support IMS. |
| 6300 | return ""; |
| 6301 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6302 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6303 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6304 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6305 | } finally { |
| 6306 | Binder.restoreCallingIdentity(identity); |
| 6307 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6308 | } |
| 6309 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6310 | /** |
| 6311 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6312 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6313 | * @param callback A callback with an integer containing the |
| 6314 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6315 | */ |
| 6316 | @Override |
| 6317 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6318 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6319 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6320 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6321 | "IMS not available on device."); |
| 6322 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6323 | final long token = Binder.clearCallingIdentity(); |
| 6324 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6325 | int slotId = getSlotIndex(subId); |
| 6326 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6327 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6328 | + subId + "'"); |
| 6329 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6330 | } |
| 6331 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6332 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6333 | try { |
| 6334 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6335 | } catch (RemoteException e) { |
| 6336 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6337 | + "Ignore"); |
| 6338 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6339 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6340 | } catch (ImsException e) { |
| 6341 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6342 | } finally { |
| 6343 | Binder.restoreCallingIdentity(token); |
| 6344 | } |
| 6345 | } |
| 6346 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6347 | /** |
| 6348 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6349 | */ |
| 6350 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6351 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6352 | |
| 6353 | final long identity = Binder.clearCallingIdentity(); |
| 6354 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6355 | // NOTE: Before S, this method only set the default phone. |
| 6356 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6357 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6358 | phone.setImsRegistrationState(registered); |
| 6359 | } |
| 6360 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6361 | } finally { |
| 6362 | Binder.restoreCallingIdentity(identity); |
| 6363 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6367 | * Set the network selection mode to automatic. |
| 6368 | * |
| 6369 | */ |
| 6370 | @Override |
| 6371 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6373 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6374 | |
| 6375 | final long identity = Binder.clearCallingIdentity(); |
| 6376 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6377 | if (!isActiveSubscription(subId)) { |
| 6378 | return; |
| 6379 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6380 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6381 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6382 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6383 | } finally { |
| 6384 | Binder.restoreCallingIdentity(identity); |
| 6385 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6386 | } |
| 6387 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6388 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6389 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6390 | * |
| 6391 | * @param subId the id of the subscription. |
| 6392 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6393 | * the operator to attach to. |
| 6394 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6395 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6396 | * normal network selection next time. |
| 6397 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6398 | */ |
| 6399 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6400 | public boolean setNetworkSelectionModeManual( |
| 6401 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6402 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6403 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6404 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6405 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6406 | if (!isActiveSubscription(subId)) { |
| 6407 | return false; |
| 6408 | } |
| 6409 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6411 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6413 | if (DBG) { |
| 6414 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6415 | + " operator: " + operatorInfo); |
| 6416 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6417 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6418 | } finally { |
| 6419 | Binder.restoreCallingIdentity(identity); |
| 6420 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6421 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6422 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6423 | * Get the manual network selection |
| 6424 | * |
| 6425 | * @param subId the id of the subscription. |
| 6426 | * |
| 6427 | * @return the previously saved user selected PLMN |
| 6428 | */ |
| 6429 | @Override |
| 6430 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6431 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6432 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6433 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6434 | |
| 6435 | final long identity = Binder.clearCallingIdentity(); |
| 6436 | try { |
| 6437 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6438 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | final Phone phone = getPhone(subId); |
| 6442 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6443 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6444 | } |
| 6445 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6446 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6447 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6448 | } finally { |
| 6449 | Binder.restoreCallingIdentity(identity); |
| 6450 | } |
| 6451 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6452 | |
| 6453 | /** |
| 6454 | * Scans for available networks. |
| 6455 | */ |
| 6456 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6457 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6458 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6460 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6461 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6462 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6463 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6464 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6465 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6466 | .setCallingPid(Binder.getCallingPid()) |
| 6467 | .setCallingUid(Binder.getCallingUid()) |
| 6468 | .setMethod("getCellNetworkScanResults") |
| 6469 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6470 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6471 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6472 | .build()); |
| 6473 | switch (locationResult) { |
| 6474 | case DENIED_HARD: |
| 6475 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6476 | case DENIED_SOFT: |
| 6477 | return null; |
| 6478 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6479 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6480 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6481 | try { |
| 6482 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6483 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6484 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6485 | } finally { |
| 6486 | Binder.restoreCallingIdentity(identity); |
| 6487 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6491 | * Get the call forwarding info, given the call forwarding reason. |
| 6492 | */ |
| 6493 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6494 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6495 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6496 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6497 | long identity = Binder.clearCallingIdentity(); |
| 6498 | try { |
| 6499 | if (DBG) { |
| 6500 | log("getCallForwarding: subId " + subId |
| 6501 | + " callForwardingReason" + callForwardingReason); |
| 6502 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6503 | |
| 6504 | Phone phone = getPhone(subId); |
| 6505 | if (phone == null) { |
| 6506 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6507 | callback.onError( |
| 6508 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6509 | } catch (RemoteException e) { |
| 6510 | // ignore |
| 6511 | } |
| 6512 | return; |
| 6513 | } |
| 6514 | |
| 6515 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6516 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6517 | @Override |
| 6518 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6519 | try { |
| 6520 | callback.onCallForwardingInfoAvailable(info); |
| 6521 | } catch (RemoteException e) { |
| 6522 | // ignore |
| 6523 | } |
| 6524 | } |
| 6525 | |
| 6526 | @Override |
| 6527 | public void onError(int error) { |
| 6528 | try { |
| 6529 | callback.onError(error); |
| 6530 | } catch (RemoteException e) { |
| 6531 | // ignore |
| 6532 | } |
| 6533 | } |
| 6534 | }); |
| 6535 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6536 | } finally { |
| 6537 | Binder.restoreCallingIdentity(identity); |
| 6538 | } |
| 6539 | } |
| 6540 | |
| 6541 | /** |
| 6542 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6543 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6544 | */ |
| 6545 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6546 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6547 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6548 | enforceModifyPermission(); |
| 6549 | long identity = Binder.clearCallingIdentity(); |
| 6550 | try { |
| 6551 | if (DBG) { |
| 6552 | log("setCallForwarding: subId " + subId |
| 6553 | + " callForwardingInfo" + callForwardingInfo); |
| 6554 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6555 | |
| 6556 | Phone phone = getPhone(subId); |
| 6557 | if (phone == null) { |
| 6558 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6559 | callback.accept( |
| 6560 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6561 | } catch (RemoteException e) { |
| 6562 | // ignore |
| 6563 | } |
| 6564 | return; |
| 6565 | } |
| 6566 | |
| 6567 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6568 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6569 | |
| 6570 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6571 | } finally { |
| 6572 | Binder.restoreCallingIdentity(identity); |
| 6573 | } |
| 6574 | } |
| 6575 | |
| 6576 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6577 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6578 | */ |
| 6579 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6580 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6581 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6582 | long identity = Binder.clearCallingIdentity(); |
| 6583 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6584 | Phone phone = getPhone(subId); |
| 6585 | if (phone == null) { |
| 6586 | try { |
| 6587 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6588 | } catch (RemoteException e) { |
| 6589 | // ignore |
| 6590 | } |
| 6591 | return; |
| 6592 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6593 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6594 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6595 | boolean requireUssd = c.getBoolean( |
| 6596 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6597 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6598 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6599 | if (requireUssd) { |
| 6600 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6601 | getSubscriptionCarrierId(subId)); |
| 6602 | String newUssdCommand = ""; |
| 6603 | try { |
| 6604 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6605 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6606 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6607 | } catch (NullPointerException e) { |
| 6608 | loge("Failed to generate USSD number" + e); |
| 6609 | } |
| 6610 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6611 | mMainThreadHandler, callback, carrierXmlParser, |
| 6612 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6613 | final String ussdCommand = newUssdCommand; |
| 6614 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6615 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6616 | }); |
| 6617 | } else { |
| 6618 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6619 | callback::accept); |
| 6620 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6621 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6622 | } finally { |
| 6623 | Binder.restoreCallingIdentity(identity); |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6628 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6629 | */ |
| 6630 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6631 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6632 | enforceModifyPermission(); |
| 6633 | long identity = Binder.clearCallingIdentity(); |
| 6634 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6635 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6636 | |
| 6637 | Phone phone = getPhone(subId); |
| 6638 | if (phone == null) { |
| 6639 | try { |
| 6640 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6641 | } catch (RemoteException e) { |
| 6642 | // ignore |
| 6643 | } |
| 6644 | return; |
| 6645 | } |
| 6646 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6647 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6648 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6649 | boolean requireUssd = c.getBoolean( |
| 6650 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6651 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6652 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6653 | if (requireUssd) { |
| 6654 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6655 | getSubscriptionCarrierId(subId)); |
| 6656 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6657 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6658 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6659 | String newUssdCommand = ""; |
| 6660 | try { |
| 6661 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6662 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6663 | .makeCommand(ssAction, null); |
| 6664 | } catch (NullPointerException e) { |
| 6665 | loge("Failed to generate USSD number" + e); |
| 6666 | } |
| 6667 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6668 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6669 | final String ussdCommand = newUssdCommand; |
| 6670 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6671 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6672 | }); |
| 6673 | } else { |
| 6674 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6675 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6676 | |
| 6677 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6678 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6679 | } finally { |
| 6680 | Binder.restoreCallingIdentity(identity); |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6685 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6686 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6687 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6688 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6689 | * location related information which will be sent if the caller already possess |
| 6690 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6691 | * @param request contains the radio access networks with bands/channels to scan |
| 6692 | * @param messenger callback messenger for scan results or errors |
| 6693 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6694 | * @return the id of the requested scan which can be used to stop the scan. |
| 6695 | */ |
| 6696 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6697 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6698 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6699 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6701 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6702 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6703 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6704 | if (!renounceFineLocationAccess) { |
| 6705 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6706 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6707 | .setCallingPackage(callingPackage) |
| 6708 | .setCallingFeatureId(callingFeatureId) |
| 6709 | .setCallingPid(Binder.getCallingPid()) |
| 6710 | .setCallingUid(Binder.getCallingUid()) |
| 6711 | .setMethod("requestNetworkScan") |
| 6712 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6713 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6714 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6715 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6716 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6717 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6718 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6719 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6720 | if (e != null) { |
| 6721 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6722 | throw e; |
| 6723 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6724 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6725 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6726 | } |
| 6727 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6729 | int callingUid = Binder.getCallingUid(); |
| 6730 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6731 | final long identity = Binder.clearCallingIdentity(); |
| 6732 | try { |
| 6733 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6734 | renounceFineLocationAccess, request, messenger, binder, |
| 6735 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6736 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6737 | } finally { |
| 6738 | Binder.restoreCallingIdentity(identity); |
| 6739 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6740 | } |
| 6741 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6742 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6743 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6744 | boolean hasCarrierPriv; |
| 6745 | final long identity = Binder.clearCallingIdentity(); |
| 6746 | try { |
| 6747 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6748 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6749 | } finally { |
| 6750 | Binder.restoreCallingIdentity(identity); |
| 6751 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6752 | boolean hasNetworkScanPermission = |
| 6753 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6754 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6755 | |
| 6756 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6757 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6758 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6762 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6763 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6764 | return new SecurityException("Specific channels must not be" |
| 6765 | + " scanned without location access."); |
| 6766 | } |
| 6767 | } |
| 6768 | } |
| 6769 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6770 | return null; |
| 6771 | } |
| 6772 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6773 | /** |
| 6774 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6775 | * |
| 6776 | * @param subId id of the subscription |
| 6777 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6778 | */ |
| 6779 | @Override |
| 6780 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6782 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6783 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6784 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6785 | final long identity = Binder.clearCallingIdentity(); |
| 6786 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6787 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6788 | } finally { |
| 6789 | Binder.restoreCallingIdentity(identity); |
| 6790 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6791 | } |
| 6792 | |
| 6793 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6794 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6795 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6796 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6797 | */ |
| 6798 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6799 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6800 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6801 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6802 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6803 | |
| 6804 | final long identity = Binder.clearCallingIdentity(); |
| 6805 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6806 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6807 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6808 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6809 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6810 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6811 | } finally { |
| 6812 | Binder.restoreCallingIdentity(identity); |
| 6813 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6814 | } |
| 6815 | |
| 6816 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6817 | * Get the allowed network types for certain reason. |
| 6818 | * |
| 6819 | * @param subId the id of the subscription. |
| 6820 | * @param reason the reason the allowed network type change is taking place |
| 6821 | * @return the allowed network types. |
| 6822 | */ |
| 6823 | @Override |
| 6824 | public long getAllowedNetworkTypesForReason(int subId, |
| 6825 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6826 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6827 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6828 | final long identity = Binder.clearCallingIdentity(); |
| 6829 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6830 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6831 | } finally { |
| 6832 | Binder.restoreCallingIdentity(identity); |
| 6833 | } |
| 6834 | } |
| 6835 | |
| 6836 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6837 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6838 | * @param subId subscription id of the sim card |
| 6839 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6840 | * This can be passed following states |
| 6841 | * <ol> |
| 6842 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6843 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6844 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6845 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6846 | * </ol> |
| 6847 | * @return operation result. |
| 6848 | */ |
| 6849 | @Override |
| 6850 | public int setNrDualConnectivityState(int subId, |
| 6851 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6852 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6853 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6854 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6855 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6856 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6857 | } |
| 6858 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6859 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6860 | final long identity = Binder.clearCallingIdentity(); |
| 6861 | try { |
| 6862 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6863 | nrDualConnectivityState, subId, |
| 6864 | workSource); |
| 6865 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6866 | return result; |
| 6867 | } finally { |
| 6868 | Binder.restoreCallingIdentity(identity); |
| 6869 | } |
| 6870 | } |
| 6871 | |
| 6872 | /** |
| 6873 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6874 | * @return true if dual connectivity is enabled else false |
| 6875 | */ |
| 6876 | @Override |
| 6877 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6878 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6879 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6880 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6881 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6882 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6883 | return false; |
| 6884 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6885 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6886 | final long identity = Binder.clearCallingIdentity(); |
| 6887 | try { |
| 6888 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6889 | null, subId, workSource); |
| 6890 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6891 | return isEnabled; |
| 6892 | } finally { |
| 6893 | Binder.restoreCallingIdentity(identity); |
| 6894 | } |
| 6895 | } |
| 6896 | |
| 6897 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6898 | * Set the allowed network types of the device and |
| 6899 | * provide the reason triggering the allowed network change. |
| 6900 | * |
| 6901 | * @param subId the id of the subscription. |
| 6902 | * @param reason the reason the allowed network type change is taking place |
| 6903 | * @param allowedNetworkTypes the allowed network types. |
| 6904 | * @return true on success; false on any failure. |
| 6905 | */ |
| 6906 | @Override |
| 6907 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6908 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6909 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6910 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6911 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6912 | // If the caller only has carrier privileges, then they should not be able to override |
| 6913 | // any network types which were set for security reasons. |
| 6914 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6915 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6916 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6917 | throw new SecurityException( |
| 6918 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6919 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6920 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6921 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6922 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6923 | return false; |
| 6924 | } |
| 6925 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6926 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6927 | return false; |
| 6928 | } |
| 6929 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6930 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6931 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6932 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6933 | Phone phone = getPhone(subId); |
| 6934 | if (phone == null) { |
| 6935 | return false; |
| 6936 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6937 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6938 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6939 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6940 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6941 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6942 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6943 | final long identity = Binder.clearCallingIdentity(); |
| 6944 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6945 | Boolean success = (Boolean) sendRequest( |
| 6946 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6947 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6948 | |
| 6949 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6950 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6951 | } finally { |
| 6952 | Binder.restoreCallingIdentity(identity); |
| 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6957 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6958 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6959 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6960 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6961 | * @hide |
| 6962 | */ |
| 6963 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6964 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6965 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6966 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6967 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6968 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6969 | if (phone != null) { |
| 6970 | return phone.hasMatchedTetherApnSetting(); |
| 6971 | } else { |
| 6972 | return false; |
| 6973 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6974 | } finally { |
| 6975 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6976 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6977 | } |
| 6978 | |
| 6979 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6980 | * Get the user enabled state of Mobile Data. |
| 6981 | * |
| 6982 | * TODO: remove and use isUserDataEnabled. |
| 6983 | * This can't be removed now because some vendor codes |
| 6984 | * calls through ITelephony directly while they should |
| 6985 | * use TelephonyManager. |
| 6986 | * |
| 6987 | * @return true on enabled |
| 6988 | */ |
| 6989 | @Override |
| 6990 | public boolean getDataEnabled(int subId) { |
| 6991 | return isUserDataEnabled(subId); |
| 6992 | } |
| 6993 | |
| 6994 | /** |
| 6995 | * Get whether mobile data is enabled per user setting. |
| 6996 | * |
| 6997 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6998 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6999 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7000 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7001 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7002 | * |
| 7003 | * @return {@code true} if data is enabled else {@code false} |
| 7004 | */ |
| 7005 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7006 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7007 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7008 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7009 | try { |
| 7010 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7011 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7012 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7013 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7014 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7015 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7016 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7017 | mApp, subId, functionName); |
| 7018 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7019 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7020 | |
| 7021 | final long identity = Binder.clearCallingIdentity(); |
| 7022 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7023 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7024 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7025 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7026 | if (phone != null) { |
| 7027 | boolean retVal = phone.isUserDataEnabled(); |
| 7028 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7029 | return retVal; |
| 7030 | } else { |
| 7031 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7032 | return false; |
| 7033 | } |
| 7034 | } finally { |
| 7035 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7036 | } |
| 7037 | } |
| 7038 | |
| 7039 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7040 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7041 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7042 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7043 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7044 | * @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] | 7045 | */ |
| 7046 | @Override |
| 7047 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7048 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7049 | try { |
| 7050 | try { |
| 7051 | mApp.enforceCallingOrSelfPermission( |
| 7052 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7053 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7054 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7055 | try { |
| 7056 | mApp.enforceCallingOrSelfPermission( |
| 7057 | android.Manifest.permission.READ_PHONE_STATE, |
| 7058 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7059 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7060 | mApp.enforceCallingOrSelfPermission( |
| 7061 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7062 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7063 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7064 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7065 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7067 | |
| 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7070 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7071 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7072 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7073 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7074 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | return retVal; |
| 7076 | } else { |
| 7077 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7078 | return false; |
| 7079 | } |
| 7080 | } finally { |
| 7081 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7082 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7083 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7084 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7085 | /** |
| 7086 | * Check if data is enabled for a specific reason |
| 7087 | * @param subId Subscription index |
| 7088 | * @param reason the reason the data enable change is taking place |
| 7089 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7090 | */ |
| 7091 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7092 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7093 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7094 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7095 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7096 | try { |
| 7097 | mApp.enforceCallingOrSelfPermission( |
| 7098 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7099 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7100 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7101 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7102 | functionName); |
| 7103 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7104 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7105 | try { |
| 7106 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7107 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7108 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7110 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7111 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7112 | } |
| 7113 | |
| 7114 | |
| 7115 | final long identity = Binder.clearCallingIdentity(); |
| 7116 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7117 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7118 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7119 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7120 | + " reason=" + reason); |
| 7121 | } |
| 7122 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7123 | if (phone != null) { |
| 7124 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7125 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7126 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7127 | return retVal; |
| 7128 | } else { |
| 7129 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7130 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7131 | + subId + " retVal=false"); |
| 7132 | } |
| 7133 | return false; |
| 7134 | } |
| 7135 | } finally { |
| 7136 | Binder.restoreCallingIdentity(identity); |
| 7137 | } |
| 7138 | } |
| 7139 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7140 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7141 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7142 | // No permission needed; this only lets the caller inspect their own status. |
| 7143 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7144 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7145 | |
| 7146 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7147 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7148 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7149 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7150 | } |
| 7151 | |
| 7152 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7153 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7154 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7155 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7156 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7157 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7158 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7159 | if (cpt == null) { |
| 7160 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7161 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7162 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7163 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7167 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7168 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7169 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7170 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7171 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7172 | Phone phone = getPhone(subId); |
| 7173 | if (phone == null) { |
| 7174 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7175 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7176 | } |
| 7177 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7178 | if (cpt == null) { |
| 7179 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7180 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7181 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7182 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | @Override |
| 7186 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7187 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7188 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7189 | } |
| 7190 | |
| 7191 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7192 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7193 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7194 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7195 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7196 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7197 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7198 | if (phone == null) { |
| 7199 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7200 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7201 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7202 | if (cpt == null) { |
| 7203 | continue; |
| 7204 | } |
| 7205 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7206 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7207 | break; |
| 7208 | } |
| 7209 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7210 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7211 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7212 | |
| 7213 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7214 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7215 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7216 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7217 | if (phone == null) { |
| 7218 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7219 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7220 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7221 | if (cpt == null) { |
| 7222 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7223 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7224 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7225 | } |
| 7226 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7227 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7228 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7229 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7230 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7231 | if (phone == null) { |
| 7232 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7233 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7234 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7235 | if (cpt == null) { |
| 7236 | return Collections.emptyList(); |
| 7237 | } |
| 7238 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7239 | } |
| 7240 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7241 | @Override |
| 7242 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7243 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7244 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7245 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7246 | try { |
| 7247 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7248 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7249 | } |
| 7250 | } finally { |
| 7251 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7252 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7253 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7254 | } |
| 7255 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7256 | @Override |
| 7257 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7258 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7259 | |
| 7260 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7261 | if (phone == null) { |
| 7262 | return null; |
| 7263 | } |
| 7264 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7265 | if (cpt == null) { |
| 7266 | return null; |
| 7267 | } |
| 7268 | return cpt.getCarrierServicePackageName(); |
| 7269 | } |
| 7270 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7271 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7272 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7273 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7274 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7275 | return null; |
| 7276 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7277 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7278 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7279 | return null; |
| 7280 | } |
| 7281 | return iccId; |
| 7282 | } |
| 7283 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7284 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7285 | public void setCallComposerStatus(int subId, int status) { |
| 7286 | enforceModifyPermission(); |
| 7287 | |
| 7288 | final long identity = Binder.clearCallingIdentity(); |
| 7289 | try { |
| 7290 | Phone phone = getPhone(subId); |
| 7291 | if (phone != null) { |
| 7292 | Phone defaultPhone = phone.getImsPhone(); |
| 7293 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7294 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7295 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7296 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7297 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7298 | } |
| 7299 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7300 | } catch (ImsException e) { |
| 7301 | throw new ServiceSpecificException(e.getCode()); |
| 7302 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7303 | Binder.restoreCallingIdentity(identity); |
| 7304 | } |
| 7305 | } |
| 7306 | |
| 7307 | @Override |
| 7308 | public int getCallComposerStatus(int subId) { |
| 7309 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7310 | |
| 7311 | final long identity = Binder.clearCallingIdentity(); |
| 7312 | try { |
| 7313 | Phone phone = getPhone(subId); |
| 7314 | if (phone != null) { |
| 7315 | Phone defaultPhone = phone.getImsPhone(); |
| 7316 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7317 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7318 | return imsPhone.getCallComposerStatus(); |
| 7319 | } |
| 7320 | } |
| 7321 | } finally { |
| 7322 | Binder.restoreCallingIdentity(identity); |
| 7323 | } |
| 7324 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7325 | } |
| 7326 | |
| 7327 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7328 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7329 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7330 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7331 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7332 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | final long identity = Binder.clearCallingIdentity(); |
| 7334 | try { |
| 7335 | final String iccId = getIccId(subId); |
| 7336 | final Phone phone = getPhone(subId); |
| 7337 | if (phone == null) { |
| 7338 | return false; |
| 7339 | } |
| 7340 | final String subscriberId = phone.getSubscriberId(); |
| 7341 | |
| 7342 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7343 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7344 | + subscriberId + " to " + number); |
| 7345 | } |
| 7346 | |
| 7347 | if (TextUtils.isEmpty(iccId)) { |
| 7348 | return false; |
| 7349 | } |
| 7350 | |
| 7351 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7352 | |
| 7353 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7354 | if (alphaTag == null) { |
| 7355 | editor.remove(alphaTagPrefKey); |
| 7356 | } else { |
| 7357 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7358 | } |
| 7359 | |
| 7360 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7361 | // track all merged IMSIs based on line number |
| 7362 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7363 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7364 | if (number == null) { |
| 7365 | editor.remove(numberPrefKey); |
| 7366 | editor.remove(subscriberPrefKey); |
| 7367 | } else { |
| 7368 | editor.putString(numberPrefKey, number); |
| 7369 | editor.putString(subscriberPrefKey, subscriberId); |
| 7370 | } |
| 7371 | |
| 7372 | editor.commit(); |
| 7373 | return true; |
| 7374 | } finally { |
| 7375 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7376 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7377 | } |
| 7378 | |
| 7379 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7380 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7381 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7382 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7383 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7384 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7385 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7386 | return null; |
| 7387 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7388 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | final long identity = Binder.clearCallingIdentity(); |
| 7390 | try { |
| 7391 | String iccId = getIccId(subId); |
| 7392 | if (iccId != null) { |
| 7393 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7394 | if (DBG_MERGE) { |
| 7395 | log("getLine1NumberForDisplay returning " |
| 7396 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7397 | } |
| 7398 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7399 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7400 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7401 | return null; |
| 7402 | } finally { |
| 7403 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7404 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7408 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7409 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7410 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7411 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7412 | return null; |
| 7413 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7414 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7415 | final long identity = Binder.clearCallingIdentity(); |
| 7416 | try { |
| 7417 | String iccId = getIccId(subId); |
| 7418 | if (iccId != null) { |
| 7419 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7420 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7421 | } |
| 7422 | return null; |
| 7423 | } finally { |
| 7424 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7425 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7426 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7427 | |
| 7428 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7429 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7430 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7431 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7432 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7433 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7434 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7435 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7436 | return null; |
| 7437 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7438 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7439 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7440 | // the process, where TelephonyManager was instantiated. |
| 7441 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7442 | final long identity = Binder.clearCallingIdentity(); |
| 7443 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7444 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7446 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7447 | |
| 7448 | // Figure out what subscribers are currently active |
| 7449 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7450 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7451 | // Only consider subs which match the current subId |
| 7452 | // This logic can be simplified. See b/131189269 for progress. |
| 7453 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7454 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7455 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7456 | |
| 7457 | // First pass, find a number override for an active subscriber |
| 7458 | String mergeNumber = null; |
| 7459 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7460 | for (String key : prefs.keySet()) { |
| 7461 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7462 | final String subscriberId = (String) prefs.get(key); |
| 7463 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7464 | final String iccId = key.substring( |
| 7465 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7466 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7467 | mergeNumber = (String) prefs.get(numberKey); |
| 7468 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7469 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7470 | + " for active subscriber " + subscriberId); |
| 7471 | } |
| 7472 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7473 | break; |
| 7474 | } |
| 7475 | } |
| 7476 | } |
| 7477 | } |
| 7478 | |
| 7479 | // Shortcut when no active merged subscribers |
| 7480 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7481 | return null; |
| 7482 | } |
| 7483 | |
| 7484 | // Second pass, find all subscribers under that line override |
| 7485 | final ArraySet<String> result = new ArraySet<>(); |
| 7486 | for (String key : prefs.keySet()) { |
| 7487 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7488 | final String number = (String) prefs.get(key); |
| 7489 | if (mergeNumber.equals(number)) { |
| 7490 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7491 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7492 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7493 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7494 | result.add(subscriberId); |
| 7495 | } |
| 7496 | } |
| 7497 | } |
| 7498 | } |
| 7499 | |
| 7500 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7501 | Arrays.sort(resultArray); |
| 7502 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7503 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7505 | } |
| 7506 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7507 | } finally { |
| 7508 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7509 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7513 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7514 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7515 | |
| 7516 | final long identity = Binder.clearCallingIdentity(); |
| 7517 | try { |
| 7518 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7519 | TelephonyManager.class); |
| 7520 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7521 | if (subscriberId == null) { |
| 7522 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7523 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7524 | + subId); |
| 7525 | } |
| 7526 | return null; |
| 7527 | } |
| 7528 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7529 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7530 | .getSubscriptionInfo(subId); |
| 7531 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7532 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7533 | if (groupUuid == null) { |
| 7534 | return new String[]{subscriberId}; |
| 7535 | } |
| 7536 | |
| 7537 | // Get all subscriberIds from the group. |
| 7538 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7539 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7540 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7541 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7542 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7543 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7544 | if (subscriberId != null) { |
| 7545 | mergedSubscriberIds.add(subscriberId); |
| 7546 | } |
| 7547 | } |
| 7548 | |
| 7549 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7550 | } finally { |
| 7551 | Binder.restoreCallingIdentity(identity); |
| 7552 | |
| 7553 | } |
| 7554 | } |
| 7555 | |
| 7556 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7557 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7558 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7559 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7560 | |
| 7561 | final long identity = Binder.clearCallingIdentity(); |
| 7562 | try { |
| 7563 | final Phone phone = getPhone(subId); |
| 7564 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7565 | } finally { |
| 7566 | Binder.restoreCallingIdentity(identity); |
| 7567 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7568 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7569 | |
| 7570 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7571 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7572 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7573 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7574 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7575 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7576 | |
| 7577 | final long identity = Binder.clearCallingIdentity(); |
| 7578 | try { |
| 7579 | final Phone phone = getPhone(subId); |
| 7580 | if (phone == null) { |
| 7581 | return false; |
| 7582 | } |
| 7583 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7584 | cdmaNonRoamingList); |
| 7585 | } finally { |
| 7586 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7587 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7591 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7592 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7593 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7594 | if (phone == null) { |
| 7595 | return raf; |
| 7596 | } |
| 7597 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7598 | try { |
| 7599 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7600 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7601 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7602 | } catch (SecurityException e) { |
| 7603 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7604 | throw e; |
| 7605 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7607 | final long identity = Binder.clearCallingIdentity(); |
| 7608 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7609 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7610 | } finally { |
| 7611 | Binder.restoreCallingIdentity(identity); |
| 7612 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7613 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7614 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7615 | |
| 7616 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7617 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7618 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7619 | try { |
| 7620 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7621 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7622 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7623 | } |
| 7624 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7625 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7626 | } |
| 7627 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7628 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7629 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7630 | throw new SecurityException("App must be the dialer role holder to" |
| 7631 | + " upload a call composer pic"); |
| 7632 | } |
| 7633 | |
| 7634 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7635 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7636 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7637 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7638 | boolean readUntilEnd = false; |
| 7639 | int totalBytesRead = 0; |
| 7640 | byte[] buffer = new byte[16 * 1024]; |
| 7641 | while (true) { |
| 7642 | int numRead; |
| 7643 | try { |
| 7644 | numRead = input.read(buffer); |
| 7645 | } catch (IOException e) { |
| 7646 | try { |
| 7647 | fd.checkError(); |
| 7648 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7649 | null); |
| 7650 | } catch (IOException e1) { |
| 7651 | // This means that the other side closed explicitly with an error. If this |
| 7652 | // happens, log and ignore. |
| 7653 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7654 | } |
| 7655 | break; |
| 7656 | } |
| 7657 | if (numRead == -1) { |
| 7658 | readUntilEnd = true; |
| 7659 | break; |
| 7660 | } |
| 7661 | totalBytesRead += numRead; |
| 7662 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7663 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7664 | try { |
| 7665 | input.close(); |
| 7666 | } catch (IOException e) { |
| 7667 | // ignore |
| 7668 | } |
| 7669 | break; |
| 7670 | } |
| 7671 | output.write(buffer, 0, numRead); |
| 7672 | } |
| 7673 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7674 | // close is above, where the picture size is too big. |
| 7675 | |
| 7676 | try { |
| 7677 | fd.checkError(); |
| 7678 | } catch (IOException e) { |
| 7679 | loge("Remote end for call composer closed with an error: " + e); |
| 7680 | return; |
| 7681 | } |
| 7682 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7683 | if (!readUntilEnd) { |
| 7684 | loge("Did not finish reading entire image; aborting"); |
| 7685 | return; |
| 7686 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7687 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7688 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7689 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7690 | new CallComposerPictureTransfer.Factory() {}, |
| 7691 | imageData, |
| 7692 | (result) -> { |
| 7693 | if (result.first != null) { |
| 7694 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7695 | Bundle outputResult = new Bundle(); |
| 7696 | outputResult.putParcelable( |
| 7697 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7698 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7699 | outputResult); |
| 7700 | } else { |
| 7701 | callback.send(result.second, null); |
| 7702 | } |
| 7703 | } |
| 7704 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7705 | }); |
| 7706 | } |
| 7707 | |
| 7708 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7709 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7710 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7711 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7712 | |
| 7713 | final long identity = Binder.clearCallingIdentity(); |
| 7714 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7715 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7716 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7717 | } finally { |
| 7718 | Binder.restoreCallingIdentity(identity); |
| 7719 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7720 | } |
| 7721 | |
| 7722 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7723 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7724 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7725 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7726 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7727 | return false; |
| 7728 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7729 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7730 | final long identity = Binder.clearCallingIdentity(); |
| 7731 | try { |
| 7732 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7733 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7734 | // In the long run, we may instead need to check if there exists a connection service |
| 7735 | // which can support video calling. |
| 7736 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7737 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7738 | return imsManager.isVtEnabledByPlatform() |
| 7739 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7740 | && imsManager.isVtEnabledByUser(); |
| 7741 | } finally { |
| 7742 | Binder.restoreCallingIdentity(identity); |
| 7743 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7744 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7745 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7746 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7747 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7748 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7750 | mApp, subId, callingPackage, callingFeatureId, |
| 7751 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 | return false; |
| 7753 | } |
| 7754 | |
| 7755 | final long identity = Binder.clearCallingIdentity(); |
| 7756 | try { |
| 7757 | CarrierConfigManager configManager = |
| 7758 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7759 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7760 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7761 | } finally { |
| 7762 | Binder.restoreCallingIdentity(identity); |
| 7763 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7767 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7768 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7769 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7770 | return false; |
| 7771 | } |
| 7772 | |
| 7773 | final long identity = Binder.clearCallingIdentity(); |
| 7774 | try { |
| 7775 | CarrierConfigManager configManager = |
| 7776 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7777 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7778 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7779 | } finally { |
| 7780 | Binder.restoreCallingIdentity(identity); |
| 7781 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7782 | } |
| 7783 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7784 | @Override |
| 7785 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7786 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7787 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7788 | } |
| 7789 | |
| 7790 | @Override |
| 7791 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7792 | final long identity = Binder.clearCallingIdentity(); |
| 7793 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7794 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7795 | } finally { |
| 7796 | Binder.restoreCallingIdentity(identity); |
| 7797 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7798 | } |
| 7799 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7800 | /** |
| 7801 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7802 | * support for the feature and device firmware support. |
| 7803 | * |
| 7804 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7805 | */ |
| 7806 | @Override |
| 7807 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7808 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7809 | final Phone phone = getPhone(subscriptionId); |
| 7810 | if (phone == null) { |
| 7811 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7812 | return false; |
| 7813 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7814 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7815 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7816 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7817 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7818 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7819 | return isCarrierSupported && isDeviceSupported; |
| 7820 | } finally { |
| 7821 | Binder.restoreCallingIdentity(identity); |
| 7822 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7823 | } |
| 7824 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7825 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7826 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7827 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7828 | * 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] | 7829 | */ |
| 7830 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7831 | final long identity = Binder.clearCallingIdentity(); |
| 7832 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7833 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7834 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7835 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7836 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7837 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7838 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7839 | } finally { |
| 7840 | Binder.restoreCallingIdentity(identity); |
| 7841 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7842 | } |
| 7843 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7844 | @Deprecated |
| 7845 | @Override |
| 7846 | public String getDeviceId(String callingPackage) { |
| 7847 | return getDeviceIdWithFeature(callingPackage, null); |
| 7848 | } |
| 7849 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7850 | /** |
| 7851 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7852 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7853 | * |
| 7854 | * <p>Requires Permission: |
| 7855 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7856 | */ |
| 7857 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7858 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7859 | try { |
| 7860 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7861 | } catch (SecurityException se) { |
| 7862 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7863 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7864 | + Binder.getCallingUid()); |
| 7865 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7866 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7867 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7868 | return null; |
| 7869 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7870 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7871 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7872 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7873 | return null; |
| 7874 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7875 | |
| 7876 | final long identity = Binder.clearCallingIdentity(); |
| 7877 | try { |
| 7878 | return phone.getDeviceId(); |
| 7879 | } finally { |
| 7880 | Binder.restoreCallingIdentity(identity); |
| 7881 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7882 | } |
| 7883 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7884 | /** |
| 7885 | * {@hide} |
| 7886 | * Returns the IMS Registration Status on a particular subid |
| 7887 | * |
| 7888 | * @param subId |
| 7889 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7890 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7891 | Phone phone = getPhone(subId); |
| 7892 | if (phone != null) { |
| 7893 | return phone.isImsRegistered(); |
| 7894 | } else { |
| 7895 | return false; |
| 7896 | } |
| 7897 | } |
| 7898 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7899 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7900 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7901 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7902 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7903 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7904 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7905 | } |
| 7906 | final long identity = Binder.clearCallingIdentity(); |
| 7907 | try { |
| 7908 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7909 | } finally { |
| 7910 | Binder.restoreCallingIdentity(identity); |
| 7911 | } |
| 7912 | } |
| 7913 | |
| 7914 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7915 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7916 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7917 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7918 | mApp, |
| 7919 | subscriptionId, |
| 7920 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7921 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7922 | final long identity = Binder.clearCallingIdentity(); |
| 7923 | try { |
| 7924 | Phone phone = getPhone(subscriptionId); |
| 7925 | if (phone == null) { |
| 7926 | return null; |
| 7927 | } |
| 7928 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7929 | } finally { |
| 7930 | Binder.restoreCallingIdentity(identity); |
| 7931 | } |
| 7932 | } |
| 7933 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7934 | /** |
| 7935 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7936 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7937 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7938 | final long identity = Binder.clearCallingIdentity(); |
| 7939 | try { |
| 7940 | Phone phone = getPhone(subId); |
| 7941 | if (phone != null) { |
| 7942 | return phone.isWifiCallingEnabled(); |
| 7943 | } else { |
| 7944 | return false; |
| 7945 | } |
| 7946 | } finally { |
| 7947 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7948 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7949 | } |
| 7950 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7951 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7952 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7953 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7954 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7955 | final long identity = Binder.clearCallingIdentity(); |
| 7956 | try { |
| 7957 | Phone phone = getPhone(subId); |
| 7958 | if (phone != null) { |
| 7959 | return phone.isVideoEnabled(); |
| 7960 | } else { |
| 7961 | return false; |
| 7962 | } |
| 7963 | } finally { |
| 7964 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7965 | } |
| 7966 | } |
| 7967 | |
| 7968 | /** |
| 7969 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7970 | * defined in {@link ImsRegistrationImplBase}. |
| 7971 | */ |
| 7972 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7973 | final long identity = Binder.clearCallingIdentity(); |
| 7974 | try { |
| 7975 | Phone phone = getPhone(subId); |
| 7976 | if (phone != null) { |
| 7977 | return phone.getImsRegistrationTech(); |
| 7978 | } else { |
| 7979 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7980 | } |
| 7981 | } finally { |
| 7982 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7983 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7984 | } |
| 7985 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7986 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7987 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7988 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7989 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7990 | return; |
| 7991 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7992 | Phone defaultPhone = getDefaultPhone(); |
| 7993 | if (defaultPhone != null) { |
| 7994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7995 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7996 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7997 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7998 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7999 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8000 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8001 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8002 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8003 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8004 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8005 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8006 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8007 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8008 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8009 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8010 | // There has been issues when Sms raw table somehow stores orphan |
| 8011 | // fragments. They lead to garbled message when new fragments come |
| 8012 | // in and combined with those stale ones. In case this happens again, |
| 8013 | // user can reset all network settings which will clean up this table. |
| 8014 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8015 | // Clean up IMS settings as well here. |
| 8016 | int slotId = getSlotIndex(subId); |
| 8017 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8018 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8019 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8020 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8021 | if (defaultPhone == null) { |
| 8022 | return; |
| 8023 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8024 | // Erase modem config if erase modem on network setting is enabled. |
| 8025 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8026 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8027 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8028 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8029 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8030 | |
| 8031 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8032 | } finally { |
| 8033 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8034 | } |
| 8035 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8036 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8037 | @VisibleForTesting |
| 8038 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8039 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8040 | return; |
| 8041 | } |
| 8042 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8043 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8044 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8045 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8046 | "user=" + defaultNetworkType); |
| 8047 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8048 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8049 | defaultNetworkType, null); |
| 8050 | } |
| 8051 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8052 | private void cleanUpSmsRawTable(Context context) { |
| 8053 | ContentResolver resolver = context.getContentResolver(); |
| 8054 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8055 | resolver.delete(uri, null, null); |
| 8056 | } |
| 8057 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8058 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8059 | public String getSimLocaleForSubscriber(int subId) { |
| 8060 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8061 | final Phone phone = getPhone(subId); |
| 8062 | if (phone == null) { |
| 8063 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8064 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8065 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8066 | final long identity = Binder.clearCallingIdentity(); |
| 8067 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8068 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8069 | phone.getContext().getOpPackageName(), |
| 8070 | phone.getContext().getAttributionTag()); |
| 8071 | if (info == null) { |
| 8072 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8073 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8074 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8075 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8076 | // preferences (EF-PL and EF-LI)... |
| 8077 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8078 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8079 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8080 | if (localeFromDefaultSim != null) { |
| 8081 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8082 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8083 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8084 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8085 | } else { |
| 8086 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8087 | } |
| 8088 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8089 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8090 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8091 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8092 | // the SIM and carrier preferences does not include a country we add the country |
| 8093 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8094 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8095 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8096 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8097 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8098 | } |
| 8099 | |
| 8100 | if (DBG) log("No locale found - returning null"); |
| 8101 | return null; |
| 8102 | } finally { |
| 8103 | Binder.restoreCallingIdentity(identity); |
| 8104 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8105 | } |
| 8106 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8107 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8108 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8109 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8110 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8111 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8112 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8113 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8114 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8115 | return localeTag; |
| 8116 | } |
| 8117 | } |
| 8118 | return inputLocale.toLanguageTag(); |
| 8119 | } |
| 8120 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8121 | /** |
| 8122 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8123 | */ |
| 8124 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8125 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8126 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8127 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8128 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8129 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8130 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8131 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8132 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8133 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8134 | * representing the state of the modem. |
| 8135 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8136 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8137 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8138 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8139 | */ |
| 8140 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8141 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8142 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8143 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8144 | |
| 8145 | final long identity = Binder.clearCallingIdentity(); |
| 8146 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8147 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8148 | } finally { |
| 8149 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8150 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8151 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8152 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8153 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8154 | // less than total activity duration. |
| 8155 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8156 | if (info == null) { |
| 8157 | return false; |
| 8158 | } |
| 8159 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8160 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8161 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8162 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8163 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8164 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8165 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8166 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8167 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8168 | } |
| 8169 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8170 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8171 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8172 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8173 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8174 | |
| 8175 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8176 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8177 | } |
| 8178 | |
| 8179 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8180 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8181 | rat, |
| 8182 | freq, |
| 8183 | info.getReceiveTimeMillis(rat, freq) |
| 8184 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8185 | } |
| 8186 | |
| 8187 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8188 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8189 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8190 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8191 | |
| 8192 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8193 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8194 | } |
| 8195 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8196 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8197 | rat, |
| 8198 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8199 | } |
| 8200 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8201 | /** |
| 8202 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8203 | * @param info recent ModemActivityInfo |
| 8204 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8205 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8206 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8207 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8208 | boolean matched; |
| 8209 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8210 | matched = false; |
| 8211 | int rat = info.getSpecificInfoRat(i); |
| 8212 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8213 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8214 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8215 | //if it already exists |
| 8216 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8217 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8218 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8219 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8220 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8221 | updateLastModemActivityInfo(info, rat, freq); |
| 8222 | matched = true; |
| 8223 | } |
| 8224 | } else { |
| 8225 | updateLastModemActivityInfo(info, rat); |
| 8226 | matched = true; |
| 8227 | } |
| 8228 | } |
| 8229 | } |
| 8230 | |
| 8231 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8232 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8233 | new ActivityStatsTechSpecificInfo( |
| 8234 | rat, |
| 8235 | freq, |
| 8236 | info.getTransmitTimeMillis(rat, freq), |
| 8237 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8238 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8239 | } |
| 8240 | } |
| 8241 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8242 | mLastModemActivitySpecificInfo = |
| 8243 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8244 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8245 | |
| 8246 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8247 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8248 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8249 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8250 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8251 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8252 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8253 | |
| 8254 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8255 | new ModemActivityInfo( |
| 8256 | mLastModemActivityInfo.getTimestampMillis(), |
| 8257 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8258 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8259 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8260 | } |
| 8261 | |
| 8262 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8263 | ActivityStatsTechSpecificInfo[] info) { |
| 8264 | int infoSize = info.length; |
| 8265 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8266 | for (int i = 0; i < infoSize; i++) { |
| 8267 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8268 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8269 | info[i].getTransmitTimeMillis(), |
| 8270 | (int) info[i].getReceiveTimeMillis()); |
| 8271 | } |
| 8272 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8273 | } |
| 8274 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8275 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8276 | * Returns the service state information on specified subscription. |
| 8277 | */ |
| 8278 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8279 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8280 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8281 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8282 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8283 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8284 | return null; |
| 8285 | } |
| 8286 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8287 | boolean hasFinePermission = false; |
| 8288 | boolean hasCoarsePermission = false; |
| 8289 | if (!renounceFineLocationAccess) { |
| 8290 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8291 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8292 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8293 | .setCallingPackage(callingPackage) |
| 8294 | .setCallingFeatureId(callingFeatureId) |
| 8295 | .setCallingPid(Binder.getCallingPid()) |
| 8296 | .setCallingUid(Binder.getCallingUid()) |
| 8297 | .setMethod("getServiceStateForSubscriber") |
| 8298 | .setLogAsInfo(true) |
| 8299 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8300 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8301 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8302 | .build()); |
| 8303 | hasFinePermission = |
| 8304 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8305 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8306 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8307 | if (!renounceCoarseLocationAccess) { |
| 8308 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8309 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8310 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8311 | .setCallingPackage(callingPackage) |
| 8312 | .setCallingFeatureId(callingFeatureId) |
| 8313 | .setCallingPid(Binder.getCallingPid()) |
| 8314 | .setCallingUid(Binder.getCallingUid()) |
| 8315 | .setMethod("getServiceStateForSubscriber") |
| 8316 | .setLogAsInfo(true) |
| 8317 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8318 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8319 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8320 | .build()); |
| 8321 | hasCoarsePermission = |
| 8322 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8323 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8324 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8325 | final Phone phone = getPhone(subId); |
| 8326 | if (phone == null) { |
| 8327 | return null; |
| 8328 | } |
| 8329 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8330 | final long identity = Binder.clearCallingIdentity(); |
| 8331 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8332 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8333 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8335 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8336 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8337 | .getSubscriptionInfoInternal(subId); |
| 8338 | if (subInfo == null || !subInfo.isActive()) { |
| 8339 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8340 | + "subId=" + subId); |
| 8341 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8342 | } |
| 8343 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8344 | ServiceState ss = phone.getServiceState(); |
| 8345 | |
| 8346 | // Scrub out the location info in ServiceState depending on what level of access |
| 8347 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8348 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8349 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8350 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8351 | } finally { |
| 8352 | Binder.restoreCallingIdentity(identity); |
| 8353 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8354 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8355 | |
| 8356 | /** |
| 8357 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8358 | * |
| 8359 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8360 | * voicemail ringtone. |
| 8361 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8362 | * PhoneAccount. |
| 8363 | */ |
| 8364 | @Override |
| 8365 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8366 | final long identity = Binder.clearCallingIdentity(); |
| 8367 | try { |
| 8368 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8369 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8370 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8371 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8372 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8373 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8374 | } finally { |
| 8375 | Binder.restoreCallingIdentity(identity); |
| 8376 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8377 | } |
| 8378 | |
| 8379 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8380 | * Sets the per-account voicemail ringtone. |
| 8381 | * |
| 8382 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8383 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8384 | * |
| 8385 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8386 | * voicemail ringtone. |
| 8387 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8388 | * PhoneAccount. |
| 8389 | */ |
| 8390 | @Override |
| 8391 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8392 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8393 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8394 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8395 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8396 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8397 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8398 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8399 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8400 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8401 | |
| 8402 | final long identity = Binder.clearCallingIdentity(); |
| 8403 | try { |
| 8404 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8405 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8406 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 | } |
| 8408 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8409 | } finally { |
| 8410 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8411 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8412 | } |
| 8413 | |
| 8414 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8415 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8416 | * |
| 8417 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8418 | * voicemail vibration setting. |
| 8419 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8420 | */ |
| 8421 | @Override |
| 8422 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8423 | final long identity = Binder.clearCallingIdentity(); |
| 8424 | try { |
| 8425 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8426 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8427 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8428 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8429 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8430 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8431 | } finally { |
| 8432 | Binder.restoreCallingIdentity(identity); |
| 8433 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8434 | } |
| 8435 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8436 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8437 | * Sets the per-account voicemail vibration. |
| 8438 | * |
| 8439 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8440 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8441 | * |
| 8442 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8443 | * voicemail vibration setting. |
| 8444 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8445 | * specific PhoneAccount. |
| 8446 | */ |
| 8447 | @Override |
| 8448 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8449 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8450 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8451 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8452 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8453 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8455 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8456 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8457 | } |
| 8458 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8459 | final long identity = Binder.clearCallingIdentity(); |
| 8460 | try { |
| 8461 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8462 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8463 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8464 | } |
| 8465 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8466 | } finally { |
| 8467 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8468 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8469 | } |
| 8470 | |
| 8471 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8472 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8473 | * |
| 8474 | * @throws SecurityException if the caller does not have the required permission |
| 8475 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8476 | @VisibleForTesting |
| 8477 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8478 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8479 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8480 | } |
| 8481 | |
| 8482 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8483 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8484 | * permission. |
| 8485 | * |
| 8486 | * @throws SecurityException if the caller does not have the required permission |
| 8487 | */ |
| 8488 | private void enforceSendSmsPermission() { |
| 8489 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8490 | } |
| 8491 | |
| 8492 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8493 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8494 | * users permission. |
| 8495 | * |
| 8496 | * @throws SecurityException if the caller does not have the required permission |
| 8497 | */ |
| 8498 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8499 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8500 | } |
| 8501 | |
| 8502 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8503 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8504 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8505 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8506 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8507 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8508 | final long identity = Binder.clearCallingIdentity(); |
| 8509 | try { |
| 8510 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8511 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8512 | if (componentName == null) { |
| 8513 | throw new SecurityException( |
| 8514 | "Caller not current active visual voicemail package[null]"); |
| 8515 | } |
| 8516 | String vvmPackage = componentName.getPackageName(); |
| 8517 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8518 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8519 | } |
| 8520 | } finally { |
| 8521 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8522 | } |
| 8523 | } |
| 8524 | |
| 8525 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8526 | * Return the application ID for the app type. |
| 8527 | * |
| 8528 | * @param subId the subscription ID that this request applies to. |
| 8529 | * @param appType the uicc app type. |
| 8530 | * @return Application ID for specificied app type, or null if no uicc. |
| 8531 | */ |
| 8532 | @Override |
| 8533 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8534 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8535 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8536 | |
| 8537 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8538 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8539 | if (phone == null) { |
| 8540 | return null; |
| 8541 | } |
| 8542 | String aid = null; |
| 8543 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8544 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8545 | .getApplicationByType(appType).getAid(); |
| 8546 | } catch (Exception e) { |
| 8547 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8548 | } |
| 8549 | return aid; |
| 8550 | } finally { |
| 8551 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8552 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8553 | } |
| 8554 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8555 | /** |
| 8556 | * Return the Electronic Serial Number. |
| 8557 | * |
| 8558 | * @param subId the subscription ID that this request applies to. |
| 8559 | * @return ESN or null if error. |
| 8560 | */ |
| 8561 | @Override |
| 8562 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8563 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8564 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8565 | |
| 8566 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8567 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8568 | if (phone == null) { |
| 8569 | return null; |
| 8570 | } |
| 8571 | String esn = null; |
| 8572 | try { |
| 8573 | esn = phone.getEsn(); |
| 8574 | } catch (Exception e) { |
| 8575 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8576 | } |
| 8577 | return esn; |
| 8578 | } finally { |
| 8579 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8580 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8581 | } |
| 8582 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8583 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8584 | * Return the Preferred Roaming List Version. |
| 8585 | * |
| 8586 | * @param subId the subscription ID that this request applies to. |
| 8587 | * @return PRLVersion or null if error. |
| 8588 | */ |
| 8589 | @Override |
| 8590 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8591 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8592 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8593 | |
| 8594 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8595 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8596 | if (phone == null) { |
| 8597 | return null; |
| 8598 | } |
| 8599 | String cdmaPrlVersion = null; |
| 8600 | try { |
| 8601 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8602 | } catch (Exception e) { |
| 8603 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8604 | } |
| 8605 | return cdmaPrlVersion; |
| 8606 | } finally { |
| 8607 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8608 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8609 | } |
| 8610 | |
| 8611 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8612 | * Get snapshot of Telephony histograms |
| 8613 | * @return List of Telephony histograms |
| 8614 | * @hide |
| 8615 | */ |
| 8616 | @Override |
| 8617 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8619 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8620 | |
| 8621 | final long identity = Binder.clearCallingIdentity(); |
| 8622 | try { |
| 8623 | return RIL.getTelephonyRILTimingHistograms(); |
| 8624 | } finally { |
| 8625 | Binder.restoreCallingIdentity(identity); |
| 8626 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8627 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8628 | |
| 8629 | /** |
| 8630 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8631 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8632 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8633 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8634 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8635 | * @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] | 8636 | */ |
| 8637 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8638 | @TelephonyManager.SetCarrierRestrictionResult |
| 8639 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8640 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8641 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8642 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8643 | if (carrierRestrictionRules == null) { |
| 8644 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8645 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8647 | final long identity = Binder.clearCallingIdentity(); |
| 8648 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8649 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8650 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8651 | } finally { |
| 8652 | Binder.restoreCallingIdentity(identity); |
| 8653 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8654 | } |
| 8655 | |
| 8656 | /** |
| 8657 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8658 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8659 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8660 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8661 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8662 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8663 | */ |
| 8664 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8665 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8666 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8667 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8668 | |
| 8669 | final long identity = Binder.clearCallingIdentity(); |
| 8670 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8671 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8672 | if (response instanceof CarrierRestrictionRules) { |
| 8673 | return (CarrierRestrictionRules) response; |
| 8674 | } |
| 8675 | // Response is an Exception of some kind, |
| 8676 | // which is signalled to the user as a NULL retval |
| 8677 | return null; |
| 8678 | } catch (Exception e) { |
| 8679 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8680 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8681 | } finally { |
| 8682 | Binder.restoreCallingIdentity(identity); |
| 8683 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8684 | } |
| 8685 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8686 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8687 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8688 | * through the callback. |
| 8689 | * |
| 8690 | * @param callback The callback that will be used to send the result. |
| 8691 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8692 | * the caller is not allowlisted. |
| 8693 | */ |
| 8694 | @Override |
| 8695 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8696 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8697 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8698 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8699 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8700 | throw new SecurityException("Not an authorized caller"); |
| 8701 | } |
| 8702 | final long identity = Binder.clearCallingIdentity(); |
| 8703 | try { |
| 8704 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8705 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8706 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8707 | } finally { |
| 8708 | Binder.restoreCallingIdentity(identity); |
| 8709 | } |
| 8710 | } |
| 8711 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 8712 | @Override |
| 8713 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 8714 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 8715 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8716 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 8717 | } |
| 8718 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8719 | @VisibleForTesting |
| 8720 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8721 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8722 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8723 | } |
| 8724 | |
| 8725 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8726 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8727 | * @param subId the subscription ID that this action applies to. |
| 8728 | * @param enabled control enable or disable radio. |
| 8729 | * {@hide} |
| 8730 | */ |
| 8731 | @Override |
| 8732 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8733 | enforceModifyPermission(); |
| 8734 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8735 | |
| 8736 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8737 | if (phone == null) { |
| 8738 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8739 | return; |
| 8740 | } |
| 8741 | try { |
| 8742 | phone.carrierActionSetRadioEnabled(enabled); |
| 8743 | } catch (Exception e) { |
| 8744 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8745 | } finally { |
| 8746 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8747 | } |
| 8748 | } |
| 8749 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8750 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8751 | * Enable or disable Voice over NR (VoNR) |
| 8752 | * @param subId the subscription ID that this action applies to. |
| 8753 | * @param enabled enable or disable VoNR. |
| 8754 | * @return operation result. |
| 8755 | */ |
| 8756 | @Override |
| 8757 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8758 | enforceModifyPermission(); |
| 8759 | final Phone phone = getPhone(subId); |
| 8760 | |
| 8761 | final long identity = Binder.clearCallingIdentity(); |
| 8762 | if (phone == null) { |
| 8763 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8764 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8765 | } |
| 8766 | |
| 8767 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8768 | try { |
| 8769 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8770 | workSource); |
| 8771 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8772 | |
| 8773 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8774 | if (DBG) { |
| 8775 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8776 | } |
| 8777 | SubscriptionManager.setSubscriptionProperty( |
| 8778 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8779 | (enabled ? "1" : "0")); |
| 8780 | } |
| 8781 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8782 | return result; |
| 8783 | } finally { |
| 8784 | Binder.restoreCallingIdentity(identity); |
| 8785 | } |
| 8786 | } |
| 8787 | |
| 8788 | /** |
| 8789 | * Is voice over NR enabled |
| 8790 | * @return true if VoNR is enabled else false |
| 8791 | */ |
| 8792 | @Override |
| 8793 | public boolean isVoNrEnabled(int subId) { |
| 8794 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8795 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8796 | final long identity = Binder.clearCallingIdentity(); |
| 8797 | try { |
| 8798 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8799 | null, subId, workSource); |
| 8800 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8801 | return isEnabled; |
| 8802 | } finally { |
| 8803 | Binder.restoreCallingIdentity(identity); |
| 8804 | } |
| 8805 | } |
| 8806 | |
| 8807 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8808 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8809 | * network status based on which carrier apps could apply actions accordingly, |
| 8810 | * enable/disable default url handler for example. |
| 8811 | * |
| 8812 | * @param subId the subscription ID that this action applies to. |
| 8813 | * @param report control start/stop reporting the default network status. |
| 8814 | * {@hide} |
| 8815 | */ |
| 8816 | @Override |
| 8817 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8818 | enforceModifyPermission(); |
| 8819 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8820 | |
| 8821 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8822 | if (phone == null) { |
| 8823 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8824 | return; |
| 8825 | } |
| 8826 | try { |
| 8827 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8828 | } catch (Exception e) { |
| 8829 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8830 | } finally { |
| 8831 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8832 | } |
| 8833 | } |
| 8834 | |
| 8835 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8836 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8837 | * @param subId the subscription ID that this action applies to. |
| 8838 | * {@hide} |
| 8839 | */ |
| 8840 | @Override |
| 8841 | public void carrierActionResetAll(int subId) { |
| 8842 | enforceModifyPermission(); |
| 8843 | final Phone phone = getPhone(subId); |
| 8844 | if (phone == null) { |
| 8845 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8846 | return; |
| 8847 | } |
| 8848 | try { |
| 8849 | phone.carrierActionResetAll(); |
| 8850 | } catch (Exception e) { |
| 8851 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8852 | } |
| 8853 | } |
| 8854 | |
| 8855 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8856 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8857 | * bug report is being generated. |
| 8858 | */ |
| 8859 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8860 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8861 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8862 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8863 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8864 | + Binder.getCallingPid() |
| 8865 | + ", uid=" + Binder.getCallingUid() |
| 8866 | + "without permission " |
| 8867 | + android.Manifest.permission.DUMP); |
| 8868 | return; |
| 8869 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8870 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8871 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8872 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8873 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8874 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8875 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8876 | @NonNull String[] args) { |
| 8877 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8878 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8879 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8880 | } |
| 8881 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8882 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8883 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8884 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8885 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8886 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8887 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8888 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8889 | */ |
| 8890 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8891 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8892 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8893 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8894 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8895 | try { |
| 8896 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8897 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8898 | } catch (SecurityException se) { |
| 8899 | enforceModifyPermission(); |
| 8900 | } |
| 8901 | } else { |
| 8902 | enforceModifyPermission(); |
| 8903 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8904 | |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 8905 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 8906 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 8907 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(), |
| 8908 | callingPackage, null, null); |
| 8909 | } |
| 8910 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8911 | final long identity = Binder.clearCallingIdentity(); |
| 8912 | try { |
| 8913 | Phone phone = getPhone(subId); |
| 8914 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8915 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8916 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8917 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8918 | phone.getDataSettingsManager().setDataEnabled( |
| 8919 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8920 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8921 | } |
| 8922 | } finally { |
| 8923 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8924 | } |
| 8925 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8926 | |
| 8927 | /** |
| 8928 | * Get Client request stats |
| 8929 | * @return List of Client Request Stats |
| 8930 | * @hide |
| 8931 | */ |
| 8932 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8933 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8934 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8935 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8936 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8937 | return null; |
| 8938 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8939 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8940 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8941 | final long identity = Binder.clearCallingIdentity(); |
| 8942 | try { |
| 8943 | if (phone != null) { |
| 8944 | return phone.getClientRequestStats(); |
| 8945 | } |
| 8946 | |
| 8947 | return null; |
| 8948 | } finally { |
| 8949 | Binder.restoreCallingIdentity(identity); |
| 8950 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8951 | } |
| 8952 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8953 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8954 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8955 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8956 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8957 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8958 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8959 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8960 | // commands that plumb through the RIL as root, like so: |
| 8961 | // $ adb root |
| 8962 | // $ adb shell cmd phone ... |
| 8963 | packageName = "root"; |
| 8964 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8965 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8966 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8967 | |
| 8968 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8969 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8970 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8971 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8972 | * @param state State of SIM (power down, power up, pass through) |
| 8973 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8974 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8975 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8976 | * |
| 8977 | **/ |
| 8978 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8979 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8980 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8981 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8982 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8983 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8984 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8985 | final long identity = Binder.clearCallingIdentity(); |
| 8986 | try { |
| 8987 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8988 | phone.setSimPowerState(state, null, workSource); |
| 8989 | } |
| 8990 | } finally { |
| 8991 | Binder.restoreCallingIdentity(identity); |
| 8992 | } |
| 8993 | } |
| 8994 | |
| 8995 | /** |
| 8996 | * Set SIM card power state. |
| 8997 | * |
| 8998 | * @param slotIndex SIM slot id. |
| 8999 | * @param state State of SIM (power down, power up, pass through) |
| 9000 | * @param callback callback to trigger after success or failure |
| 9001 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9002 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9003 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9004 | * |
| 9005 | **/ |
| 9006 | @Override |
| 9007 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9008 | IIntegerConsumer callback) { |
| 9009 | enforceModifyPermission(); |
| 9010 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9011 | |
| 9012 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9013 | |
| 9014 | final long identity = Binder.clearCallingIdentity(); |
| 9015 | try { |
| 9016 | if (phone != null) { |
| 9017 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9018 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9019 | } |
| 9020 | } finally { |
| 9021 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9022 | } |
| 9023 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9024 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9025 | private boolean isUssdApiAllowed(int subId) { |
| 9026 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9027 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9028 | if (configManager == null) { |
| 9029 | return false; |
| 9030 | } |
| 9031 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9032 | if (pb == null) { |
| 9033 | return false; |
| 9034 | } |
| 9035 | return pb.getBoolean( |
| 9036 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9037 | } |
| 9038 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9039 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9040 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9041 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9042 | * @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] | 9043 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9044 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9045 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9046 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9047 | final long identity = Binder.clearCallingIdentity(); |
| 9048 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9049 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9050 | } finally { |
| 9051 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9052 | } |
| 9053 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9054 | |
| 9055 | /** |
| 9056 | * Get the current signal strength information for the given subscription. |
| 9057 | * Because this information is not updated when the device is in a low power state |
| 9058 | * it should not be relied-upon to be current. |
| 9059 | * @param subId Subscription index |
| 9060 | * @return the most recent cached signal strength info from the modem |
| 9061 | */ |
| 9062 | @Override |
| 9063 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9064 | final long identity = Binder.clearCallingIdentity(); |
| 9065 | try { |
| 9066 | Phone p = getPhone(subId); |
| 9067 | if (p == null) { |
| 9068 | return null; |
| 9069 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9071 | return p.getSignalStrength(); |
| 9072 | } finally { |
| 9073 | Binder.restoreCallingIdentity(identity); |
| 9074 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9075 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9076 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9077 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9078 | * Get the current modem radio state for the given slot. |
| 9079 | * @param slotIndex slot index. |
| 9080 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9081 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9082 | * @return the current radio power state from the modem |
| 9083 | */ |
| 9084 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9085 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9086 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9087 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9088 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9089 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9090 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9091 | } |
| 9092 | |
| 9093 | final long identity = Binder.clearCallingIdentity(); |
| 9094 | try { |
| 9095 | return phone.getRadioPowerState(); |
| 9096 | } finally { |
| 9097 | Binder.restoreCallingIdentity(identity); |
| 9098 | } |
| 9099 | } |
| 9100 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9101 | } |
| 9102 | |
| 9103 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9104 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9105 | * |
| 9106 | * <p>Requires one of the following permissions: |
| 9107 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9108 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9109 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9110 | * privileges. |
| 9111 | * |
| 9112 | * @param subId subscription id |
| 9113 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9114 | * {@code false}. |
| 9115 | */ |
| 9116 | @Override |
| 9117 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9118 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9119 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9120 | try { |
| 9121 | mApp.enforceCallingOrSelfPermission( |
| 9122 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9123 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9124 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9125 | mApp.enforceCallingOrSelfPermission( |
| 9126 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9127 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9128 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9129 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9130 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9131 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9132 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9133 | boolean isEnabled = false; |
| 9134 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9135 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9136 | Phone phone = getPhone(subId); |
| 9137 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9138 | } finally { |
| 9139 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9140 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9141 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9142 | } |
| 9143 | |
| 9144 | |
| 9145 | /** |
| 9146 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9147 | * |
| 9148 | * <p> Requires permission: |
| 9149 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9150 | * privileges. |
| 9151 | * |
| 9152 | * @param subId subscription id |
| 9153 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9154 | */ |
| 9155 | @Override |
| 9156 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9158 | mApp, subId, "setDataRoamingEnabled"); |
| 9159 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9160 | final long identity = Binder.clearCallingIdentity(); |
| 9161 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9162 | Phone phone = getPhone(subId); |
| 9163 | if (phone != null) { |
| 9164 | phone.setDataRoamingEnabled(isEnabled); |
| 9165 | } |
| 9166 | } finally { |
| 9167 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9168 | } |
| 9169 | } |
| 9170 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9171 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9172 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9173 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9174 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9175 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9176 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9177 | boolean isAllowed = true; |
| 9178 | final long identity = Binder.clearCallingIdentity(); |
| 9179 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9180 | Phone phone = getPhone(subId); |
| 9181 | if (phone != null) { |
| 9182 | isAllowed = phone.isCspPlmnEnabled(); |
| 9183 | } |
| 9184 | } finally { |
| 9185 | Binder.restoreCallingIdentity(identity); |
| 9186 | } |
| 9187 | return isAllowed; |
| 9188 | } |
| 9189 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9190 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9191 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9192 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9193 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9194 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9195 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9196 | if (phone == null) { |
| 9197 | return false; |
| 9198 | } |
| 9199 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9200 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9201 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9202 | } |
| 9203 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9204 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9205 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9206 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9207 | mApp.getSystemService(AppOpsManager.class) |
| 9208 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9209 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9210 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9211 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9212 | try { |
| 9213 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9214 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9215 | } catch (SecurityException e) { |
| 9216 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9217 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9218 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9219 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9220 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9221 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9222 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9223 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9224 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9225 | Binder.getCallingUid())) { |
| 9226 | isIccIdAccessRestricted = true; |
| 9227 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9228 | final long identity = Binder.clearCallingIdentity(); |
| 9229 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9230 | UiccController uiccController = UiccController.getInstance(); |
| 9231 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9232 | if (hasReadPermission) { |
| 9233 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9234 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9235 | |
| 9236 | // Remove private info if the caller doesn't have access |
| 9237 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9238 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9239 | //setting the value after compatibility check |
| 9240 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9241 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9242 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9243 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9244 | if (card == null) { |
| 9245 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9246 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9247 | continue; |
| 9248 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9249 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9250 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9251 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9252 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9253 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9254 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9255 | for (UiccPortInfo portInfo : portInfos) { |
| 9256 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9257 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9258 | if (port == null) { |
| 9259 | // assume no access if port is null |
| 9260 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9261 | continue; |
| 9262 | } |
| 9263 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9264 | uiccPortInfos.add(portInfo); |
| 9265 | } else { |
| 9266 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9267 | } |
| 9268 | } |
| 9269 | filteredInfos.add(new UiccCardInfo( |
| 9270 | cardInfo.isEuicc(), |
| 9271 | cardInfo.getCardId(), |
| 9272 | null, |
| 9273 | cardInfo.getPhysicalSlotIndex(), |
| 9274 | cardInfo.isRemovable(), |
| 9275 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9276 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9277 | } |
| 9278 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9279 | } finally { |
| 9280 | Binder.restoreCallingIdentity(identity); |
| 9281 | } |
| 9282 | } |
| 9283 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9284 | /** |
| 9285 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9286 | * generally private and require carrier privileges to view. |
| 9287 | * |
| 9288 | * @hide |
| 9289 | */ |
| 9290 | @NonNull |
| 9291 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9292 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9293 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9294 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9295 | } |
| 9296 | return new UiccCardInfo( |
| 9297 | cardInfo.isEuicc(), |
| 9298 | cardInfo.getCardId(), |
| 9299 | null, |
| 9300 | cardInfo.getPhysicalSlotIndex(), |
| 9301 | cardInfo.isRemovable(), |
| 9302 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9303 | portinfo |
| 9304 | ); |
| 9305 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9306 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9307 | /** |
| 9308 | * @hide |
| 9309 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9310 | * These values are generally private and require carrier privileges to view. |
| 9311 | */ |
| 9312 | @NonNull |
| 9313 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9314 | return new UiccPortInfo( |
| 9315 | UiccPortInfo.ICCID_REDACTED, |
| 9316 | portInfo.getPortIndex(), |
| 9317 | portInfo.getLogicalSlotIndex(), |
| 9318 | portInfo.isActive() |
| 9319 | ); |
| 9320 | } |
| 9321 | @Override |
| 9322 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9323 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9324 | mApp.getSystemService(AppOpsManager.class) |
| 9325 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9326 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9327 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9328 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9329 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9330 | // we are reading iccId which is PII data. |
| 9331 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9332 | |
| 9333 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9334 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9335 | Binder.getCallingUid())) { |
| 9336 | isLogicalSlotAccessRestricted = true; |
| 9337 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9338 | final long identity = Binder.clearCallingIdentity(); |
| 9339 | try { |
| 9340 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9341 | if (slots == null || slots.length == 0) { |
| 9342 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9343 | return null; |
| 9344 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9345 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9346 | for (int i = 0; i < slots.length; i++) { |
| 9347 | UiccSlot slot = slots[i]; |
| 9348 | if (slot == null) { |
| 9349 | continue; |
| 9350 | } |
| 9351 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9352 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9353 | UiccCard card = slot.getUiccCard(); |
| 9354 | if (card != null) { |
| 9355 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9356 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9357 | cardId = slot.getEid(); |
| 9358 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9359 | // If cardId is null, use iccId of default port as cardId. |
| 9360 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9361 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9362 | } |
| 9363 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9364 | if (cardId != null) { |
| 9365 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9366 | // if cardId is an EID, it's all digits so this is fine |
| 9367 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9368 | } |
| 9369 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9370 | int cardState = 0; |
| 9371 | switch (slot.getCardState()) { |
| 9372 | case CARDSTATE_ABSENT: |
| 9373 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9374 | break; |
| 9375 | case CARDSTATE_PRESENT: |
| 9376 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9377 | break; |
| 9378 | case CARDSTATE_ERROR: |
| 9379 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9380 | break; |
| 9381 | case CARDSTATE_RESTRICTED: |
| 9382 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9383 | break; |
| 9384 | default: |
| 9385 | break; |
| 9386 | |
| 9387 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9388 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9389 | int[] portIndexes = slot.getPortList(); |
| 9390 | for (int portIdx : portIndexes) { |
| 9391 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9392 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9393 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9394 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9395 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9396 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9397 | slot.isEuicc(), |
| 9398 | cardId, |
| 9399 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9400 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9401 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9402 | //setting the value after compatibility check |
| 9403 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9404 | } |
| 9405 | return infos; |
| 9406 | } finally { |
| 9407 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9408 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9409 | } |
| 9410 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9411 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9412 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9413 | boolean hasReadPermission) { |
| 9414 | String iccId = slot.getIccId(portIndex); |
| 9415 | if (hasReadPermission) { // if has read permission |
| 9416 | return iccId; |
| 9417 | } else { |
| 9418 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9419 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9420 | // if no read permission, checking carrier privilege access |
| 9421 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9422 | return iccId; |
| 9423 | } |
| 9424 | } |
| 9425 | } |
| 9426 | // No read permission or carrier privilege access. |
| 9427 | return UiccPortInfo.ICCID_REDACTED; |
| 9428 | } |
| 9429 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9430 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9431 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9432 | public boolean switchSlots(int[] physicalSlots) { |
| 9433 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9434 | |
| 9435 | final long identity = Binder.clearCallingIdentity(); |
| 9436 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9437 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9438 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9439 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9440 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9441 | physicalSlots[i], i)); |
| 9442 | } |
| 9443 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9444 | } finally { |
| 9445 | Binder.restoreCallingIdentity(identity); |
| 9446 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9447 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9448 | |
| 9449 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9450 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9451 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9452 | enforceModifyPermission(); |
| 9453 | |
| 9454 | final long identity = Binder.clearCallingIdentity(); |
| 9455 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9456 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9457 | } finally { |
| 9458 | Binder.restoreCallingIdentity(identity); |
| 9459 | } |
| 9460 | } |
| 9461 | |
| 9462 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9463 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9464 | final long identity = Binder.clearCallingIdentity(); |
| 9465 | try { |
| 9466 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9467 | } finally { |
| 9468 | Binder.restoreCallingIdentity(identity); |
| 9469 | } |
| 9470 | } |
| 9471 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9472 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9473 | * A test API to reload the UICC profile. |
| 9474 | * |
| 9475 | * <p>Requires that the calling app has permission |
| 9476 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9477 | * @hide |
| 9478 | */ |
| 9479 | @Override |
| 9480 | public void refreshUiccProfile(int subId) { |
| 9481 | enforceModifyPermission(); |
| 9482 | |
| 9483 | final long identity = Binder.clearCallingIdentity(); |
| 9484 | try { |
| 9485 | Phone phone = getPhone(subId); |
| 9486 | if (phone == null) { |
| 9487 | return; |
| 9488 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9489 | UiccPort uiccPort = phone.getUiccPort(); |
| 9490 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9491 | return; |
| 9492 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9493 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9494 | if (uiccProfile == null) { |
| 9495 | return; |
| 9496 | } |
| 9497 | uiccProfile.refresh(); |
| 9498 | } finally { |
| 9499 | Binder.restoreCallingIdentity(identity); |
| 9500 | } |
| 9501 | } |
| 9502 | |
| 9503 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9504 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9505 | */ |
| 9506 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9507 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9508 | } |
| 9509 | |
| 9510 | /** |
| 9511 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9512 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9513 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9514 | */ |
| 9515 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9516 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9517 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9518 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9519 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9520 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9521 | return isDataRoamingEnabled; |
| 9522 | } |
| 9523 | |
| 9524 | /** |
| 9525 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9526 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9527 | */ |
| 9528 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9529 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9530 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9531 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9532 | return list.get(phoneId); |
| 9533 | } |
| 9534 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9535 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9536 | |
| 9537 | @Override |
| 9538 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9539 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9540 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9541 | |
| 9542 | final long identity = Binder.clearCallingIdentity(); |
| 9543 | try { |
| 9544 | final Phone phone = getPhone(subId); |
| 9545 | if (phone == null) { |
| 9546 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9547 | return; |
| 9548 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9549 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9550 | if (cpt != null) { |
| 9551 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9552 | } |
| 9553 | // 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] | 9554 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9555 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9556 | if (carrierPrivilegeRules == null) { |
| 9557 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9558 | } else { |
| 9559 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9560 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9561 | } finally { |
| 9562 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9563 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9564 | } |
| 9565 | |
| 9566 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9567 | public void setCarrierServicePackageOverride( |
| 9568 | int subId, String carrierServicePackage, String callingPackage) { |
| 9569 | TelephonyPermissions.enforceShellOnly( |
| 9570 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9571 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9572 | final long identity = Binder.clearCallingIdentity(); |
| 9573 | try { |
| 9574 | final Phone phone = getPhone(subId); |
| 9575 | if (phone == null || phone.getSubId() != subId) { |
| 9576 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9577 | throw new IllegalArgumentException("No phone for subid"); |
| 9578 | } |
| 9579 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9580 | if (cpt == null) { |
| 9581 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9582 | throw new IllegalStateException("No CPT for phone"); |
| 9583 | } |
| 9584 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9585 | } finally { |
| 9586 | Binder.restoreCallingIdentity(identity); |
| 9587 | } |
| 9588 | } |
| 9589 | |
| 9590 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9591 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9592 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9593 | |
| 9594 | final long identity = Binder.clearCallingIdentity(); |
| 9595 | try { |
| 9596 | final Phone phone = getPhone(subId); |
| 9597 | if (phone == null) { |
| 9598 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9599 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9600 | } |
| 9601 | return phone.getCarrierIdListVersion(); |
| 9602 | } finally { |
| 9603 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9604 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9605 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9606 | |
| 9607 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9608 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9609 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9610 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9611 | mApp, subId, callingPackage, callingFeatureId, |
| 9612 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9613 | return -1; |
| 9614 | } |
| 9615 | |
| 9616 | final long identity = Binder.clearCallingIdentity(); |
| 9617 | try { |
| 9618 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9619 | } finally { |
| 9620 | Binder.restoreCallingIdentity(identity); |
| 9621 | } |
| 9622 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9623 | |
| 9624 | @Override |
| 9625 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9626 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9627 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9628 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9629 | |
| 9630 | final long identity = Binder.clearCallingIdentity(); |
| 9631 | try { |
| 9632 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9633 | } finally { |
| 9634 | Binder.restoreCallingIdentity(identity); |
| 9635 | } |
| 9636 | } |
| 9637 | |
| 9638 | @Override |
| 9639 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9641 | mApp, subId, "setCdmaRoamingMode"); |
| 9642 | |
| 9643 | final long identity = Binder.clearCallingIdentity(); |
| 9644 | try { |
| 9645 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9646 | } finally { |
| 9647 | Binder.restoreCallingIdentity(identity); |
| 9648 | } |
| 9649 | } |
| 9650 | |
| 9651 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9652 | public int getCdmaSubscriptionMode(int subId) { |
| 9653 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9654 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9655 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9656 | |
| 9657 | final long identity = Binder.clearCallingIdentity(); |
| 9658 | try { |
| 9659 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9660 | } finally { |
| 9661 | Binder.restoreCallingIdentity(identity); |
| 9662 | } |
| 9663 | } |
| 9664 | |
| 9665 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9666 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9667 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9668 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9669 | |
| 9670 | final long identity = Binder.clearCallingIdentity(); |
| 9671 | try { |
| 9672 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9673 | } finally { |
| 9674 | Binder.restoreCallingIdentity(identity); |
| 9675 | } |
| 9676 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9677 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9678 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9679 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9680 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9681 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9682 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9683 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9684 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9685 | } |
| 9686 | final long identity = Binder.clearCallingIdentity(); |
| 9687 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9688 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9689 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9690 | if (phone.getEmergencyNumberTracker() != null |
| 9691 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9692 | emergencyNumberListInternal.put( |
| 9693 | phone.getSubId(), |
| 9694 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9695 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9696 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9697 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9698 | } finally { |
| 9699 | Binder.restoreCallingIdentity(identity); |
| 9700 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9701 | } |
| 9702 | |
| 9703 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9704 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9705 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9706 | if (!exactMatch) { |
| 9707 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9708 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9709 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9710 | } |
| 9711 | final long identity = Binder.clearCallingIdentity(); |
| 9712 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9713 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9714 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9715 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9716 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9717 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9718 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9719 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9720 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9721 | } |
| 9722 | return false; |
| 9723 | } finally { |
| 9724 | Binder.restoreCallingIdentity(identity); |
| 9725 | } |
| 9726 | } |
| 9727 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9728 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9729 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9730 | */ |
| 9731 | @Override |
| 9732 | public void startEmergencyCallbackMode() { |
| 9733 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9734 | "startEmergencyCallbackMode"); |
| 9735 | enforceModifyPermission(); |
| 9736 | final long identity = Binder.clearCallingIdentity(); |
| 9737 | try { |
| 9738 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9739 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9740 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9741 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9742 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9743 | gsmCdmaPhone.obtainMessage( |
| 9744 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9745 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9746 | } |
| 9747 | } |
| 9748 | } finally { |
| 9749 | Binder.restoreCallingIdentity(identity); |
| 9750 | } |
| 9751 | } |
| 9752 | |
| 9753 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9754 | * Update emergency number list for test mode. |
| 9755 | */ |
| 9756 | @Override |
| 9757 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9758 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9759 | "updateEmergencyNumberListTestMode"); |
| 9760 | |
| 9761 | final long identity = Binder.clearCallingIdentity(); |
| 9762 | try { |
| 9763 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9764 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9765 | if (tracker != null) { |
| 9766 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9767 | } |
| 9768 | } |
| 9769 | } finally { |
| 9770 | Binder.restoreCallingIdentity(identity); |
| 9771 | } |
| 9772 | } |
| 9773 | |
| 9774 | /** |
| 9775 | * Get the full emergency number list for test mode. |
| 9776 | */ |
| 9777 | @Override |
| 9778 | public List<String> getEmergencyNumberListTestMode() { |
| 9779 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9780 | "getEmergencyNumberListTestMode"); |
| 9781 | |
| 9782 | final long identity = Binder.clearCallingIdentity(); |
| 9783 | try { |
| 9784 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9785 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9786 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9787 | if (tracker != null) { |
| 9788 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9789 | emergencyNumbers.add(num.getNumber()); |
| 9790 | } |
| 9791 | } |
| 9792 | } |
| 9793 | return new ArrayList<>(emergencyNumbers); |
| 9794 | } finally { |
| 9795 | Binder.restoreCallingIdentity(identity); |
| 9796 | } |
| 9797 | } |
| 9798 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9799 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9800 | public int getEmergencyNumberDbVersion(int subId) { |
| 9801 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9802 | |
| 9803 | final long identity = Binder.clearCallingIdentity(); |
| 9804 | try { |
| 9805 | final Phone phone = getPhone(subId); |
| 9806 | if (phone == null) { |
| 9807 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9808 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9809 | } |
| 9810 | return phone.getEmergencyNumberDbVersion(); |
| 9811 | } finally { |
| 9812 | Binder.restoreCallingIdentity(identity); |
| 9813 | } |
| 9814 | } |
| 9815 | |
| 9816 | @Override |
| 9817 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9818 | enforceModifyPermission(); |
| 9819 | |
| 9820 | final long identity = Binder.clearCallingIdentity(); |
| 9821 | try { |
| 9822 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9823 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9824 | if (tracker != null) { |
| 9825 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9826 | } |
| 9827 | } |
| 9828 | } finally { |
| 9829 | Binder.restoreCallingIdentity(identity); |
| 9830 | } |
| 9831 | } |
| 9832 | |
| 9833 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9834 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9835 | enforceActiveEmergencySessionPermission(); |
| 9836 | |
| 9837 | final long identity = Binder.clearCallingIdentity(); |
| 9838 | try { |
| 9839 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9840 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9841 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9842 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9843 | } |
| 9844 | } |
| 9845 | } finally { |
| 9846 | Binder.restoreCallingIdentity(identity); |
| 9847 | } |
| 9848 | } |
| 9849 | |
| 9850 | @Override |
| 9851 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9852 | enforceActiveEmergencySessionPermission(); |
| 9853 | |
| 9854 | final long identity = Binder.clearCallingIdentity(); |
| 9855 | try { |
| 9856 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9857 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9858 | if (tracker != null) { |
| 9859 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9860 | } |
| 9861 | } |
| 9862 | } finally { |
| 9863 | Binder.restoreCallingIdentity(identity); |
| 9864 | } |
| 9865 | } |
| 9866 | |
| 9867 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9868 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9869 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9870 | Phone phone = getPhone(subId); |
| 9871 | if (phone == null) { |
| 9872 | return null; |
| 9873 | } |
| 9874 | final long identity = Binder.clearCallingIdentity(); |
| 9875 | try { |
| 9876 | UiccProfile profile = UiccController.getInstance() |
| 9877 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9878 | if (profile != null) { |
| 9879 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9880 | } |
| 9881 | } finally { |
| 9882 | Binder.restoreCallingIdentity(identity); |
| 9883 | } |
| 9884 | return null; |
| 9885 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9886 | |
| 9887 | /** |
| 9888 | * Enable or disable a modem stack. |
| 9889 | */ |
| 9890 | @Override |
| 9891 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9892 | enforceModifyPermission(); |
| 9893 | |
| 9894 | final long identity = Binder.clearCallingIdentity(); |
| 9895 | try { |
| 9896 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9897 | if (phone == null) { |
| 9898 | return false; |
| 9899 | } else { |
| 9900 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9901 | } |
| 9902 | } finally { |
| 9903 | Binder.restoreCallingIdentity(identity); |
| 9904 | } |
| 9905 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9906 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9907 | /** |
| 9908 | * Whether a modem stack is enabled or not. |
| 9909 | */ |
| 9910 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9911 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9912 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9913 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9914 | if (phone == null) return false; |
| 9915 | |
| 9916 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9917 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9918 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9919 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9920 | } |
| 9921 | |
| 9922 | final long identity = Binder.clearCallingIdentity(); |
| 9923 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9924 | try { |
| 9925 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9926 | } catch (NoSuchElementException ex) { |
| 9927 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9928 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9929 | } finally { |
| 9930 | Binder.restoreCallingIdentity(identity); |
| 9931 | } |
| 9932 | } |
| 9933 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9934 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9935 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9936 | enforceModifyPermission(); |
| 9937 | |
| 9938 | final long identity = Binder.clearCallingIdentity(); |
| 9939 | try { |
| 9940 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9941 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9942 | .commit(); |
| 9943 | } finally { |
| 9944 | Binder.restoreCallingIdentity(identity); |
| 9945 | } |
| 9946 | } |
| 9947 | |
| 9948 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9949 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9950 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9951 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9952 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9953 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9954 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9955 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9956 | |
| 9957 | final long identity = Binder.clearCallingIdentity(); |
| 9958 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9959 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9960 | } finally { |
| 9961 | Binder.restoreCallingIdentity(identity); |
| 9962 | } |
| 9963 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9964 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9965 | @TelephonyManager.IsMultiSimSupportedResult |
| 9966 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9967 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9968 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9969 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9970 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9971 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9972 | } |
| 9973 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9974 | // supported by the modem, indicate that it is restricted. |
| 9975 | PhoneCapability staticCapability = |
| 9976 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9977 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9978 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9979 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9980 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9981 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9982 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9983 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9984 | } |
| 9985 | // Check if support of multiple SIMs is restricted by carrier |
| 9986 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9987 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9988 | } |
| 9989 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9990 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9991 | } |
| 9992 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9993 | /** |
| 9994 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9995 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9996 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9997 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9998 | * @param numOfSims number of active sims we want to switch to |
| 9999 | */ |
| 10000 | @Override |
| 10001 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10002 | if (numOfSims == 1) { |
| 10003 | enforceModifyPermission(); |
| 10004 | } else { |
| 10005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10006 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10007 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10008 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10009 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10010 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10011 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10012 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10013 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10014 | return; |
| 10015 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10016 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10017 | } finally { |
| 10018 | Binder.restoreCallingIdentity(identity); |
| 10019 | } |
| 10020 | } |
| 10021 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10022 | @Override |
| 10023 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10024 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10025 | Phone phone = getPhone(subId); |
| 10026 | if (phone == null) { |
| 10027 | return false; |
| 10028 | } |
| 10029 | final long identity = Binder.clearCallingIdentity(); |
| 10030 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10031 | UiccPort uiccPort = phone.getUiccPort(); |
| 10032 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10033 | return false; |
| 10034 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10035 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10036 | if (uiccProfile == null) { |
| 10037 | return false; |
| 10038 | } |
| 10039 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10040 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10041 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10042 | } |
| 10043 | return false; |
| 10044 | } finally { |
| 10045 | Binder.restoreCallingIdentity(identity); |
| 10046 | } |
| 10047 | } |
| 10048 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10049 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10050 | * Get whether making changes to modem configurations will trigger reboot. |
| 10051 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10052 | */ |
| 10053 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10054 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10055 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10056 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10057 | mApp, subId, callingPackage, callingFeatureId, |
| 10058 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10059 | return false; |
| 10060 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10061 | final long identity = Binder.clearCallingIdentity(); |
| 10062 | try { |
| 10063 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10064 | } finally { |
| 10065 | Binder.restoreCallingIdentity(identity); |
| 10066 | } |
| 10067 | } |
| 10068 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10069 | private void updateModemStateMetrics() { |
| 10070 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10071 | // TODO: check the state for each modem if the api is ready. |
| 10072 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10073 | } |
| 10074 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10075 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10076 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10077 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10078 | // Verify that the callingPackage belongs to the calling UID |
| 10079 | mApp.getSystemService(AppOpsManager.class) |
| 10080 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10081 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10082 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10083 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10084 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10085 | if (slotInfos != null) { |
| 10086 | for (int i = 0; i < slotInfos.length; i++) { |
| 10087 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10088 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10089 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10090 | portInfo.getLogicalSlotIndex())); |
| 10091 | } |
| 10092 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10093 | } |
| 10094 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10095 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10096 | } finally { |
| 10097 | Binder.restoreCallingIdentity(identity); |
| 10098 | } |
| 10099 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10100 | |
| 10101 | /** |
| 10102 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10103 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10104 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10105 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10106 | @Override |
| 10107 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10108 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10109 | } |
| 10110 | |
| 10111 | /** |
| 10112 | * Get the HAL Version of a specific service |
| 10113 | */ |
| 10114 | @Override |
| 10115 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10116 | Phone phone = getDefaultPhone(); |
| 10117 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10118 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10119 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10120 | return hv.major * 100 + hv.minor; |
| 10121 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10122 | |
| 10123 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10124 | * Get the current calling package name. |
| 10125 | * @return the current calling package name |
| 10126 | */ |
| 10127 | @Override |
| 10128 | public String getCurrentPackageName() { |
| 10129 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10130 | } |
| 10131 | |
| 10132 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10133 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10134 | * corresponding network requests on a subId. |
| 10135 | * |
| 10136 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10137 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10138 | * 2) APN is un-metered for this subscription, or |
| 10139 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10140 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10141 | * |
| 10142 | * @return whether data is allowed for a apn type. |
| 10143 | * |
| 10144 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10145 | */ |
| 10146 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10147 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10148 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10149 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10150 | |
| 10151 | // Now that all security checks passes, perform the operation as ourselves. |
| 10152 | final long identity = Binder.clearCallingIdentity(); |
| 10153 | try { |
| 10154 | Phone phone = getPhone(subId); |
| 10155 | if (phone == null) return false; |
| 10156 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10157 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10158 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10159 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10160 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10161 | phone.getServiceState().getDataRoaming()); |
| 10162 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10163 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10164 | } finally { |
| 10165 | Binder.restoreCallingIdentity(identity); |
| 10166 | } |
| 10167 | } |
| 10168 | |
| 10169 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10170 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10171 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10172 | |
| 10173 | // Now that all security checks passes, perform the operation as ourselves. |
| 10174 | final long identity = Binder.clearCallingIdentity(); |
| 10175 | try { |
| 10176 | Phone phone = getPhone(subId); |
| 10177 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10178 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10179 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10180 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10181 | } finally { |
| 10182 | Binder.restoreCallingIdentity(identity); |
| 10183 | } |
| 10184 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10185 | |
| 10186 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10187 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10188 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10189 | enforceModifyPermission(); |
| 10190 | long token = Binder.clearCallingIdentity(); |
| 10191 | try { |
| 10192 | Phone phone = getPhone(subscriptionId); |
| 10193 | if (phone == null) { |
| 10194 | try { |
| 10195 | if (resultCallback != null) { |
| 10196 | resultCallback.accept(false); |
| 10197 | } |
| 10198 | } catch (RemoteException e) { |
| 10199 | // ignore |
| 10200 | } |
| 10201 | return; |
| 10202 | } |
| 10203 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10204 | Pair.create(specifiers, (x) -> { |
| 10205 | try { |
| 10206 | if (resultCallback != null) { |
| 10207 | resultCallback.accept(x); |
| 10208 | } |
| 10209 | } catch (RemoteException e) { |
| 10210 | // ignore |
| 10211 | } |
| 10212 | }); |
| 10213 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10214 | } finally { |
| 10215 | Binder.restoreCallingIdentity(token); |
| 10216 | } |
| 10217 | } |
| 10218 | |
| 10219 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10220 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10221 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10222 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10223 | mApp, subId, "getSystemSelectionChannels"); |
| 10224 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10225 | final long identity = Binder.clearCallingIdentity(); |
| 10226 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10227 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10228 | if (result instanceof IllegalStateException) { |
| 10229 | throw (IllegalStateException) result; |
| 10230 | } |
| 10231 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10232 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10233 | return specifiers; |
| 10234 | } finally { |
| 10235 | Binder.restoreCallingIdentity(identity); |
| 10236 | } |
| 10237 | } |
| 10238 | |
| 10239 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10240 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10241 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10242 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10243 | } |
| 10244 | |
| 10245 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10246 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10247 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10248 | if (callingPackage == null) { |
| 10249 | callingPackage = getCurrentPackageName(); |
| 10250 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10251 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10252 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10253 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10254 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10255 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10256 | } |
| 10257 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10258 | Intent intent = new Intent(); |
| 10259 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10260 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10261 | // Bring up choose default SMS subscription dialog right now |
| 10262 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10263 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10264 | mApp.startActivity(intent); |
| 10265 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10266 | |
| 10267 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10268 | public void showSwitchToManagedProfileDialog() { |
| 10269 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10270 | try { |
| 10271 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10272 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10273 | // for work telephony. |
| 10274 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10275 | intent.setData(Uri.parse("smsto:")); |
| 10276 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10277 | mApp.startActivity(intent); |
| 10278 | } catch (ActivityNotFoundException e) { |
| 10279 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10280 | Intent intent = new Intent(); |
| 10281 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10282 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10283 | mApp.startActivity(intent); |
| 10284 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10285 | } |
| 10286 | |
| 10287 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10288 | public String getMmsUAProfUrl(int subId) { |
| 10289 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10290 | final long identity = Binder.clearCallingIdentity(); |
| 10291 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10292 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10293 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10294 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10295 | return carrierUAProfUrl; |
| 10296 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10297 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10298 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10299 | } finally { |
| 10300 | Binder.restoreCallingIdentity(identity); |
| 10301 | } |
| 10302 | } |
| 10303 | |
| 10304 | @Override |
| 10305 | public String getMmsUserAgent(int subId) { |
| 10306 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10307 | final long identity = Binder.clearCallingIdentity(); |
| 10308 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10309 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10310 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10311 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10312 | return carrierUserAgent; |
| 10313 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10314 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10315 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10316 | } finally { |
| 10317 | Binder.restoreCallingIdentity(identity); |
| 10318 | } |
| 10319 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10320 | |
| 10321 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10322 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10323 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10324 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10325 | final long identity = Binder.clearCallingIdentity(); |
| 10326 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10327 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10328 | if (phone == null) return false; |
| 10329 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10330 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10331 | } finally { |
| 10332 | Binder.restoreCallingIdentity(identity); |
| 10333 | } |
| 10334 | } |
| 10335 | |
| 10336 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10337 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10338 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10339 | enforceModifyPermission(); |
| 10340 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10341 | final long identity = Binder.clearCallingIdentity(); |
| 10342 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10343 | Phone phone = getPhone(subscriptionId); |
| 10344 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10345 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10346 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10347 | } finally { |
| 10348 | Binder.restoreCallingIdentity(identity); |
| 10349 | } |
| 10350 | } |
| 10351 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10352 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10353 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10354 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10355 | * otherwise. |
| 10356 | */ |
| 10357 | @Override |
| 10358 | public void setCepEnabled(boolean isCepEnabled) { |
| 10359 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10360 | |
| 10361 | final long identity = Binder.clearCallingIdentity(); |
| 10362 | try { |
| 10363 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10364 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10365 | Phone defaultPhone = phone.getImsPhone(); |
| 10366 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10367 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10368 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10369 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10370 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10371 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10372 | + imsPhone.getMsisdn()); |
| 10373 | } |
| 10374 | } |
| 10375 | } finally { |
| 10376 | Binder.restoreCallingIdentity(identity); |
| 10377 | } |
| 10378 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10379 | |
| 10380 | /** |
| 10381 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10382 | * |
| 10383 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10384 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10385 | * before being read. |
| 10386 | */ |
| 10387 | @Override |
| 10388 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10389 | isCompressed) { |
| 10390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10391 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10392 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10393 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10394 | } |
| 10395 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10396 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10397 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10398 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10399 | } |
| 10400 | |
| 10401 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10402 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10403 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10404 | } finally { |
| 10405 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10406 | } |
| 10407 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10408 | |
| 10409 | @Override |
| 10410 | public boolean isIccLockEnabled(int subId) { |
| 10411 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10412 | |
| 10413 | // Now that all security checks passes, perform the operation as ourselves. |
| 10414 | final long identity = Binder.clearCallingIdentity(); |
| 10415 | try { |
| 10416 | Phone phone = getPhone(subId); |
| 10417 | if (phone != null && phone.getIccCard() != null) { |
| 10418 | return phone.getIccCard().getIccLockEnabled(); |
| 10419 | } else { |
| 10420 | return false; |
| 10421 | } |
| 10422 | } finally { |
| 10423 | Binder.restoreCallingIdentity(identity); |
| 10424 | } |
| 10425 | } |
| 10426 | |
| 10427 | /** |
| 10428 | * Set the ICC pin lock enabled or disabled. |
| 10429 | * |
| 10430 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10431 | * three cases: |
| 10432 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10433 | * successfully. |
| 10434 | * - Positive number and zero for remaining password attempts. |
| 10435 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10436 | * |
| 10437 | */ |
| 10438 | @Override |
| 10439 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10440 | enforceModifyPermission(); |
| 10441 | |
| 10442 | Phone phone = getPhone(subId); |
| 10443 | if (phone == null) { |
| 10444 | return 0; |
| 10445 | } |
| 10446 | // Now that all security checks passes, perform the operation as ourselves. |
| 10447 | final long identity = Binder.clearCallingIdentity(); |
| 10448 | try { |
| 10449 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10450 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10451 | return attemptsRemaining; |
| 10452 | |
| 10453 | } catch (Exception e) { |
| 10454 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10455 | } finally { |
| 10456 | Binder.restoreCallingIdentity(identity); |
| 10457 | } |
| 10458 | return 0; |
| 10459 | } |
| 10460 | |
| 10461 | /** |
| 10462 | * Change the ICC password used in ICC pin lock. |
| 10463 | * |
| 10464 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10465 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10466 | * - Positive number and zero for remaining password attempts. |
| 10467 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10468 | * |
| 10469 | */ |
| 10470 | @Override |
| 10471 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10472 | enforceModifyPermission(); |
| 10473 | |
| 10474 | Phone phone = getPhone(subId); |
| 10475 | if (phone == null) { |
| 10476 | return 0; |
| 10477 | } |
| 10478 | // Now that all security checks passes, perform the operation as ourselves. |
| 10479 | final long identity = Binder.clearCallingIdentity(); |
| 10480 | try { |
| 10481 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10482 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10483 | return attemptsRemaining; |
| 10484 | |
| 10485 | } catch (Exception e) { |
| 10486 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10487 | } finally { |
| 10488 | Binder.restoreCallingIdentity(identity); |
| 10489 | } |
| 10490 | return 0; |
| 10491 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10492 | |
| 10493 | /** |
| 10494 | * Request for receiving user activity notification |
| 10495 | */ |
| 10496 | @Override |
| 10497 | public void requestUserActivityNotification() { |
| 10498 | if (!mNotifyUserActivity.get() |
| 10499 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10500 | mNotifyUserActivity.set(true); |
| 10501 | } |
| 10502 | } |
| 10503 | |
| 10504 | /** |
| 10505 | * Called when userActivity is signalled in the power manager. |
| 10506 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10507 | */ |
| 10508 | @Override |
| 10509 | public void userActivity() { |
| 10510 | // *************************************** |
| 10511 | // * Inherited from PhoneWindowManager * |
| 10512 | // *************************************** |
| 10513 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10514 | // WITH ITS LOCKS HELD. |
| 10515 | // |
| 10516 | // This code must be VERY careful about the locks |
| 10517 | // it acquires. |
| 10518 | // In fact, the current code acquires way too many, |
| 10519 | // and probably has lurking deadlocks. |
| 10520 | |
| 10521 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10522 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10523 | } |
| 10524 | |
| 10525 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10526 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10527 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10528 | } |
| 10529 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10530 | |
| 10531 | @Override |
| 10532 | public boolean canConnectTo5GInDsdsMode() { |
| 10533 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10534 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10535 | |
| 10536 | @Override |
| 10537 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10538 | String callingFeatureId) { |
| 10539 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10540 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10541 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10542 | } |
| 10543 | |
| 10544 | Phone phone = getPhone(subId); |
| 10545 | if (phone == null) { |
| 10546 | throw new RuntimeException("phone is not available"); |
| 10547 | } |
| 10548 | // Now that all security checks passes, perform the operation as ourselves. |
| 10549 | final long identity = Binder.clearCallingIdentity(); |
| 10550 | try { |
| 10551 | return phone.getEquivalentHomePlmns(); |
| 10552 | } finally { |
| 10553 | Binder.restoreCallingIdentity(identity); |
| 10554 | } |
| 10555 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10556 | |
| 10557 | @Override |
| 10558 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10559 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10560 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10561 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10562 | if (radioInterfaceCapabilities == null) { |
| 10563 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10564 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10565 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10566 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10567 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10568 | @Override |
| 10569 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10570 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10571 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10572 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10573 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10574 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10575 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10576 | if (DBG) { |
| 10577 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10578 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10579 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10580 | } |
| 10581 | |
| 10582 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10583 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10584 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10585 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10586 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10587 | if (callback != null) { |
| 10588 | try { |
| 10589 | callback.onAuthenticationFailure( |
| 10590 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10591 | } catch (RemoteException exception) { |
| 10592 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10593 | } |
| 10594 | return; |
| 10595 | } |
| 10596 | } |
| 10597 | |
| 10598 | final long token = Binder.clearCallingIdentity(); |
| 10599 | try { |
| 10600 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10601 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10602 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10603 | } finally { |
| 10604 | Binder.restoreCallingIdentity(token); |
| 10605 | } |
| 10606 | } |
| 10607 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10608 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10609 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10610 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10611 | * requested radio power state will actually be set. See {@link |
| 10612 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10613 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10614 | * @param enable {@code true} if trying to turn radio on. |
| 10615 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10616 | * false}. |
| 10617 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10618 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10619 | boolean isPhoneAvailable = false; |
| 10620 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10621 | Phone phone = PhoneFactory.getPhone(i); |
| 10622 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10623 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10624 | isPhoneAvailable = true; |
| 10625 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10626 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10627 | |
| 10628 | // return true if successfully informed the phone object about the thermal radio power |
| 10629 | // request. |
| 10630 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10631 | } |
| 10632 | |
| 10633 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10634 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10635 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10636 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10637 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10638 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10639 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10640 | } |
| 10641 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10642 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10643 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10644 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10645 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10646 | } |
| 10647 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10648 | setDataEnabledForReason( |
| 10649 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10650 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10651 | if (isDataThrottlingSupported) { |
| 10652 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10653 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10654 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10655 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10656 | } else if (thermalMitigationResult |
| 10657 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10658 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10659 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10660 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10661 | } |
| 10662 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10663 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10664 | |
| 10665 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10666 | } |
| 10667 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10668 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10669 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10670 | for (String pckg : context.getResources() |
| 10671 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10672 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10673 | } |
| 10674 | } |
| 10675 | |
| 10676 | return sThermalMitigationAllowlistedPackages; |
| 10677 | } |
| 10678 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10679 | private boolean isAnyPhoneInEmergencyState() { |
| 10680 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10681 | if (tm.isInEmergencyCall()) { |
| 10682 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10683 | return true; |
| 10684 | } |
| 10685 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10686 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10687 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10688 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10689 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10690 | return true; |
| 10691 | } |
| 10692 | } |
| 10693 | |
| 10694 | return false; |
| 10695 | } |
| 10696 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10697 | /** |
| 10698 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10699 | * @param packageName name of package to be allowlisted |
| 10700 | * @param context |
| 10701 | */ |
| 10702 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10703 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10704 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10705 | } |
| 10706 | |
| 10707 | /** |
| 10708 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10709 | * @param packageName name of package to remove from allowlist |
| 10710 | * @param context |
| 10711 | */ |
| 10712 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10713 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10714 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10715 | } |
| 10716 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10717 | /** |
| 10718 | * Thermal mitigation request to control functionalities at modem. |
| 10719 | * |
| 10720 | * @param subId the id of the subscription. |
| 10721 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10722 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10723 | * |
| 10724 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10725 | */ |
| 10726 | @Override |
| 10727 | @ThermalMitigationResult |
| 10728 | public int sendThermalMitigationRequest( |
| 10729 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10730 | ThermalMitigationRequest thermalMitigationRequest, |
| 10731 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10732 | enforceModifyPermission(); |
| 10733 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10734 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10735 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10736 | .contains(callingPackage)) { |
| 10737 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10738 | + "calling package: " + callingPackage); |
| 10739 | } |
| 10740 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10741 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10742 | final long identity = Binder.clearCallingIdentity(); |
| 10743 | |
| 10744 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10745 | try { |
| 10746 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10747 | switch (thermalMitigationAction) { |
| 10748 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10749 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10750 | handleDataThrottlingRequest(subId, |
| 10751 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10752 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10753 | break; |
| 10754 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10755 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10756 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10757 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10758 | } |
| 10759 | |
| 10760 | // Ensure that radio is on. If not able to power on due to phone being |
| 10761 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10762 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10763 | thermalMitigationResult = |
| 10764 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10765 | break; |
| 10766 | } |
| 10767 | |
| 10768 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10769 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10770 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10771 | break; |
| 10772 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10773 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10774 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10775 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10776 | } |
| 10777 | |
| 10778 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10779 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10780 | Phone phone = getPhone(subId); |
| 10781 | if (phone == null) { |
| 10782 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10783 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10784 | break; |
| 10785 | } |
| 10786 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10787 | TelephonyConnectionService service = |
| 10788 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10789 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10790 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10791 | thermalMitigationResult = |
| 10792 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10793 | break; |
| 10794 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10795 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10796 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10797 | break; |
| 10798 | } |
| 10799 | } else { |
| 10800 | thermalMitigationResult = |
| 10801 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10802 | break; |
| 10803 | } |
| 10804 | |
| 10805 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10806 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10807 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10808 | thermalMitigationResult = |
| 10809 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10810 | break; |
| 10811 | } |
| 10812 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10813 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10814 | break; |
| 10815 | default: |
| 10816 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10817 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10818 | } |
| 10819 | } catch (IllegalArgumentException e) { |
| 10820 | throw e; |
| 10821 | } catch (Exception e) { |
| 10822 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10823 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10824 | } finally { |
| 10825 | Binder.restoreCallingIdentity(identity); |
| 10826 | } |
| 10827 | |
| 10828 | if (DBG) { |
| 10829 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10830 | + thermalMitigationResult); |
| 10831 | } |
| 10832 | |
| 10833 | return thermalMitigationResult; |
| 10834 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10835 | |
| 10836 | /** |
| 10837 | * Set the GbaService Package Name that Telephony will bind to. |
| 10838 | * |
| 10839 | * @param subId The sim that the GbaService is associated with. |
| 10840 | * @param packageName The name of the package to be replaced with. |
| 10841 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10842 | */ |
| 10843 | @Override |
| 10844 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10845 | enforceModifyPermission(); |
| 10846 | |
| 10847 | final long identity = Binder.clearCallingIdentity(); |
| 10848 | try { |
| 10849 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10850 | } finally { |
| 10851 | Binder.restoreCallingIdentity(identity); |
| 10852 | } |
| 10853 | } |
| 10854 | |
| 10855 | /** |
| 10856 | * Return the package name of the currently bound GbaService. |
| 10857 | * |
| 10858 | * @param subId The sim that the GbaService is associated with. |
| 10859 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10860 | */ |
| 10861 | @Override |
| 10862 | public String getBoundGbaService(int subId) { |
| 10863 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10864 | |
| 10865 | final long identity = Binder.clearCallingIdentity(); |
| 10866 | try { |
| 10867 | return getGbaManager(subId).getServicePackage(); |
| 10868 | } finally { |
| 10869 | Binder.restoreCallingIdentity(identity); |
| 10870 | } |
| 10871 | } |
| 10872 | |
| 10873 | /** |
| 10874 | * Set the release time for telephony to unbind GbaService. |
| 10875 | * |
| 10876 | * @param subId The sim that the GbaService is associated with. |
| 10877 | * @param interval The release time to unbind GbaService by millisecond. |
| 10878 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10879 | */ |
| 10880 | @Override |
| 10881 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10882 | enforceModifyPermission(); |
| 10883 | |
| 10884 | final long identity = Binder.clearCallingIdentity(); |
| 10885 | try { |
| 10886 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10887 | } finally { |
| 10888 | Binder.restoreCallingIdentity(identity); |
| 10889 | } |
| 10890 | } |
| 10891 | |
| 10892 | /** |
| 10893 | * Return the release time for telephony to unbind GbaService. |
| 10894 | * |
| 10895 | * @param subId The sim that the GbaService is associated with. |
| 10896 | * @return The release time to unbind GbaService by millisecond. |
| 10897 | */ |
| 10898 | @Override |
| 10899 | public int getGbaReleaseTime(int subId) { |
| 10900 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10901 | |
| 10902 | final long identity = Binder.clearCallingIdentity(); |
| 10903 | try { |
| 10904 | return getGbaManager(subId).getReleaseTime(); |
| 10905 | } finally { |
| 10906 | Binder.restoreCallingIdentity(identity); |
| 10907 | } |
| 10908 | } |
| 10909 | |
| 10910 | private GbaManager getGbaManager(int subId) { |
| 10911 | GbaManager instance = GbaManager.getInstance(subId); |
| 10912 | if (instance == null) { |
| 10913 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10914 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10915 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10916 | } |
| 10917 | return instance; |
| 10918 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10919 | |
| 10920 | /** |
| 10921 | * indicate whether the device and the carrier can support |
| 10922 | * RCS VoLTE single registration. |
| 10923 | */ |
| 10924 | @Override |
| 10925 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10926 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10927 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10928 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10929 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10930 | |
| 10931 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10932 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10933 | } |
| 10934 | |
| 10935 | final long identity = Binder.clearCallingIdentity(); |
| 10936 | try { |
| 10937 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10938 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10939 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10940 | if (isCapable != null) { |
| 10941 | return isCapable; |
| 10942 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10943 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10944 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10945 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10946 | } finally { |
| 10947 | Binder.restoreCallingIdentity(identity); |
| 10948 | } |
| 10949 | } |
| 10950 | |
| 10951 | /** |
| 10952 | * Register RCS provisioning callback. |
| 10953 | */ |
| 10954 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10955 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10956 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10957 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10958 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10959 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10960 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10961 | |
| 10962 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10963 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10964 | } |
| 10965 | if (!isImsAvailableOnDevice()) { |
| 10966 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10967 | "IMS not available on device."); |
| 10968 | } |
| 10969 | |
| 10970 | final long identity = Binder.clearCallingIdentity(); |
| 10971 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10972 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10973 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10974 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10975 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10976 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10977 | } finally { |
| 10978 | Binder.restoreCallingIdentity(identity); |
| 10979 | } |
| 10980 | } |
| 10981 | |
| 10982 | /** |
| 10983 | * Unregister RCS provisioning callback. |
| 10984 | */ |
| 10985 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10986 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10987 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10988 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10989 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10990 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10991 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10992 | |
| 10993 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10994 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10995 | } |
| 10996 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10997 | // operation failed silently |
| 10998 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10999 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11000 | } |
| 11001 | |
| 11002 | final long identity = Binder.clearCallingIdentity(); |
| 11003 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11004 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11005 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11006 | } finally { |
| 11007 | Binder.restoreCallingIdentity(identity); |
| 11008 | } |
| 11009 | } |
| 11010 | |
| 11011 | /** |
| 11012 | * trigger RCS reconfiguration. |
| 11013 | */ |
| 11014 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11015 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11016 | "triggerRcsReconfiguration", |
| 11017 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11018 | |
| 11019 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11020 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11021 | } |
| 11022 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11023 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11024 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11025 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11026 | } |
| 11027 | |
| 11028 | final long identity = Binder.clearCallingIdentity(); |
| 11029 | try { |
| 11030 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11031 | } finally { |
| 11032 | Binder.restoreCallingIdentity(identity); |
| 11033 | } |
| 11034 | } |
| 11035 | |
| 11036 | /** |
| 11037 | * Provide the client configuration parameters of the RCS application. |
| 11038 | */ |
| 11039 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11040 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11041 | "setRcsClientConfiguration", |
| 11042 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11043 | |
| 11044 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11045 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11046 | } |
| 11047 | if (!isImsAvailableOnDevice()) { |
| 11048 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11049 | "IMS not available on device."); |
| 11050 | } |
| 11051 | |
| 11052 | final long identity = Binder.clearCallingIdentity(); |
| 11053 | |
| 11054 | try { |
| 11055 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11056 | if (configBinder == null) { |
| 11057 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11058 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11059 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11060 | } else { |
| 11061 | configBinder.setRcsClientConfiguration(rcc); |
| 11062 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11063 | |
| 11064 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11065 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11066 | } catch (RemoteException e) { |
| 11067 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11068 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11069 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11070 | } finally { |
| 11071 | Binder.restoreCallingIdentity(identity); |
| 11072 | } |
| 11073 | } |
| 11074 | |
| 11075 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11076 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11077 | */ |
| 11078 | @Override |
| 11079 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11080 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11081 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11082 | |
| 11083 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11084 | } |
| 11085 | |
| 11086 | /** |
| 11087 | * Gets the test mode for RCS VoLTE single registration. |
| 11088 | */ |
| 11089 | @Override |
| 11090 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11091 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11092 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11093 | |
| 11094 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11095 | } |
| 11096 | |
| 11097 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11098 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11099 | */ |
| 11100 | @Override |
| 11101 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11102 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11103 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11104 | enforceModifyPermission(); |
| 11105 | |
| 11106 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11107 | : Boolean.parseBoolean(enabledStr); |
| 11108 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11109 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11110 | } |
| 11111 | |
| 11112 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11113 | * Sends a device to device communication message. Only usable via shell. |
| 11114 | * @param message message to send. |
| 11115 | * @param value message value. |
| 11116 | */ |
| 11117 | @Override |
| 11118 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11119 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11120 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11121 | enforceModifyPermission(); |
| 11122 | |
| 11123 | final long identity = Binder.clearCallingIdentity(); |
| 11124 | try { |
| 11125 | TelephonyConnectionService service = |
| 11126 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11127 | if (service == null) { |
| 11128 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11129 | return; |
| 11130 | } |
| 11131 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11132 | } finally { |
| 11133 | Binder.restoreCallingIdentity(identity); |
| 11134 | } |
| 11135 | } |
| 11136 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11137 | /** |
| 11138 | * Sets the specified device to device transport active. |
| 11139 | * @param transport The transport to set active. |
| 11140 | */ |
| 11141 | @Override |
| 11142 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11143 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11144 | "setActiveDeviceToDeviceTransport"); |
| 11145 | enforceModifyPermission(); |
| 11146 | |
| 11147 | final long identity = Binder.clearCallingIdentity(); |
| 11148 | try { |
| 11149 | TelephonyConnectionService service = |
| 11150 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11151 | if (service == null) { |
| 11152 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11153 | return; |
| 11154 | } |
| 11155 | service.setActiveDeviceToDeviceTransport(transport); |
| 11156 | } finally { |
| 11157 | Binder.restoreCallingIdentity(identity); |
| 11158 | } |
| 11159 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11160 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11161 | @Override |
| 11162 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11163 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11164 | "setDeviceToDeviceForceEnabled"); |
| 11165 | |
| 11166 | final long identity = Binder.clearCallingIdentity(); |
| 11167 | try { |
| 11168 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11169 | p -> { |
| 11170 | Phone thePhone = p.getImsPhone(); |
| 11171 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11172 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11173 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11174 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11175 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11176 | (ImsPhoneCallTracker) tracker; |
| 11177 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11178 | } |
| 11179 | } |
| 11180 | } |
| 11181 | ); |
| 11182 | } finally { |
| 11183 | Binder.restoreCallingIdentity(identity); |
| 11184 | } |
| 11185 | } |
| 11186 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11187 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11188 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11189 | */ |
| 11190 | @Override |
| 11191 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11192 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11193 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11194 | } |
| 11195 | |
| 11196 | /** |
| 11197 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11198 | */ |
| 11199 | @Override |
| 11200 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11201 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11202 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11203 | enforceModifyPermission(); |
| 11204 | |
| 11205 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11206 | : Boolean.parseBoolean(enabledStr); |
| 11207 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11208 | subId, enabled); |
| 11209 | } |
| 11210 | |
| 11211 | /** |
| 11212 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11213 | */ |
| 11214 | @Override |
| 11215 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11216 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11217 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11218 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11219 | |
| 11220 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11221 | * Overrides the ims feature validation result |
| 11222 | */ |
| 11223 | @Override |
| 11224 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11225 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11226 | "setImsFeatureValidationOverride"); |
| 11227 | |
| 11228 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11229 | : Boolean.parseBoolean(enabledStr); |
| 11230 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11231 | subId, enabled); |
| 11232 | } |
| 11233 | |
| 11234 | /** |
| 11235 | * Gets the ims feature validation override value |
| 11236 | */ |
| 11237 | @Override |
| 11238 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11239 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11240 | "getImsFeatureValidationOverride"); |
| 11241 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11242 | } |
| 11243 | |
| 11244 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11245 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11246 | * their mobile plan. |
| 11247 | */ |
| 11248 | @Override |
| 11249 | public String getMobileProvisioningUrl() { |
| 11250 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11251 | final long identity = Binder.clearCallingIdentity(); |
| 11252 | try { |
| 11253 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11254 | } finally { |
| 11255 | Binder.restoreCallingIdentity(identity); |
| 11256 | } |
| 11257 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11258 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11259 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11260 | * Get the EAB contact from the EAB database. |
| 11261 | */ |
| 11262 | @Override |
| 11263 | public String getContactFromEab(String contact) { |
| 11264 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11265 | enforceModifyPermission(); |
| 11266 | final long identity = Binder.clearCallingIdentity(); |
| 11267 | try { |
| 11268 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11269 | } finally { |
| 11270 | Binder.restoreCallingIdentity(identity); |
| 11271 | } |
| 11272 | } |
| 11273 | |
| 11274 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11275 | * Get the EAB capability from the EAB database. |
| 11276 | */ |
| 11277 | @Override |
| 11278 | public String getCapabilityFromEab(String contact) { |
| 11279 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11280 | enforceModifyPermission(); |
| 11281 | final long identity = Binder.clearCallingIdentity(); |
| 11282 | try { |
| 11283 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11284 | } finally { |
| 11285 | Binder.restoreCallingIdentity(identity); |
| 11286 | } |
| 11287 | } |
| 11288 | |
| 11289 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11290 | * Remove the EAB contacts from the EAB database. |
| 11291 | */ |
| 11292 | @Override |
| 11293 | public int removeContactFromEab(int subId, String contacts) { |
| 11294 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11295 | enforceModifyPermission(); |
| 11296 | final long identity = Binder.clearCallingIdentity(); |
| 11297 | try { |
| 11298 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11299 | } finally { |
| 11300 | Binder.restoreCallingIdentity(identity); |
| 11301 | } |
| 11302 | } |
| 11303 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11304 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11305 | public boolean getDeviceUceEnabled() { |
| 11306 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11307 | final long identity = Binder.clearCallingIdentity(); |
| 11308 | try { |
| 11309 | return mApp.getDeviceUceEnabled(); |
| 11310 | } finally { |
| 11311 | Binder.restoreCallingIdentity(identity); |
| 11312 | } |
| 11313 | } |
| 11314 | |
| 11315 | @Override |
| 11316 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11317 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11318 | final long identity = Binder.clearCallingIdentity(); |
| 11319 | try { |
| 11320 | mApp.setDeviceUceEnabled(isEnabled); |
| 11321 | } finally { |
| 11322 | Binder.restoreCallingIdentity(identity); |
| 11323 | } |
| 11324 | } |
| 11325 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11326 | /** |
| 11327 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11328 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11329 | */ |
| 11330 | // Used for SHELL command only right now. |
| 11331 | @Override |
| 11332 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11333 | List<String> featureTags) { |
| 11334 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11335 | "addUceRegistrationOverrideShell"); |
| 11336 | final long identity = Binder.clearCallingIdentity(); |
| 11337 | try { |
| 11338 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11339 | new ArraySet<>(featureTags)); |
| 11340 | } catch (ImsException e) { |
| 11341 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11342 | } finally { |
| 11343 | Binder.restoreCallingIdentity(identity); |
| 11344 | } |
| 11345 | } |
| 11346 | |
| 11347 | /** |
| 11348 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11349 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11350 | */ |
| 11351 | // Used for SHELL command only right now. |
| 11352 | @Override |
| 11353 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11354 | List<String> featureTags) { |
| 11355 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11356 | "removeUceRegistrationOverrideShell"); |
| 11357 | final long identity = Binder.clearCallingIdentity(); |
| 11358 | try { |
| 11359 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11360 | new ArraySet<>(featureTags)); |
| 11361 | } catch (ImsException e) { |
| 11362 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11363 | } finally { |
| 11364 | Binder.restoreCallingIdentity(identity); |
| 11365 | } |
| 11366 | } |
| 11367 | |
| 11368 | /** |
| 11369 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11370 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11371 | */ |
| 11372 | // Used for SHELL command only right now. |
| 11373 | @Override |
| 11374 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11375 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11376 | "clearUceRegistrationOverrideShell"); |
| 11377 | final long identity = Binder.clearCallingIdentity(); |
| 11378 | try { |
| 11379 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11380 | } catch (ImsException e) { |
| 11381 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11382 | } finally { |
| 11383 | Binder.restoreCallingIdentity(identity); |
| 11384 | } |
| 11385 | } |
| 11386 | |
| 11387 | /** |
| 11388 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11389 | */ |
| 11390 | // Used for SHELL command only right now. |
| 11391 | @Override |
| 11392 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11393 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11394 | "getLatestRcsContactUceCapabilityShell"); |
| 11395 | final long identity = Binder.clearCallingIdentity(); |
| 11396 | try { |
| 11397 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11398 | } catch (ImsException e) { |
| 11399 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11400 | } finally { |
| 11401 | Binder.restoreCallingIdentity(identity); |
| 11402 | } |
| 11403 | } |
| 11404 | |
| 11405 | /** |
| 11406 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11407 | * device does not have an active PUBLISH. |
| 11408 | */ |
| 11409 | // Used for SHELL command only right now. |
| 11410 | @Override |
| 11411 | public String getLastUcePidfXmlShell(int subId) { |
| 11412 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11413 | final long identity = Binder.clearCallingIdentity(); |
| 11414 | try { |
| 11415 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11416 | } catch (ImsException e) { |
| 11417 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11418 | } finally { |
| 11419 | Binder.restoreCallingIdentity(identity); |
| 11420 | } |
| 11421 | } |
| 11422 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11423 | /** |
| 11424 | * Remove UCE requests cannot be sent to the network status. |
| 11425 | */ |
| 11426 | // Used for SHELL command only right now. |
| 11427 | @Override |
| 11428 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11429 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11430 | final long identity = Binder.clearCallingIdentity(); |
| 11431 | try { |
| 11432 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11433 | } catch (ImsException e) { |
| 11434 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11435 | } finally { |
| 11436 | Binder.restoreCallingIdentity(identity); |
| 11437 | } |
| 11438 | } |
| 11439 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11440 | /** |
| 11441 | * Remove UCE requests cannot be sent to the network status. |
| 11442 | */ |
| 11443 | // Used for SHELL command only. |
| 11444 | @Override |
| 11445 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11446 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11447 | final long identity = Binder.clearCallingIdentity(); |
| 11448 | try { |
| 11449 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11450 | } catch (ImsException e) { |
| 11451 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11452 | } finally { |
| 11453 | Binder.restoreCallingIdentity(identity); |
| 11454 | } |
| 11455 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11456 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11457 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11458 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11459 | String callingPackage) { |
| 11460 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11461 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11462 | |
| 11463 | final int callingUid = Binder.getCallingUid(); |
| 11464 | // Verify that tha callingPackage belongs to the calling UID |
| 11465 | mApp.getSystemService(AppOpsManager.class) |
| 11466 | .checkPackage(callingUid, callingPackage); |
| 11467 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11468 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11469 | |
| 11470 | final long identity = Binder.clearCallingIdentity(); |
| 11471 | try { |
| 11472 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11473 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11474 | |
| 11475 | if (result instanceof IllegalStateException) { |
| 11476 | throw (IllegalStateException) result; |
| 11477 | } |
| 11478 | } finally { |
| 11479 | Binder.restoreCallingIdentity(identity); |
| 11480 | } |
| 11481 | } |
| 11482 | |
| 11483 | @Override |
| 11484 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11485 | String callingPackage) { |
| 11486 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11487 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11488 | |
| 11489 | final int callingUid = Binder.getCallingUid(); |
| 11490 | // Verify that tha callingPackage belongs to the calling UID |
| 11491 | mApp.getSystemService(AppOpsManager.class) |
| 11492 | .checkPackage(callingUid, callingPackage); |
| 11493 | |
| 11494 | final long identity = Binder.clearCallingIdentity(); |
| 11495 | try { |
| 11496 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11497 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11498 | |
| 11499 | if (result instanceof IllegalStateException) { |
| 11500 | throw (IllegalStateException) result; |
| 11501 | } |
| 11502 | } finally { |
| 11503 | Binder.restoreCallingIdentity(identity); |
| 11504 | } |
| 11505 | } |
| 11506 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11507 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11508 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11509 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11510 | // phone/system process do not have further restriction on request |
| 11511 | return; |
| 11512 | } |
| 11513 | |
| 11514 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11515 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11516 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11517 | context.enforceCallingOrSelfPermission( |
| 11518 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11519 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11520 | } |
| 11521 | |
| 11522 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11523 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11524 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11525 | || info.isEnabled()) { |
| 11526 | throw new IllegalArgumentException( |
| 11527 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11528 | } |
| 11529 | |
| 11530 | // Thresholds length for each RAN need in range. This has been validated in |
| 11531 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11532 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11533 | final int[] thresholds = info.getThresholds(); |
| 11534 | Objects.requireNonNull(thresholds); |
| 11535 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11536 | || thresholds.length |
| 11537 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11538 | throw new IllegalArgumentException( |
| 11539 | "thresholds length is out of range: " + thresholds.length); |
| 11540 | } |
| 11541 | } |
| 11542 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11543 | |
| 11544 | /** |
| 11545 | * Gets the current phone capability. |
| 11546 | * |
| 11547 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11548 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11549 | * It's used to evaluate possible phone config change, for example from single |
| 11550 | * SIM device to multi-SIM device. |
| 11551 | */ |
| 11552 | @Override |
| 11553 | public PhoneCapability getPhoneCapability() { |
| 11554 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11555 | final long identity = Binder.clearCallingIdentity(); |
| 11556 | try { |
| 11557 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11558 | } finally { |
| 11559 | Binder.restoreCallingIdentity(identity); |
| 11560 | } |
| 11561 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11562 | |
| 11563 | /** |
| 11564 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11565 | * required to be done shortly after the API is invoked. |
| 11566 | */ |
| 11567 | @Override |
| 11568 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11569 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11570 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11571 | enforceRebootPermission(); |
| 11572 | |
| 11573 | final long identity = Binder.clearCallingIdentity(); |
| 11574 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11575 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11576 | } finally { |
| 11577 | Binder.restoreCallingIdentity(identity); |
| 11578 | } |
| 11579 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11580 | |
| 11581 | /** |
| 11582 | * Request to get the current slicing configuration including URSP rules and |
| 11583 | * NSSAIs (configured, allowed and rejected). |
| 11584 | * |
| 11585 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11586 | */ |
| 11587 | @Override |
| 11588 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11589 | TelephonyPermissions |
| 11590 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11591 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11592 | |
| 11593 | final long identity = Binder.clearCallingIdentity(); |
| 11594 | try { |
| 11595 | Phone phone = getDefaultPhone(); |
| 11596 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11597 | } finally { |
| 11598 | Binder.restoreCallingIdentity(identity); |
| 11599 | } |
| 11600 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11601 | |
| 11602 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11603 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11604 | * |
| 11605 | * @param capability The premium capability to check. |
| 11606 | * @param subId The subId to check the premium capability for. |
| 11607 | * |
| 11608 | * @return Whether the given premium capability is available to purchase. |
| 11609 | */ |
| 11610 | @Override |
| 11611 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11612 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11613 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11614 | log("Premium capability " |
| 11615 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11616 | + " is not available for purchase due to missing permissions."); |
| 11617 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11618 | + "permission READ_BASIC_PHONE_STATE."); |
| 11619 | } |
| 11620 | |
| 11621 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11622 | if (phone == null) { |
| 11623 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11624 | return false; |
| 11625 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11626 | final long identity = Binder.clearCallingIdentity(); |
| 11627 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 11628 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11629 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11630 | } finally { |
| 11631 | Binder.restoreCallingIdentity(identity); |
| 11632 | } |
| 11633 | } |
| 11634 | |
| 11635 | /** |
| 11636 | * Purchase the given premium capability from the carrier. |
| 11637 | * |
| 11638 | * @param capability The premium capability to purchase. |
| 11639 | * @param callback The result of the purchase request. |
| 11640 | * @param subId The subId to purchase the premium capability for. |
| 11641 | */ |
| 11642 | @Override |
| 11643 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11644 | log("purchasePremiumCapability: capability=" |
| 11645 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11646 | + getCurrentPackageName()); |
| 11647 | |
| 11648 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11649 | mApp, "purchasePremiumCapability")) { |
| 11650 | log("purchasePremiumCapability " |
| 11651 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11652 | + " failed due to missing permissions."); |
| 11653 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11654 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11655 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11656 | mApp, "purchasePremiumCapability")) { |
| 11657 | log("purchasePremiumCapability " |
| 11658 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11659 | + " failed due to missing permissions."); |
| 11660 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11661 | } |
| 11662 | |
| 11663 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11664 | if (phone == null) { |
| 11665 | try { |
| 11666 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11667 | callback.accept(result); |
| 11668 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11669 | } catch (RemoteException e) { |
| 11670 | String logStr = "Purchase premium capability " |
| 11671 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11672 | + " failed due to RemoteException handling null phone: " + e; |
| 11673 | if (DBG) log(logStr); |
| 11674 | AnomalyReporter.reportAnomaly( |
| 11675 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11676 | } |
| 11677 | return; |
| 11678 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11679 | |
| 11680 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11681 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11682 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11683 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11684 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11685 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11686 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11687 | |
| 11688 | boolean isVisible = false; |
| 11689 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11690 | if (am != null) { |
| 11691 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11692 | if (processes != null) { |
| 11693 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11694 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 11695 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11696 | if (process.processName.equals(callingProcess) && process.importance |
| 11697 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11698 | isVisible = true; |
| 11699 | break; |
| 11700 | } |
| 11701 | } |
| 11702 | } |
| 11703 | } |
| 11704 | |
| 11705 | if (!isVisible) { |
| 11706 | try { |
| 11707 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11708 | callback.accept(result); |
| 11709 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11710 | } catch (RemoteException e) { |
| 11711 | String logStr = "Purchase premium capability " |
| 11712 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11713 | + " failed due to RemoteException handling background application: " + e; |
| 11714 | if (DBG) log(logStr); |
| 11715 | AnomalyReporter.reportAnomaly( |
| 11716 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11717 | } |
| 11718 | return; |
| 11719 | } |
| 11720 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11721 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11722 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11723 | } |
| 11724 | |
| 11725 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11726 | * Register an IMS connection state callback |
| 11727 | */ |
| 11728 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11729 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11730 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11731 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11732 | // ImsMmTelManager |
| 11733 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11734 | TelephonyPermissions |
| 11735 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11736 | mApp, subId, "registerImsStateCallback"); |
| 11737 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11738 | // ImsRcsManager or SipDelegateManager |
| 11739 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11740 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11741 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11742 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11743 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11744 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11745 | } |
| 11746 | |
| 11747 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11748 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11749 | "IMS not available on device."); |
| 11750 | } |
| 11751 | |
| 11752 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11753 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11754 | } |
| 11755 | |
| 11756 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11757 | if (controller == null) { |
| 11758 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11759 | "IMS not available on device."); |
| 11760 | } |
| 11761 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11762 | if (callingPackage == null) { |
| 11763 | callingPackage = getCurrentPackageName(); |
| 11764 | } |
| 11765 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11766 | final long token = Binder.clearCallingIdentity(); |
| 11767 | try { |
| 11768 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11769 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11770 | } catch (ImsException e) { |
| 11771 | throw new ServiceSpecificException(e.getCode()); |
| 11772 | } finally { |
| 11773 | Binder.restoreCallingIdentity(token); |
| 11774 | } |
| 11775 | } |
| 11776 | |
| 11777 | /** |
| 11778 | * Unregister an IMS connection state callback |
| 11779 | */ |
| 11780 | @Override |
| 11781 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11782 | final long token = Binder.clearCallingIdentity(); |
| 11783 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11784 | if (controller == null) { |
| 11785 | return; |
| 11786 | } |
| 11787 | try { |
| 11788 | controller.unregisterImsStateCallback(cb); |
| 11789 | } finally { |
| 11790 | Binder.restoreCallingIdentity(token); |
| 11791 | } |
| 11792 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11793 | |
| 11794 | /** |
| 11795 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11796 | * |
| 11797 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11798 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11799 | * SecurityException. |
| 11800 | * If there is current registered network this value will be same as the registered cell |
| 11801 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11802 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11803 | * it will be cleared and null will be returned. |
| 11804 | * |
| 11805 | */ |
| 11806 | @Override |
| 11807 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11808 | String callingFeatureId) { |
| 11809 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11810 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11811 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11812 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11813 | .setCallingPackage(callingPackage) |
| 11814 | .setCallingFeatureId(callingFeatureId) |
| 11815 | .setCallingPid(Binder.getCallingPid()) |
| 11816 | .setCallingUid(Binder.getCallingUid()) |
| 11817 | .setMethod("getLastKnownCellIdentity") |
| 11818 | .setLogAsInfo(true) |
| 11819 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11820 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11821 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11822 | .build()); |
| 11823 | |
| 11824 | boolean hasFinePermission = |
| 11825 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11826 | if (!hasFinePermission |
| 11827 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11828 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11829 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11830 | } |
| 11831 | |
| 11832 | final long identity = Binder.clearCallingIdentity(); |
| 11833 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11834 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11835 | if (sst == null) return null; |
| 11836 | return sst.getLastKnownCellIdentity(); |
| 11837 | } finally { |
| 11838 | Binder.restoreCallingIdentity(identity); |
| 11839 | } |
| 11840 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11841 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11842 | /** |
| 11843 | * Sets the modem service class Name that Telephony will bind to. |
| 11844 | * |
| 11845 | * @param serviceName The class name of the modem service. |
| 11846 | * @return true if the operation is succeed, otherwise false. |
| 11847 | */ |
| 11848 | public boolean setModemService(String serviceName) { |
| 11849 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11850 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11851 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11852 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11853 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11854 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11855 | } |
| 11856 | |
| 11857 | /** |
| 11858 | * Return the class name of the currently bounded modem service. |
| 11859 | * |
| 11860 | * @return the class name of the modem service. |
| 11861 | */ |
| 11862 | public String getModemService() { |
| 11863 | String result; |
| 11864 | Log.d(LOG_TAG, "getModemService"); |
| 11865 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11866 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11867 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11868 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11869 | "getModemService"); |
| 11870 | result = mPhoneConfigurationManager.getModemService(); |
| 11871 | Log.d(LOG_TAG, "result = " + result); |
| 11872 | return result; |
| 11873 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11874 | |
| 11875 | @Override |
| 11876 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11877 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11878 | mApp.enforceCallingOrSelfPermission( |
| 11879 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11880 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11881 | |
| 11882 | final long identity = Binder.clearCallingIdentity(); |
| 11883 | try { |
| 11884 | Phone phone = getPhone(subId); |
| 11885 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11886 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11887 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11888 | phone.setVoiceServiceStateOverride(hasService); |
| 11889 | } finally { |
| 11890 | Binder.restoreCallingIdentity(identity); |
| 11891 | } |
| 11892 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11893 | |
| 11894 | /** |
| 11895 | * set removable eSIM as default eUICC. |
| 11896 | * |
| 11897 | * @hide |
| 11898 | */ |
| 11899 | @Override |
| 11900 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11901 | enforceModifyPermission(); |
| 11902 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11903 | |
| 11904 | final long identity = Binder.clearCallingIdentity(); |
| 11905 | try { |
| 11906 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11907 | } finally { |
| 11908 | Binder.restoreCallingIdentity(identity); |
| 11909 | } |
| 11910 | } |
| 11911 | |
| 11912 | /** |
| 11913 | * Returns whether the removable eSIM is default eUICC or not. |
| 11914 | * |
| 11915 | * @hide |
| 11916 | */ |
| 11917 | @Override |
| 11918 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11919 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11920 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11921 | |
| 11922 | final long identity = Binder.clearCallingIdentity(); |
| 11923 | try { |
| 11924 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11925 | } finally { |
| 11926 | Binder.restoreCallingIdentity(identity); |
| 11927 | } |
| 11928 | } |
| 11929 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11930 | /** |
| 11931 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11932 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11933 | * application currently configured for this user. |
| 11934 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11935 | * {@code null} if the functionality is not supported. |
| 11936 | * @hide |
| 11937 | */ |
| 11938 | @Override |
| 11939 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11940 | boolean updateIfNeeded) { |
| 11941 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11942 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11943 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11944 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11945 | UserHandle userHandle = null; |
| 11946 | final long identity = Binder.clearCallingIdentity(); |
| 11947 | try { |
| 11948 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11949 | } finally { |
| 11950 | Binder.restoreCallingIdentity(identity); |
| 11951 | } |
| 11952 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11953 | updateIfNeeded, userHandle); |
| 11954 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11955 | |
| 11956 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11957 | * Set whether the device is able to connect with null ciphering or integrity |
| 11958 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11959 | * and all new subscriptions after this. |
| 11960 | * |
| 11961 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11962 | * @hide |
| 11963 | */ |
| 11964 | @Override |
| 11965 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11966 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11967 | enforceModifyPermission(); |
| 11968 | checkForNullCipherAndIntegritySupport(); |
| 11969 | |
| 11970 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11971 | // for listening to these preference changes and applying them immediately. |
| 11972 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11973 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11974 | editor.apply(); |
| 11975 | |
| 11976 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11977 | phone.handleNullCipherEnabledChange(); |
| 11978 | } |
| 11979 | } |
| 11980 | |
| 11981 | |
| 11982 | /** |
| 11983 | * Get whether the device is able to connect with null ciphering or integrity |
| 11984 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11985 | * the state of the radio. |
| 11986 | * |
| 11987 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11988 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11989 | * version for this feature. |
| 11990 | * @hide |
| 11991 | */ |
| 11992 | @Override |
| 11993 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11994 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11995 | enforceReadPermission(); |
| 11996 | checkForNullCipherAndIntegritySupport(); |
| 11997 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11998 | } |
| 11999 | |
| 12000 | private void checkForNullCipherAndIntegritySupport() { |
| 12001 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12002 | throw new UnsupportedOperationException( |
| 12003 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12004 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12005 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12006 | throw new UnsupportedOperationException( |
| 12007 | "Null cipher and integrity operations unsupported by modem"); |
| 12008 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12009 | } |
| 12010 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12011 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12012 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12013 | throw new UnsupportedOperationException( |
| 12014 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12015 | + "above"); |
| 12016 | } |
| 12017 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12018 | throw new UnsupportedOperationException( |
| 12019 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12020 | } |
| 12021 | } |
| 12022 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12023 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12024 | * Get the SIM state for the slot index. |
| 12025 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12026 | * |
| 12027 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12028 | */ |
| 12029 | @Override |
| 12030 | @SimState |
| 12031 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12032 | IccCardConstants.State simState; |
| 12033 | if (slotIndex < 0) { |
| 12034 | simState = IccCardConstants.State.UNKNOWN; |
| 12035 | } else { |
| 12036 | Phone phone = null; |
| 12037 | try { |
| 12038 | phone = PhoneFactory.getPhone(slotIndex); |
| 12039 | } catch (IllegalStateException e) { |
| 12040 | // ignore |
| 12041 | } |
| 12042 | if (phone == null) { |
| 12043 | simState = IccCardConstants.State.UNKNOWN; |
| 12044 | } else { |
| 12045 | IccCard icc = phone.getIccCard(); |
| 12046 | if (icc == null) { |
| 12047 | simState = IccCardConstants.State.UNKNOWN; |
| 12048 | } else { |
| 12049 | simState = icc.getState(); |
| 12050 | } |
| 12051 | } |
| 12052 | } |
| 12053 | return simState.ordinal(); |
| 12054 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12055 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12056 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12057 | boolean enableLogcat, |
| 12058 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12059 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12060 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 12061 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 12062 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 12063 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 12064 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 12065 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 12066 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 12067 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12068 | Executors.newCachedThreadPool(), db, |
| 12069 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 12070 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12071 | } |
| 12072 | |
| 12073 | /** |
| 12074 | * Request telephony to persist state for debugging emergency call failures. |
| 12075 | * |
| 12076 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 12077 | * @param enableLogcat whether to collect logcat output |
| 12078 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12079 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12080 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12081 | */ |
| 12082 | @Override |
| 12083 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12084 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12085 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12086 | boolean enableTelephonyDump) { |
| 12087 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12088 | "persistEmergencyCallDiagnosticData"); |
| 12089 | final long identity = Binder.clearCallingIdentity(); |
| 12090 | try { |
| 12091 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12092 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12093 | |
| 12094 | } finally { |
| 12095 | Binder.restoreCallingIdentity(identity); |
| 12096 | } |
| 12097 | } |
| 12098 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12099 | /** |
| 12100 | * Get current cell broadcast ranges. |
| 12101 | */ |
| 12102 | @Override |
| 12103 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12104 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12105 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12106 | "getCellBroadcastIdRanges"); |
| 12107 | final long identity = Binder.clearCallingIdentity(); |
| 12108 | try { |
| 12109 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12110 | } finally { |
| 12111 | Binder.restoreCallingIdentity(identity); |
| 12112 | } |
| 12113 | } |
| 12114 | |
| 12115 | /** |
| 12116 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12117 | * |
| 12118 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12119 | */ |
| 12120 | @Override |
| 12121 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12122 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12123 | @Nullable IIntegerConsumer callback) { |
| 12124 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12125 | "setCellBroadcastIdRanges"); |
| 12126 | final long identity = Binder.clearCallingIdentity(); |
| 12127 | try { |
| 12128 | Phone phone = getPhoneFromSubId(subId); |
| 12129 | if (DBG) { |
| 12130 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12131 | } |
| 12132 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12133 | if (callback != null) { |
| 12134 | try { |
| 12135 | callback.accept(result); |
| 12136 | } catch (RemoteException e) { |
| 12137 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12138 | } |
| 12139 | } |
| 12140 | }); |
| 12141 | } finally { |
| 12142 | Binder.restoreCallingIdentity(identity); |
| 12143 | } |
| 12144 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12145 | |
| 12146 | /** |
| 12147 | * Returns whether the device supports the domain selection service. |
| 12148 | * |
| 12149 | * @return {@code true} if the device supports the domain selection service. |
| 12150 | */ |
| 12151 | @Override |
| 12152 | public boolean isDomainSelectionSupported() { |
| 12153 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12154 | "isDomainSelectionSupported"); |
| 12155 | |
| 12156 | final long identity = Binder.clearCallingIdentity(); |
| 12157 | try { |
| 12158 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12159 | } finally { |
| 12160 | Binder.restoreCallingIdentity(identity); |
| 12161 | } |
| 12162 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12163 | |
| 12164 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12165 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12166 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12167 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12168 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12169 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12170 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12171 | * {@code false} to disable. |
| 12172 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12173 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12174 | * |
| 12175 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12176 | */ |
| 12177 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12178 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12179 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12180 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12181 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12182 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12183 | } |
| 12184 | |
| 12185 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12186 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12187 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12188 | * @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] | 12189 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12190 | * 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] | 12191 | * |
| 12192 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12193 | */ |
| 12194 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12195 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12196 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12197 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12198 | } |
| 12199 | |
| 12200 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12201 | * Request to get whether the satellite service demo mode is enabled. |
| 12202 | * |
| 12203 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12204 | * is enabled for. |
| 12205 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12206 | * if the request is successful or an error code if the request failed. |
| 12207 | * |
| 12208 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12209 | */ |
| 12210 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12211 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12212 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12213 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12214 | } |
| 12215 | |
| 12216 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12217 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12218 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12219 | * @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] | 12220 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12221 | * 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] | 12222 | */ |
| 12223 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12224 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12225 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12226 | } |
| 12227 | |
| 12228 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12229 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12230 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12231 | * @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] | 12232 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12233 | * 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] | 12234 | * |
| 12235 | * @throws SecurityException if the caller doesn't have required permission. |
| 12236 | */ |
| 12237 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12238 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12239 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12240 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12241 | } |
| 12242 | |
| 12243 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12244 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12245 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12246 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12247 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12248 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12249 | * @param resultCallback The callback to get the result of the request. |
| 12250 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12251 | * |
| 12252 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12253 | */ |
| 12254 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12255 | public void startSatelliteTransmissionUpdates(int subId, |
| 12256 | @NonNull IIntegerConsumer resultCallback, |
| 12257 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12258 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12259 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12260 | } |
| 12261 | |
| 12262 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12263 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12264 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12265 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12266 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12267 | * @param resultCallback The callback to get the result of the request. |
| 12268 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12269 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12270 | * |
| 12271 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12272 | */ |
| 12273 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12274 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12275 | @NonNull IIntegerConsumer resultCallback, |
| 12276 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12277 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12278 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12279 | } |
| 12280 | |
| 12281 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12282 | * Register the subscription with a satellite provider. |
| 12283 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12284 | * |
| 12285 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12286 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12287 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12288 | * @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] | 12289 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12290 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12291 | * @return The signal transport used by the caller to cancel the provision request, |
| 12292 | * or {@code null} if the request failed. |
| 12293 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12294 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12295 | */ |
| 12296 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12297 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12298 | @NonNull String token, @NonNull byte[] provisionData, |
| 12299 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12300 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 12301 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 12302 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12303 | } |
| 12304 | |
| 12305 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12306 | * Unregister the device/subscription with the satellite provider. |
| 12307 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12308 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12309 | * should report as deprovisioned. |
| 12310 | * |
| 12311 | * @param subId The subId of the subscription to be deprovisioned. |
| 12312 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12313 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12314 | * |
| 12315 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12316 | */ |
| 12317 | @Override |
| 12318 | public void deprovisionSatelliteService(int subId, |
| 12319 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12320 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12321 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12322 | } |
| 12323 | |
| 12324 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12325 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12326 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12327 | * @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] | 12328 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12329 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12330 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12331 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12332 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12333 | */ |
| 12334 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12335 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 12336 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12337 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12338 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12339 | } |
| 12340 | |
| 12341 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12342 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12343 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12344 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12345 | * @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] | 12346 | * @param callback The callback that was passed to |
| 12347 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12348 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12349 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12350 | */ |
| 12351 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12352 | public void unregisterForSatelliteProvisionStateChanged( |
| 12353 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12354 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12355 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12356 | } |
| 12357 | |
| 12358 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12359 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12360 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12361 | * @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] | 12362 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12363 | * satellite provider if the request is successful or an error code if the |
| 12364 | * request failed. |
| 12365 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12366 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12367 | */ |
| 12368 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12369 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12370 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12371 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12372 | } |
| 12373 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12374 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12375 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12376 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12377 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12378 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12379 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12380 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12381 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12382 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12383 | */ |
| 12384 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12385 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12386 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12387 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12388 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12389 | } |
| 12390 | |
| 12391 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12392 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12393 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12394 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12395 | * @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] | 12396 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12397 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12398 | * |
| 12399 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12400 | */ |
| 12401 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12402 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12403 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12404 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12405 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12406 | } |
| 12407 | |
| 12408 | /** |
| 12409 | * Register to receive incoming datagrams over satellite. |
| 12410 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12411 | * @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] | 12412 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12413 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12414 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12415 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12416 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12417 | */ |
| 12418 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12419 | @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12420 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12421 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12422 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12423 | } |
| 12424 | |
| 12425 | /** |
| 12426 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12427 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12428 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12429 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12430 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12431 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12432 | * |
| 12433 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12434 | */ |
| 12435 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12436 | public void unregisterForSatelliteDatagram(int subId, |
| 12437 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12438 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12439 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12440 | } |
| 12441 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12442 | /** |
| 12443 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12444 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12445 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12446 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 12447 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12448 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12449 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12450 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12451 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12452 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12453 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12454 | @Override |
| 12455 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12456 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12457 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12458 | } |
| 12459 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12460 | /** |
| 12461 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12462 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12463 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 12464 | * input to this method. Datagram received here will be passed down to modem without any |
| 12465 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12466 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12467 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 12468 | * @param datagramType datagram type indicating whether the datagram is of type |
| 12469 | * SOS_SMS or LOCATION_SHARING. |
| 12470 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 12471 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12472 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 12473 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 12474 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12475 | * |
| 12476 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12477 | */ |
| 12478 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12479 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 12480 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 12481 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12482 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12483 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 12484 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12485 | } |
| 12486 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12487 | /** |
| 12488 | * Request to get whether satellite communication is allowed for the current location. |
| 12489 | * |
| 12490 | * @param subId The subId of the subscription to check whether satellite communication is |
| 12491 | * allowed for the current location for. |
| 12492 | * @param result The result receiver that returns whether satellite communication is allowed |
| 12493 | * for the current location if the request is successful or an error code |
| 12494 | * if the request failed. |
| 12495 | * |
| 12496 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12497 | */ |
| 12498 | @Override |
| 12499 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 12500 | @NonNull ResultReceiver result) { |
| 12501 | enforceSatelliteCommunicationPermission( |
| 12502 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12503 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 12504 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12505 | } |
| 12506 | |
| 12507 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12508 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12509 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12510 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12511 | * @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] | 12512 | * be visible if the request is successful or an error code if the request failed. |
| 12513 | * |
| 12514 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12515 | */ |
| 12516 | @Override |
| 12517 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 12518 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12519 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12520 | } |
| 12521 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12522 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12523 | * Inform that Device is aligned to satellite for demo mode. |
| 12524 | * |
| 12525 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12526 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 12527 | * {@code false} Device fails to align with the satellite for demo mode. |
| 12528 | * |
| 12529 | * @throws SecurityException if the caller doesn't have required permission. |
| 12530 | */ |
| 12531 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 12532 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12533 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12534 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 12535 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12536 | } |
| 12537 | |
| 12538 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 12539 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12540 | * by modem. |
| 12541 | * |
| 12542 | * @param subId The subId of the subscription to request for. |
| 12543 | * @param reason Reason for disallowing satellite communication for carrier. |
| 12544 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12545 | * operation. |
| 12546 | * |
| 12547 | * @throws SecurityException if the caller doesn't have required permission. |
| 12548 | */ |
| 12549 | public void addSatelliteAttachRestrictionForCarrier(int subId, |
| 12550 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12551 | @NonNull IIntegerConsumer callback) { |
| 12552 | enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier"); |
| 12553 | final long identity = Binder.clearCallingIdentity(); |
| 12554 | try { |
| 12555 | mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback); |
| 12556 | } finally { |
| 12557 | Binder.restoreCallingIdentity(identity); |
| 12558 | } |
| 12559 | } |
| 12560 | |
| 12561 | /** |
| 12562 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 12563 | * by modem. |
| 12564 | * |
| 12565 | * @param subId The subId of the subscription to request for. |
| 12566 | * @param reason Reason for disallowing satellite communication. |
| 12567 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 12568 | * operation. |
| 12569 | * |
| 12570 | * @throws SecurityException if the caller doesn't have required permission. |
| 12571 | */ |
| 12572 | public void removeSatelliteAttachRestrictionForCarrier(int subId, |
| 12573 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 12574 | @NonNull IIntegerConsumer callback) { |
| 12575 | enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier"); |
| 12576 | final long identity = Binder.clearCallingIdentity(); |
| 12577 | try { |
| 12578 | mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason, |
| 12579 | callback); |
| 12580 | } finally { |
| 12581 | Binder.restoreCallingIdentity(identity); |
| 12582 | } |
| 12583 | } |
| 12584 | |
| 12585 | /** |
| 12586 | * Get reasons for disallowing satellite communication, as requested by |
| 12587 | * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
| 12588 | * |
| 12589 | * @param subId The subId of the subscription to request for. |
| 12590 | * |
| 12591 | * @return Integer array of reasons for disallowing satellite communication. |
| 12592 | * |
| 12593 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12594 | */ |
| 12595 | public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier( |
| 12596 | int subId) { |
| 12597 | enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier"); |
| 12598 | final long identity = Binder.clearCallingIdentity(); |
| 12599 | try { |
| 12600 | Set<Integer> reasonSet = |
| 12601 | mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId); |
| 12602 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 12603 | } finally { |
| 12604 | Binder.restoreCallingIdentity(identity); |
| 12605 | } |
| 12606 | } |
| 12607 | |
| 12608 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12609 | * Request to get the signal strength of the satellite connection. |
| 12610 | * |
| 12611 | * @param subId The subId of the subscription to request for. |
| 12612 | * @param result Result receiver to get the error code of the request and the current signal |
| 12613 | * strength of the satellite connection. |
| 12614 | * |
| 12615 | * @throws SecurityException if the caller doesn't have required permission. |
| 12616 | */ |
| 12617 | @Override |
| 12618 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 12619 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 12620 | final long identity = Binder.clearCallingIdentity(); |
| 12621 | try { |
| 12622 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 12623 | } finally { |
| 12624 | Binder.restoreCallingIdentity(identity); |
| 12625 | } |
| 12626 | } |
| 12627 | |
| 12628 | /** |
| 12629 | * Registers for NTN signal strength changed from satellite modem. |
| 12630 | * |
| 12631 | * @param subId The subId of the subscription to request for. |
| 12632 | * @param callback The callback to handle the NTN signal strength changed event. |
| 12633 | * |
| 12634 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 12635 | * |
| 12636 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12637 | */ |
| 12638 | @Override |
| 12639 | @SatelliteManager.SatelliteResult public int registerForNtnSignalStrengthChanged( |
| 12640 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 12641 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 12642 | final long identity = Binder.clearCallingIdentity(); |
| 12643 | try { |
| 12644 | return mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
| 12645 | } finally { |
| 12646 | Binder.restoreCallingIdentity(identity); |
| 12647 | } |
| 12648 | } |
| 12649 | |
| 12650 | /** |
| 12651 | * Unregisters for NTN signal strength changed from satellite modem. |
| 12652 | * If callback was not registered before, the request will be ignored. |
| 12653 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12654 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 12655 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 12656 | * @param callback The callback that was passed to |
| 12657 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 12658 | * |
| 12659 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12660 | */ |
| 12661 | @Override |
| 12662 | public void unregisterForNtnSignalStrengthChanged( |
| 12663 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 12664 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 12665 | final long identity = Binder.clearCallingIdentity(); |
| 12666 | try { |
| 12667 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 12668 | } finally { |
| 12669 | Binder.restoreCallingIdentity(identity); |
| 12670 | } |
| 12671 | } |
| 12672 | |
| 12673 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 12674 | * Registers for satellite capabilities change event from the satellite service. |
| 12675 | * |
| 12676 | * @param subId The subId of the subscription to request for. |
| 12677 | * @param callback The callback to handle the satellite capabilities changed event. |
| 12678 | * |
| 12679 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 12680 | * |
| 12681 | * @throws SecurityException if the caller doesn't have required permission. |
| 12682 | */ |
| 12683 | @Override |
| 12684 | @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged( |
| 12685 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12686 | enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged"); |
| 12687 | final long identity = Binder.clearCallingIdentity(); |
| 12688 | try { |
| 12689 | return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback); |
| 12690 | } finally { |
| 12691 | Binder.restoreCallingIdentity(identity); |
| 12692 | } |
| 12693 | } |
| 12694 | |
| 12695 | /** |
| 12696 | * Unregisters for satellite capabilities change event from the satellite service. |
| 12697 | * If callback was not registered before, the request will be ignored. |
| 12698 | * |
| 12699 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 12700 | * @param callback The callback that was passed to. |
| 12701 | * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
| 12702 | * |
| 12703 | * @throws SecurityException if the caller doesn't have required permission. |
| 12704 | */ |
| 12705 | @Override |
| 12706 | public void unregisterForSatelliteCapabilitiesChanged( |
| 12707 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 12708 | enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged"); |
| 12709 | final long identity = Binder.clearCallingIdentity(); |
| 12710 | try { |
| 12711 | mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback); |
| 12712 | } finally { |
| 12713 | Binder.restoreCallingIdentity(identity); |
| 12714 | } |
| 12715 | } |
| 12716 | |
| 12717 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 12718 | * This API can be used by only CTS to update satellite vendor service package name. |
| 12719 | * |
| 12720 | * @param servicePackageName The package name of the satellite vendor service. |
| 12721 | * @return {@code true} if the satellite vendor service is set successfully, |
| 12722 | * {@code false} otherwise. |
| 12723 | */ |
| 12724 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 12725 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 12726 | TelephonyPermissions.enforceShellOnly( |
| 12727 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 12728 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12729 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12730 | "setSatelliteServicePackageName"); |
| 12731 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 12732 | } |
| 12733 | |
| 12734 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 12735 | * This API can be used by only CTS to update satellite gateway service package name. |
| 12736 | * |
| 12737 | * @param servicePackageName The package name of the satellite gateway service. |
| 12738 | * @return {@code true} if the satellite gateway service is set successfully, |
| 12739 | * {@code false} otherwise. |
| 12740 | */ |
| 12741 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 12742 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 12743 | TelephonyPermissions.enforceShellOnly( |
| 12744 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 12745 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12746 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12747 | "setSatelliteGatewayServicePackageName"); |
| 12748 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 12749 | } |
| 12750 | |
| 12751 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 12752 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 12753 | * |
| 12754 | * @param packageName The package name of the satellite pointing UI app. |
| 12755 | * @param className The class name of the satellite pointing UI app. |
| 12756 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 12757 | * {@code false} otherwise. |
| 12758 | */ |
| 12759 | public boolean setSatellitePointingUiClassName( |
| 12760 | @Nullable String packageName, @Nullable String className) { |
| 12761 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 12762 | + ", className=" + className); |
| 12763 | TelephonyPermissions.enforceShellOnly( |
| 12764 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 12765 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12766 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12767 | "setSatelliteGatewayServicePackageName"); |
| 12768 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 12769 | } |
| 12770 | |
| 12771 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 12772 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 12773 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 12774 | * listening mode. |
| 12775 | * |
| 12776 | * @param timeoutMillis The timeout duration in millisecond. |
| 12777 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12778 | */ |
| 12779 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 12780 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 12781 | TelephonyPermissions.enforceShellOnly( |
| 12782 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 12783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12784 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12785 | "setSatelliteListeningTimeoutDuration"); |
| 12786 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 12787 | } |
| 12788 | |
| 12789 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 12790 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 12791 | * the device is aligned with the satellite for demo mode |
| 12792 | * |
| 12793 | * @param timeoutMillis The timeout duration in millisecond. |
| 12794 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 12795 | */ |
| 12796 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 12797 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 12798 | TelephonyPermissions.enforceShellOnly( |
| 12799 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 12800 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12801 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12802 | "setDeviceAlignedTimeoutDuration"); |
| 12803 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 12804 | } |
| 12805 | |
| 12806 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 12807 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 12808 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 12809 | * |
| 12810 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 12811 | * of the following values to enable the override: |
| 12812 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 12813 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 12814 | * To disable the override, use -1 for handoverType. |
| 12815 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 12816 | * delaySeconds after the emergency call starts. |
| 12817 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 12818 | */ |
| 12819 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 12820 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 12821 | TelephonyPermissions.enforceShellOnly( |
| 12822 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 12823 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12824 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12825 | "setEmergencyCallToSatelliteHandoverType"); |
| 12826 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 12827 | handoverType, delaySeconds); |
| 12828 | } |
| 12829 | |
| 12830 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 12831 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 12832 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 12833 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 12834 | * |
| 12835 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 12836 | * satellite modem or not. |
| 12837 | * |
| 12838 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 12839 | */ |
| 12840 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 12841 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 12842 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 12843 | + "disabled"); |
| 12844 | return false; |
| 12845 | } |
| 12846 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 12847 | TelephonyPermissions.enforceShellOnly( |
| 12848 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 12849 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 12850 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12851 | "setShouldSendDatagramToModemInDemoMode"); |
| 12852 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 12853 | shouldSendToModemInDemoMode); |
| 12854 | } |
| 12855 | |
| 12856 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12857 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 12858 | * |
| 12859 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 12860 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 12861 | * identifier is sent in the clear, which has privacy implications for the user. |
| 12862 | * |
| 12863 | * @param enable if notifications about disclosure events should be enabled |
| 12864 | * @throws SecurityException if the caller does not have the required privileges |
| 12865 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 12866 | */ |
| 12867 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 12868 | public void enableCellularIdentifierDisclosureNotifications(boolean enable) { |
| 12869 | enforceModifyPermission(); |
| 12870 | checkForIdentifierDisclosureNotificationSupport(); |
| 12871 | |
| 12872 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12873 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 12874 | editor.apply(); |
| 12875 | |
| 12876 | // Each phone instance is responsible for updating its respective modem immediately |
| 12877 | // after we've made a preference change. |
| 12878 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12879 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 12880 | } |
| 12881 | } |
| 12882 | |
| 12883 | /** |
| 12884 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 12885 | * |
| 12886 | * @throws SecurityException if the caller does not have the required privileges |
| 12887 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 12888 | */ |
| 12889 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 12890 | public boolean isCellularIdentifierDisclosureNotificationEnabled() { |
| 12891 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 12892 | checkForIdentifierDisclosureNotificationSupport(); |
| 12893 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 12894 | } |
| 12895 | |
| 12896 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12897 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12898 | * |
| 12899 | * <p>This method behaves in one of the following ways: |
| 12900 | * <ul> |
| 12901 | * <li>return true : if the calling package has the appop permission {@link |
| 12902 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12903 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12904 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12905 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12906 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12907 | * </ul> |
| 12908 | */ |
| 12909 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12910 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12911 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12912 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12913 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12914 | return true; |
| 12915 | } |
| 12916 | } |
| 12917 | return false; |
| 12918 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12919 | |
| 12920 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12921 | * @return The subscription manager service instance. |
| 12922 | */ |
| 12923 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12924 | return SubscriptionManagerService.getInstance(); |
| 12925 | } |
| 12926 | |
| 12927 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12928 | * Class binds the consumer[callback] and carrierId. |
| 12929 | */ |
| 12930 | private static class CallerCallbackInfo { |
| 12931 | private final Consumer<Integer> mConsumer; |
| 12932 | private final int mCarrierId; |
| 12933 | |
| 12934 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12935 | mConsumer = consumer; |
| 12936 | mCarrierId = carrierId; |
| 12937 | } |
| 12938 | |
| 12939 | public Consumer<Integer> getConsumer() { |
| 12940 | return mConsumer; |
| 12941 | } |
| 12942 | |
| 12943 | public int getCarrierId() { |
| 12944 | return mCarrierId; |
| 12945 | } |
| 12946 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12947 | } |