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; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 20 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 22 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 27 | 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] | 28 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 29 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 30 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 33 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 34 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 36 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 37 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 38 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 39 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.compat.annotation.ChangeId; |
| 41 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 42 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 43 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.content.Context; |
| 45 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 46 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 47 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.net.Uri; |
| 50 | import android.os.AsyncResult; |
| 51 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 52 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Bundle; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 54 | import android.os.CancellationSignal; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 56 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 57 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 58 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import android.os.Looper; |
| 60 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 61 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 62 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 63 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 64 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 65 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 66 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 67 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 68 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 69 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 71 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 72 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 73 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 74 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 75 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 76 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 77 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 78 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 79 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 80 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 81 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 82 | import android.telephony.AccessNetworkConstants; |
| 83 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 84 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 85 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 86 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 87 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 88 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 89 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 90 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 91 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 92 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 93 | import android.telephony.CellIdentityCdma; |
| 94 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 96 | import android.telephony.CellInfoGsm; |
| 97 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 98 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 99 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 100 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 101 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 102 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 103 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 104 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 105 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 106 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 107 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 108 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 109 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 110 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 111 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 112 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 113 | import android.telephony.SignalStrengthUpdateRequest; |
| 114 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 115 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 117 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 118 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 119 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 120 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 121 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 122 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 123 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 124 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 125 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 126 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 127 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 129 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 130 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 131 | import android.telephony.gba.GbaAuthRequest; |
| 132 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 133 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 134 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 135 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 136 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 137 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 145 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 146 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 147 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 148 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 149 | import android.telephony.satellite.ISatelliteDatagramReceiverAck; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 150 | import android.telephony.satellite.ISatellitePositionUpdateCallback; |
| 151 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 152 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 153 | import android.telephony.satellite.PointingInfo; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 154 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 155 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 156 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 157 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 158 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 160 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 161 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 163 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 164 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 165 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 166 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 167 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 168 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 183 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 200 | import com.android.internal.telephony.RILConstants; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.RILUtils; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 204 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.SubscriptionController; |
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; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 216 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 217 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 218 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 219 | import com.android.internal.telephony.satellite.SatelliteServiceController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 220 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 221 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 222 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.IccIoResult; |
| 224 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 225 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 227 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 229 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 230 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 231 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 232 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 233 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 234 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 235 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 236 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 237 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 238 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 239 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 240 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 241 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 242 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 243 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 244 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 245 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 246 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 247 | import com.android.services.telephony.TelecomAccountRegistry; |
| 248 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 249 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 250 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 251 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 252 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 253 | import java.io.IOException; |
| 254 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 255 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 256 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 257 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 258 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 259 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 260 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 261 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 262 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 263 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 264 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 265 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 266 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 267 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 268 | import java.util.UUID; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 269 | import java.util.concurrent.ConcurrentHashMap; |
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; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 303 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 304 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 305 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 306 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 307 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 308 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 309 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 310 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 311 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 312 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 313 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 314 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 315 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 316 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 317 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 318 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 319 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 320 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 321 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 322 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 323 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 324 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 325 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 326 | private static final int CMD_SWITCH_SLOTS = 50; |
| 327 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 329 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 330 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 331 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 332 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 333 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 334 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 335 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 336 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 337 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 338 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 339 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 340 | private static final int CMD_MODEM_REBOOT = 64; |
| 341 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 342 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 343 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 344 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 345 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 346 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 347 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 348 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 349 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 350 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 351 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 352 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 353 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 354 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 355 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 356 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 357 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 358 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 359 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 360 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 361 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 362 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 363 | private static final int CMD_GET_CALL_WAITING = 87; |
| 364 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 365 | private static final int CMD_SET_CALL_WAITING = 89; |
| 366 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 367 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 368 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 369 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 370 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 371 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 372 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 373 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 374 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 375 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 376 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 377 | private static final int CMD_SET_SIM_POWER = 101; |
| 378 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 379 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 380 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 381 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 382 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 383 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 384 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 385 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 386 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 387 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 388 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 389 | private static final int CMD_ENABLE_VONR = 113; |
| 390 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 391 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 392 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 393 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 394 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 395 | private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119; |
| 396 | private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120; |
| 397 | private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121; |
| 398 | private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 399 | private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123; |
| 400 | private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 401 | private static final int CMD_PROVISION_SATELLITE_SERVICE = 125; |
| 402 | private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 403 | private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127; |
| 404 | private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 405 | private static final int CMD_SET_SATELLITE_ENABLED = 129; |
| 406 | private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130; |
| 407 | private static final int CMD_IS_SATELLITE_ENABLED = 131; |
| 408 | private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132; |
| 409 | private static final int CMD_IS_SATELLITE_SUPPORTED = 133; |
| 410 | private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134; |
| 411 | private static final int CMD_GET_SATELLITE_CAPABILITIES = 135; |
| 412 | private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 413 | private static final int CMD_POLL_PENDING_SATELLITE_DATAGRAMS = 137; |
| 414 | private static final int EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE = 138; |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 415 | private static final int CMD_SEND_SATELLITE_DATAGRAM = 139; |
| 416 | private static final int EVENT_SEND_SATELLITE_DATAGRAM_DONE = 140; |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 417 | private static final int CMD_IS_SATELLITE_COMMUNICATION_ALLOWED = 141; |
| 418 | private static final int EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE = 142; |
| 419 | private static final int CMD_GET_TIME_SATELLITE_NEXT_VISIBLE = 143; |
| 420 | private static final int EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE = 144; |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 421 | // Parameters of select command. |
| 422 | private static final int SELECT_COMMAND = 0xA4; |
| 423 | private static final int SELECT_P1 = 0x04; |
| 424 | private static final int SELECT_P2 = 0; |
| 425 | private static final int SELECT_P3 = 0x10; |
| 426 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 427 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 428 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 429 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 430 | /** The singleton instance. */ |
| 431 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 432 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 434 | private final PhoneGlobals mApp; |
| 435 | private final CallManager mCM; |
| 436 | private final ImsResolver mImsResolver; |
| 437 | private final SatelliteServiceController mSatelliteServiceController; |
| 438 | private final UserManager mUserManager; |
| 439 | private final AppOpsManager mAppOps; |
| 440 | private final MainThreadHandler mMainThreadHandler; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 441 | private final SubscriptionController mSubscriptionController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 442 | private final SharedPreferences mTelephonySharedPreferences; |
| 443 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 444 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 446 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 447 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 448 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 449 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 450 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 451 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 452 | /** |
| 453 | * Map key: subId, value: callback to get error code of the provision request. |
| 454 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 455 | private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks = |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 456 | new ConcurrentHashMap<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 457 | /** |
| 458 | * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants. |
| 459 | */ |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 460 | private final ConcurrentHashMap<Integer, SatellitePositionUpdateHandler> |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 461 | mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>(); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 462 | /** |
| 463 | * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants. |
| 464 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 465 | private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler> |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 466 | mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>(); |
| 467 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 468 | private Boolean mIsSatelliteSupported = null; |
| 469 | private final Object mIsSatelliteSupportedLock = new Object(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 470 | private final ResultReceiver mSatelliteSupportedReceiver; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 471 | /** |
| 472 | * {@code true} to use the vendor satellite service and {@code false} to use the HAL. |
| 473 | */ |
| 474 | private final boolean mIsSatelliteServiceSupported = false; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 475 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 476 | /** |
| 477 | * Map key: subId, value: SatelliteStateChangeHandler to notify registrants. |
| 478 | */ |
| 479 | private ConcurrentHashMap<Integer, SatelliteStateListenerHandler> |
| 480 | mSatelliteStateListenerHandlers = new ConcurrentHashMap<>(); |
| 481 | |
| 482 | /** |
| 483 | * Map key: subId, value: SatelliteDatagramListenerHandler to notify registrants. |
| 484 | */ |
| 485 | private ConcurrentHashMap<Integer, SatelliteDatagramListenerHandler> |
| 486 | mSatelliteDatagramListenerHandlers = new ConcurrentHashMap<>(); |
| 487 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 488 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 489 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 490 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 491 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 492 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 493 | // String to store multi SIM allowed |
| 494 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 495 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 496 | // The AID of ISD-R. |
| 497 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 498 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 499 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 500 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 501 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 502 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 503 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 504 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 505 | 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] | 506 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 507 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 508 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 509 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 510 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 511 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 512 | */ |
| 513 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 514 | "reset_network_erase_modem_config_enabled"; |
| 515 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 516 | 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] | 517 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 518 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 519 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 520 | /** |
| 521 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 522 | * one ICCID active at the same time. |
| 523 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 524 | * |
| 525 | * @hide |
| 526 | */ |
| 527 | @ChangeId |
| 528 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 529 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 530 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 531 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 532 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 533 | * operation fails. |
| 534 | */ |
| 535 | @ChangeId |
| 536 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 537 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 538 | |
| 539 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 540 | * A request object to use for transmitting data to an ICC. |
| 541 | */ |
| 542 | private static final class IccAPDUArgument { |
| 543 | public int channel, cla, command, p1, p2, p3; |
| 544 | public String data; |
| 545 | |
| 546 | public IccAPDUArgument(int channel, int cla, int command, |
| 547 | int p1, int p2, int p3, String data) { |
| 548 | this.channel = channel; |
| 549 | this.cla = cla; |
| 550 | this.command = command; |
| 551 | this.p1 = p1; |
| 552 | this.p2 = p2; |
| 553 | this.p3 = p3; |
| 554 | this.data = data; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 559 | * A request object to use for transmitting data to an ICC. |
| 560 | */ |
| 561 | private static final class ManualNetworkSelectionArgument { |
| 562 | public OperatorInfo operatorInfo; |
| 563 | public boolean persistSelection; |
| 564 | |
| 565 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 566 | this.operatorInfo = operatorInfo; |
| 567 | this.persistSelection = persistSelection; |
| 568 | } |
| 569 | } |
| 570 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 571 | private static final class PurchasePremiumCapabilityArgument { |
| 572 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 573 | public @NonNull IIntegerConsumer callback; |
| 574 | |
| 575 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 576 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 577 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 578 | this.callback = callback; |
| 579 | } |
| 580 | } |
| 581 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 582 | private static final class ProvisionSatelliteServiceArgument { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 583 | public @NonNull String token; |
| 584 | public @NonNull Consumer<Integer> callback; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 585 | public int subId; |
| 586 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 587 | ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) { |
| 588 | this.token = token; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 589 | this.callback = callback; |
| 590 | this.subId = subId; |
| 591 | } |
| 592 | } |
| 593 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 594 | private static final class SendSatelliteDatagramArgument { |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 595 | public long datagramId; |
| 596 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 597 | public @SatelliteManager.DatagramType int datagramType; |
| 598 | public @NonNull SatelliteDatagram datagram; |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame^] | 599 | |
| 600 | public boolean needFullScreenPointingUI; |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 601 | public @NonNull ResultReceiver result; |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 602 | |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 603 | SendSatelliteDatagramArgument(long datagramId, |
| 604 | @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame^] | 605 | SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 606 | ResultReceiver result) { |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 607 | this.datagramId = datagramId; |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 608 | this.datagramType = datagramType; |
| 609 | this.datagram = datagram; |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame^] | 610 | this.needFullScreenPointingUI = needFullScreenPointingUI; |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 611 | this.result = result; |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 615 | private static final class SatellitePositionUpdateArgument { |
| 616 | public @NonNull Consumer<Integer> errorCallback; |
| 617 | public @NonNull ISatellitePositionUpdateCallback callback; |
| 618 | public int subId; |
| 619 | |
| 620 | SatellitePositionUpdateArgument(Consumer<Integer> errorCallback, |
| 621 | ISatellitePositionUpdateCallback callback, int subId) { |
| 622 | this.errorCallback = errorCallback; |
| 623 | this.callback = callback; |
| 624 | this.subId = subId; |
| 625 | } |
| 626 | } |
| 627 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 628 | private static final class SatellitePositionUpdateHandler extends Handler { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 629 | public static final int EVENT_POSITION_INFO_CHANGED = 1; |
| 630 | public static final int EVENT_DATAGRAM_TRANSFER_STATE_CHANGED = 2; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 631 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 632 | private final ConcurrentHashMap<IBinder, ISatellitePositionUpdateCallback> mListeners; |
| 633 | SatellitePositionUpdateHandler(Looper looper) { |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 634 | super(looper); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 635 | mListeners = new ConcurrentHashMap<>(); |
| 636 | } |
| 637 | |
| 638 | public void addListener(ISatellitePositionUpdateCallback listener) { |
| 639 | mListeners.put(listener.asBinder(), listener); |
| 640 | } |
| 641 | |
| 642 | public void removeListener(ISatellitePositionUpdateCallback listener) { |
| 643 | mListeners.remove(listener.asBinder()); |
| 644 | } |
| 645 | |
| 646 | public boolean hasListeners() { |
| 647 | return !mListeners.isEmpty(); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | @Override |
| 651 | public void handleMessage(@NonNull Message msg) { |
| 652 | switch (msg.what) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 653 | case EVENT_POSITION_INFO_CHANGED: { |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 654 | AsyncResult ar = (AsyncResult) msg.obj; |
| 655 | PointingInfo pointingInfo = (PointingInfo) ar.result; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 656 | mListeners.values().forEach(listener -> { |
| 657 | try { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 658 | listener.onSatellitePositionChanged(pointingInfo); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 659 | } catch (RemoteException e) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 660 | log("EVENT_POSITION_INFO_CHANGED RemoteException: " + e); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 661 | } |
| 662 | }); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 663 | break; |
| 664 | } |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 665 | case EVENT_DATAGRAM_TRANSFER_STATE_CHANGED: { |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 666 | AsyncResult ar = (AsyncResult) msg.obj; |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 667 | int result = (int) ar.result; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 668 | mListeners.values().forEach(listener -> { |
| 669 | try { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 670 | // TODO: process and return the rest of the values correctly |
| 671 | listener.onDatagramTransferStateChanged(result, 0, 0, 0); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 672 | } catch (RemoteException e) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 673 | log("EVENT_DATAGRAM_TRANSFER_STATE_CHANGED RemoteException: " + e); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 674 | } |
| 675 | }); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 676 | break; |
| 677 | } |
| 678 | default: |
| 679 | loge("SatellitePositionUpdateHandler unknown event: " + msg.what); |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 684 | private static final class SatelliteProvisionStateChangedHandler extends Handler { |
| 685 | public static final int EVENT_PROVISION_STATE_CHANGED = 1; |
| 686 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 687 | private final ConcurrentHashMap<IBinder, ISatelliteProvisionStateCallback> mListeners; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 688 | private final int mSubId; |
| 689 | |
| 690 | SatelliteProvisionStateChangedHandler(Looper looper, int subId) { |
| 691 | super(looper); |
| 692 | mListeners = new ConcurrentHashMap<>(); |
| 693 | mSubId = subId; |
| 694 | } |
| 695 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 696 | public void addListener(ISatelliteProvisionStateCallback listener) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 697 | mListeners.put(listener.asBinder(), listener); |
| 698 | } |
| 699 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 700 | public void removeListener(ISatelliteProvisionStateCallback listener) { |
| 701 | mListeners.remove(listener.asBinder()); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | @Override |
| 705 | public void handleMessage(@NonNull Message msg) { |
| 706 | switch (msg.what) { |
| 707 | case EVENT_PROVISION_STATE_CHANGED: { |
| 708 | AsyncResult ar = (AsyncResult) msg.obj; |
| 709 | boolean provisioned = (boolean) ar.userObj; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 710 | log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 711 | + ", provisioned=" + provisioned); |
| 712 | mListeners.values().forEach(listener -> { |
| 713 | try { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 714 | listener.onSatelliteProvisionStateChanged(provisioned); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 715 | } catch (RemoteException e) { |
| 716 | log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e); |
| 717 | } |
| 718 | }); |
| 719 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 720 | setSatelliteProvisioned(provisioned); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 721 | /** |
| 722 | * TODO: Take bugreport if provisioned is true and user did not initiate the |
| 723 | * provision procedure for the corresponding subscription. |
| 724 | */ |
| 725 | break; |
| 726 | } |
| 727 | default: |
| 728 | loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what); |
| 729 | } |
| 730 | } |
| 731 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 732 | private void setSatelliteProvisioned(boolean isProvisioned) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 733 | if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 734 | SubscriptionManager.setSubscriptionProperty( |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 735 | mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 736 | } else { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 737 | //TODO (b/267826133): set via SatelliteController. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 742 | private static final class SatelliteStateListenerHandler extends Handler { |
| 743 | public static final int EVENT_SATELLITE_MODEM_STATE_CHANGE = 1; |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 744 | public static final int EVENT_PENDING_DATAGRAM_COUNT = 2; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 745 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 746 | private final ConcurrentHashMap<IBinder, ISatelliteStateCallback> mListeners; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 747 | private final int mSubId; |
| 748 | |
| 749 | SatelliteStateListenerHandler(Looper looper, int subId) { |
| 750 | super(looper); |
| 751 | mSubId = subId; |
| 752 | mListeners = new ConcurrentHashMap<>(); |
| 753 | } |
| 754 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 755 | public void addListener(ISatelliteStateCallback listener) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 756 | mListeners.put(listener.asBinder(), listener); |
| 757 | } |
| 758 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 759 | public void removeListener(ISatelliteStateCallback listener) { |
| 760 | mListeners.remove(listener.asBinder()); |
| 761 | } |
| 762 | |
| 763 | public boolean hasListeners() { |
| 764 | return !mListeners.isEmpty(); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | @Override |
| 768 | public void handleMessage(@NonNull Message msg) { |
| 769 | switch (msg.what) { |
| 770 | case EVENT_SATELLITE_MODEM_STATE_CHANGE : { |
| 771 | AsyncResult ar = (AsyncResult) msg.obj; |
| 772 | int state = (int) ar.result; |
| 773 | log("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId |
| 774 | + ", state=" + state); |
| 775 | mListeners.values().forEach(listener -> { |
| 776 | try { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 777 | listener.onSatelliteModemStateChanged(state); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 778 | } catch (RemoteException e) { |
| 779 | log("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e); |
| 780 | } |
| 781 | }); |
| 782 | break; |
| 783 | } |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 784 | case EVENT_PENDING_DATAGRAM_COUNT: { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 785 | AsyncResult ar = (AsyncResult) msg.obj; |
| 786 | int count = (int) ar.result; |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 787 | log("Received EVENT_PENDING_DATAGRAM_COUNT for subId=" + mSubId |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 788 | + ", count=" + count); |
| 789 | mListeners.values().forEach(listener -> { |
| 790 | try { |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 791 | listener.onPendingDatagramCount(count); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 792 | } catch (RemoteException e) { |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 793 | log("EVENT_PENDING_DATAGRAM_COUNT RemoteException: " + e); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 794 | } |
| 795 | }); |
| 796 | break; |
| 797 | } |
| 798 | default: |
| 799 | loge("SatelliteStateListenerHandler unknown event: " + msg.what); |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 804 | /** Callback used by datagram receiver app to send ack back to Telephony. */ |
| 805 | private static final ISatelliteDatagramReceiverAck.Stub mDatagramReceiverAck = |
| 806 | new ISatelliteDatagramReceiverAck.Stub() { |
| 807 | /** |
| 808 | * This callback will be used by datagram receiver app to send ack back to |
| 809 | * Telephony. If the callback is not received within five minutes, |
| 810 | * then Telephony will resend the datagram again. |
| 811 | * |
| 812 | * @param datagramId An id that uniquely identifies datagram |
| 813 | * received by satellite datagram receiver app. |
| 814 | * This should match with datagramId passed in |
| 815 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived( |
| 816 | * long, SatelliteDatagram, int, ISatelliteDatagramReceiverAck)}. |
| 817 | * Upon receiving the ack, Telephony will remove the datagram from |
| 818 | * the persistent memory. |
| 819 | */ |
| 820 | public void acknowledgeSatelliteDatagramReceived(long datagramId) { |
| 821 | |
| 822 | } |
| 823 | }; |
| 824 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 825 | private static final class SatelliteDatagramListenerHandler extends Handler { |
| 826 | public static final int EVENT_SATELLITE_DATAGRAMS_RECEIVED = 1; |
| 827 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 828 | private final ConcurrentHashMap<IBinder, ISatelliteDatagramCallback> mListeners; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 829 | private final int mSubId; |
| 830 | |
| 831 | SatelliteDatagramListenerHandler(Looper looper, int subId) { |
| 832 | super(looper); |
| 833 | mSubId = subId; |
| 834 | mListeners = new ConcurrentHashMap<>(); |
| 835 | } |
| 836 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 837 | public void addListener(ISatelliteDatagramCallback listener) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 838 | mListeners.put(listener.asBinder(), listener); |
| 839 | } |
| 840 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 841 | public void removeListener(ISatelliteDatagramCallback listener) { |
| 842 | mListeners.remove(listener.asBinder()); |
| 843 | } |
| 844 | |
| 845 | public boolean hasListeners() { |
| 846 | return !mListeners.isEmpty(); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | @Override |
| 850 | public void handleMessage(@NonNull Message msg) { |
| 851 | switch (msg.what) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 852 | case EVENT_SATELLITE_DATAGRAMS_RECEIVED: { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 853 | AsyncResult ar = (AsyncResult) msg.obj; |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 854 | Pair<SatelliteDatagram[], Integer> result = |
| 855 | (Pair<SatelliteDatagram[], Integer>) ar.result; |
| 856 | SatelliteDatagram[] satelliteDatagrams = result.first; |
| 857 | int pendingCount = result.second; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 858 | |
| 859 | log("Received EVENT_SATELLITE_DATAGRAMS_RECEIVED for subId=" + mSubId); |
| 860 | mListeners.values().forEach(listener -> { |
| 861 | try { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 862 | for (int i = 0; i < satelliteDatagrams.length; i++) { |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 863 | // TODO (b/269637555): wait for ack and retry after 5mins |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 864 | listener.onSatelliteDatagramReceived( |
| 865 | // TODO: create a new datagramId every time |
| 866 | i, satelliteDatagrams[i], pendingCount, |
| 867 | // TODO: create a new instance of ack that will resend |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 868 | mDatagramReceiverAck); |
| 869 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 870 | } catch (RemoteException e) { |
| 871 | log("EVENT_SATELLITE_DATAGRAMS_RECEIVED RemoteException: " + e); |
| 872 | } |
| 873 | }); |
| 874 | break; |
| 875 | } |
| 876 | default: |
| 877 | loge("SatelliteDatagramListenerHandler unknown event: " + msg.what); |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 882 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 883 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 884 | * request after sending. The main thread will notify the request when it is complete. |
| 885 | */ |
| 886 | private static final class MainThreadRequest { |
| 887 | /** The argument to use for the request */ |
| 888 | public Object argument; |
| 889 | /** The result of the request that is run on the main thread */ |
| 890 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 891 | // The subscriber id that this request applies to. Defaults to |
| 892 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 893 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 894 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 895 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 896 | public Phone phone; |
| 897 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 898 | public WorkSource workSource; |
| 899 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 900 | public MainThreadRequest(Object argument) { |
| 901 | this.argument = argument; |
| 902 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 903 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 904 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 905 | this.argument = argument; |
| 906 | if (phone != null) { |
| 907 | this.phone = phone; |
| 908 | } |
| 909 | this.workSource = workSource; |
| 910 | } |
| 911 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 912 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 913 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 914 | if (subId != null) { |
| 915 | this.subId = subId; |
| 916 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 917 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 918 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 921 | private static final class IncomingThirdPartyCallArgs { |
| 922 | public final ComponentName component; |
| 923 | public final String callId; |
| 924 | public final String callerDisplayName; |
| 925 | |
| 926 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 927 | String callerDisplayName) { |
| 928 | this.component = component; |
| 929 | this.callId = callId; |
| 930 | this.callerDisplayName = callerDisplayName; |
| 931 | } |
| 932 | } |
| 933 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 934 | /** |
| 935 | * A handler that processes messages on the main thread in the phone process. Since many |
| 936 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 937 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 938 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 939 | * on, which will be notified when the operation completes and will contain the result of the |
| 940 | * request. |
| 941 | * |
| 942 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 943 | * note that request.result must be set to something non-null for the calling thread to |
| 944 | * unblock. |
| 945 | */ |
| 946 | private final class MainThreadHandler extends Handler { |
| 947 | @Override |
| 948 | public void handleMessage(Message msg) { |
| 949 | MainThreadRequest request; |
| 950 | Message onCompleted; |
| 951 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 952 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 953 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 954 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 955 | |
| 956 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 957 | case CMD_HANDLE_USSD_REQUEST: { |
| 958 | request = (MainThreadRequest) msg.obj; |
| 959 | final Phone phone = getPhoneFromRequest(request); |
| 960 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 961 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 962 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 963 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 964 | if (!isUssdApiAllowed(request.subId)) { |
| 965 | // Carrier does not support use of this API, return failure. |
| 966 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 967 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 968 | Bundle returnData = new Bundle(); |
| 969 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 970 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 971 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 972 | request.result = true; |
| 973 | notifyRequester(request); |
| 974 | return; |
| 975 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 976 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 977 | try { |
| 978 | request.result = phone != null |
| 979 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 980 | } catch (CallStateException cse) { |
| 981 | request.result = false; |
| 982 | } |
| 983 | // Wake up the requesting thread |
| 984 | notifyRequester(request); |
| 985 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 988 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 989 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 990 | final Phone phone = getPhoneFromRequest(request); |
| 991 | request.result = phone != null ? |
| 992 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 993 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 994 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 995 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 996 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 997 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 998 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 999 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1000 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1001 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1002 | uiccPort = getUiccPortFromRequest(request); |
| 1003 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1004 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1005 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1006 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1007 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1008 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1009 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1010 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1011 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 1012 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 1013 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1014 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1015 | break; |
| 1016 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1017 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1018 | ar = (AsyncResult) msg.obj; |
| 1019 | request = (MainThreadRequest) ar.userObj; |
| 1020 | if (ar.exception == null && ar.result != null) { |
| 1021 | request.result = ar.result; |
| 1022 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1023 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1024 | if (ar.result == null) { |
| 1025 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1026 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1027 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1028 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1029 | } else { |
| 1030 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 1031 | } |
| 1032 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1033 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1034 | break; |
| 1035 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1036 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 1037 | request = (MainThreadRequest) msg.obj; |
| 1038 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1039 | uiccPort = getUiccPortFromRequest(request); |
| 1040 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1041 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1042 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1043 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1044 | } else { |
| 1045 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1046 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1047 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1048 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 1049 | iccArgument.p2, |
| 1050 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1051 | } |
| 1052 | break; |
| 1053 | |
| 1054 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 1055 | ar = (AsyncResult) msg.obj; |
| 1056 | request = (MainThreadRequest) ar.userObj; |
| 1057 | if (ar.exception == null && ar.result != null) { |
| 1058 | request.result = ar.result; |
| 1059 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1060 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1061 | if (ar.result == null) { |
| 1062 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 1063 | } else if (ar.exception instanceof CommandException) { |
| 1064 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 1065 | ar.exception); |
| 1066 | } else { |
| 1067 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 1068 | } |
| 1069 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1070 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1071 | break; |
| 1072 | |
| 1073 | case CMD_EXCHANGE_SIM_IO: |
| 1074 | request = (MainThreadRequest) msg.obj; |
| 1075 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1076 | uiccPort = getUiccPortFromRequest(request); |
| 1077 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1078 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1079 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1080 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1081 | } else { |
| 1082 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 1083 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1084 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1085 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 1086 | iccArgument.data, onCompleted); |
| 1087 | } |
| 1088 | break; |
| 1089 | |
| 1090 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 1091 | ar = (AsyncResult) msg.obj; |
| 1092 | request = (MainThreadRequest) ar.userObj; |
| 1093 | if (ar.exception == null && ar.result != null) { |
| 1094 | request.result = ar.result; |
| 1095 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1096 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1097 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1098 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1099 | break; |
| 1100 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 1101 | case CMD_SEND_ENVELOPE: |
| 1102 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1103 | uiccPort = getUiccPortFromRequest(request); |
| 1104 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1105 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1106 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1107 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1108 | } else { |
| 1109 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1110 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1111 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 1112 | break; |
| 1113 | |
| 1114 | case EVENT_SEND_ENVELOPE_DONE: |
| 1115 | ar = (AsyncResult) msg.obj; |
| 1116 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 1117 | if (ar.exception == null && ar.result != null) { |
| 1118 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 1119 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1120 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 1121 | if (ar.result == null) { |
| 1122 | loge("sendEnvelopeWithStatus: Empty response"); |
| 1123 | } else if (ar.exception instanceof CommandException) { |
| 1124 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 1125 | ar.exception); |
| 1126 | } else { |
| 1127 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 1128 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 1129 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1130 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 1131 | break; |
| 1132 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1133 | case CMD_OPEN_CHANNEL: |
| 1134 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1135 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 1136 | IccLogicalChannelRequest openChannelRequest = |
| 1137 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1138 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1139 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 1140 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1141 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1142 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1143 | } else { |
| 1144 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 1145 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 1146 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1147 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1148 | break; |
| 1149 | |
| 1150 | case EVENT_OPEN_CHANNEL_DONE: |
| 1151 | ar = (AsyncResult) msg.obj; |
| 1152 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1153 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1154 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1155 | int[] result = (int[]) ar.result; |
| 1156 | int channelId = result[0]; |
| 1157 | byte[] selectResponse = null; |
| 1158 | if (result.length > 1) { |
| 1159 | selectResponse = new byte[result.length - 1]; |
| 1160 | for (int i = 1; i < result.length; ++i) { |
| 1161 | selectResponse[i - 1] = (byte) result[i]; |
| 1162 | } |
| 1163 | } |
| 1164 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1165 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 1166 | |
| 1167 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 1168 | if (uiccPort == null) { |
| 1169 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 1170 | } else { |
| 1171 | IccLogicalChannelRequest channelRequest = |
| 1172 | (IccLogicalChannelRequest) request.argument; |
| 1173 | channelRequest.channel = channelId; |
| 1174 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 1175 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1176 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1177 | if (ar.result == null) { |
| 1178 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1179 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1180 | if (ar.exception != null) { |
| 1181 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 1182 | } |
| 1183 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 1184 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 1185 | if (ar.exception instanceof CommandException) { |
| 1186 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1187 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 1188 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 1189 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 1190 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 1191 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1195 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1196 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 1197 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1198 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1199 | break; |
| 1200 | |
| 1201 | case CMD_CLOSE_CHANNEL: |
| 1202 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1203 | uiccPort = getUiccPortFromRequest(request); |
| 1204 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1205 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 1206 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1207 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1208 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1209 | } else { |
| 1210 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1211 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1212 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1213 | break; |
| 1214 | |
| 1215 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1216 | ar = (AsyncResult) msg.obj; |
| 1217 | request = (MainThreadRequest) ar.userObj; |
| 1218 | if (ar.exception == null) { |
| 1219 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 1220 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 1221 | if (uiccPort == null) { |
| 1222 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 1223 | } else { |
| 1224 | final int channelId = (Integer) request.argument; |
| 1225 | uiccPort.onLogicalChannelClosed(channelId); |
| 1226 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1227 | } else { |
| 1228 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1229 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1230 | if (ar.exception instanceof CommandException) { |
| 1231 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 1232 | CommandException.Error error = |
| 1233 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 1234 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1235 | // should only throw exceptions from the binder threads. |
| 1236 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1237 | "iccCloseLogicalChannel: invalid argument "); |
| 1238 | } |
| 1239 | } else { |
| 1240 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 1241 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 1242 | request.result = (exception != null) ? exception : |
| 1243 | new IllegalStateException( |
| 1244 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 1245 | } |
| 1246 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1247 | break; |
| 1248 | |
| 1249 | case CMD_NV_READ_ITEM: |
| 1250 | request = (MainThreadRequest) msg.obj; |
| 1251 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1252 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 1253 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1254 | break; |
| 1255 | |
| 1256 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1257 | ar = (AsyncResult) msg.obj; |
| 1258 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1259 | if (ar.exception == null && ar.result != null) { |
| 1260 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1261 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1262 | request.result = ""; |
| 1263 | if (ar.result == null) { |
| 1264 | loge("nvReadItem: Empty response"); |
| 1265 | } else if (ar.exception instanceof CommandException) { |
| 1266 | loge("nvReadItem: CommandException: " + |
| 1267 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1268 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1269 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1270 | } |
| 1271 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1272 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1273 | break; |
| 1274 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1275 | case CMD_NV_WRITE_ITEM: |
| 1276 | request = (MainThreadRequest) msg.obj; |
| 1277 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 1278 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1279 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1280 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1281 | break; |
| 1282 | |
| 1283 | case EVENT_NV_WRITE_ITEM_DONE: |
| 1284 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 1285 | break; |
| 1286 | |
| 1287 | case CMD_NV_WRITE_CDMA_PRL: |
| 1288 | request = (MainThreadRequest) msg.obj; |
| 1289 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1290 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1291 | break; |
| 1292 | |
| 1293 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 1294 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 1295 | break; |
| 1296 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1297 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1298 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1299 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1300 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1301 | break; |
| 1302 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1303 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 1304 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1305 | break; |
| 1306 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1307 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 1308 | request = (MainThreadRequest) msg.obj; |
| 1309 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 1310 | request); |
| 1311 | Phone phone = getPhoneFromRequest(request); |
| 1312 | if (phone != null) { |
| 1313 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 1314 | } else { |
| 1315 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 1316 | request.result = false; |
| 1317 | notifyRequester(request); |
| 1318 | } |
| 1319 | break; |
| 1320 | } |
| 1321 | |
| 1322 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 1323 | ar = (AsyncResult) msg.obj; |
| 1324 | request = (MainThreadRequest) ar.userObj; |
| 1325 | if (ar.exception == null && ar.result != null) { |
| 1326 | request.result = ar.result; |
| 1327 | } else { |
| 1328 | // request.result must be set to something non-null |
| 1329 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1330 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1331 | request.result = ar.result; |
| 1332 | } else { |
| 1333 | request.result = false; |
| 1334 | } |
| 1335 | if (ar.result == null) { |
| 1336 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1337 | } else if (ar.exception instanceof CommandException) { |
| 1338 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1339 | + ar.exception); |
| 1340 | } else { |
| 1341 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1342 | } |
| 1343 | } |
| 1344 | notifyRequester(request); |
| 1345 | break; |
| 1346 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1347 | case CMD_IS_VONR_ENABLED: { |
| 1348 | request = (MainThreadRequest) msg.obj; |
| 1349 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1350 | request); |
| 1351 | Phone phone = getPhoneFromRequest(request); |
| 1352 | if (phone != null) { |
| 1353 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1354 | } else { |
| 1355 | loge("isVoNrEnabled: No phone object"); |
| 1356 | request.result = false; |
| 1357 | notifyRequester(request); |
| 1358 | } |
| 1359 | break; |
| 1360 | } |
| 1361 | |
| 1362 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1363 | ar = (AsyncResult) msg.obj; |
| 1364 | request = (MainThreadRequest) ar.userObj; |
| 1365 | if (ar.exception == null && ar.result != null) { |
| 1366 | request.result = ar.result; |
| 1367 | } else { |
| 1368 | // request.result must be set to something non-null |
| 1369 | // for the calling thread to unblock |
| 1370 | if (ar.result != null) { |
| 1371 | request.result = ar.result; |
| 1372 | } else { |
| 1373 | request.result = false; |
| 1374 | } |
| 1375 | if (ar.result == null) { |
| 1376 | loge("isVoNrEnabled: Empty response"); |
| 1377 | } else if (ar.exception instanceof CommandException) { |
| 1378 | loge("isVoNrEnabled: CommandException: " |
| 1379 | + ar.exception); |
| 1380 | } else { |
| 1381 | loge("isVoNrEnabled: Unknown exception"); |
| 1382 | } |
| 1383 | } |
| 1384 | notifyRequester(request); |
| 1385 | break; |
| 1386 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1387 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1388 | request = (MainThreadRequest) msg.obj; |
| 1389 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1390 | Phone phone = getPhoneFromRequest(request); |
| 1391 | if (phone != null) { |
| 1392 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1393 | request.workSource); |
| 1394 | } else { |
| 1395 | loge("enableNrDualConnectivity: No phone object"); |
| 1396 | request.result = |
| 1397 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1398 | notifyRequester(request); |
| 1399 | } |
| 1400 | break; |
| 1401 | } |
| 1402 | |
| 1403 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1404 | ar = (AsyncResult) msg.obj; |
| 1405 | request = (MainThreadRequest) ar.userObj; |
| 1406 | if (ar.exception == null) { |
| 1407 | request.result = |
| 1408 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1409 | } else { |
| 1410 | request.result = |
| 1411 | TelephonyManager |
| 1412 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1413 | if (ar.exception instanceof CommandException) { |
| 1414 | CommandException.Error error = |
| 1415 | ((CommandException) (ar.exception)).getCommandError(); |
| 1416 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1417 | request.result = |
| 1418 | TelephonyManager |
| 1419 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1420 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1421 | request.result = |
| 1422 | TelephonyManager |
| 1423 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1424 | } |
| 1425 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1426 | + ar.exception); |
| 1427 | } else { |
| 1428 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1429 | } |
| 1430 | } |
| 1431 | notifyRequester(request); |
| 1432 | break; |
| 1433 | } |
| 1434 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1435 | case CMD_ENABLE_VONR: { |
| 1436 | request = (MainThreadRequest) msg.obj; |
| 1437 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1438 | Phone phone = getPhoneFromRequest(request); |
| 1439 | if (phone != null) { |
| 1440 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1441 | request.workSource); |
| 1442 | } else { |
| 1443 | loge("setVoNrEnabled: No phone object"); |
| 1444 | request.result = |
| 1445 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1446 | notifyRequester(request); |
| 1447 | } |
| 1448 | break; |
| 1449 | } |
| 1450 | |
| 1451 | case EVENT_ENABLE_VONR_DONE: { |
| 1452 | ar = (AsyncResult) msg.obj; |
| 1453 | request = (MainThreadRequest) ar.userObj; |
| 1454 | if (ar.exception == null) { |
| 1455 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1456 | } else { |
| 1457 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1458 | if (ar.exception instanceof CommandException) { |
| 1459 | CommandException.Error error = |
| 1460 | ((CommandException) (ar.exception)).getCommandError(); |
| 1461 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1462 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1463 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1464 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1465 | } else { |
| 1466 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1467 | } |
| 1468 | loge("setVoNrEnabled" + ": CommandException: " |
| 1469 | + ar.exception); |
| 1470 | } else { |
| 1471 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1472 | } |
| 1473 | } |
| 1474 | notifyRequester(request); |
| 1475 | break; |
| 1476 | } |
| 1477 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1478 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1479 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1480 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1481 | request); |
| 1482 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1483 | break; |
| 1484 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1485 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1486 | ar = (AsyncResult) msg.obj; |
| 1487 | request = (MainThreadRequest) ar.userObj; |
| 1488 | if (ar.exception == null && ar.result != null) { |
| 1489 | request.result = ar.result; // Integer |
| 1490 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1491 | // request.result must be set to something non-null |
| 1492 | // for the calling thread to unblock |
| 1493 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1494 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1495 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1496 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1497 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1498 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1499 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1500 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1501 | } |
| 1502 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1503 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1504 | break; |
| 1505 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1506 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1507 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1508 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1509 | request); |
| 1510 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1511 | (Pair<Integer, Long>) request.argument; |
| 1512 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1513 | reasonWithNetworkTypes.first, |
| 1514 | reasonWithNetworkTypes.second, |
| 1515 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1516 | break; |
| 1517 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1518 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1519 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1520 | break; |
| 1521 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1522 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1523 | request = (MainThreadRequest)msg.obj; |
| 1524 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1525 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1526 | break; |
| 1527 | |
| 1528 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1529 | ar = (AsyncResult)msg.obj; |
| 1530 | request = (MainThreadRequest)ar.userObj; |
| 1531 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1532 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1535 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1536 | request = (MainThreadRequest) msg.obj; |
| 1537 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1538 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1539 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1540 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1541 | break; |
| 1542 | |
| 1543 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1544 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1545 | break; |
| 1546 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1547 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1548 | request = (MainThreadRequest) msg.obj; |
| 1549 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1550 | request); |
| 1551 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1552 | break; |
| 1553 | |
| 1554 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1555 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1556 | break; |
| 1557 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1558 | case CMD_PERFORM_NETWORK_SCAN: |
| 1559 | request = (MainThreadRequest) msg.obj; |
| 1560 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1561 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1562 | break; |
| 1563 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1564 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1565 | request = (MainThreadRequest) msg.obj; |
| 1566 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1567 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1568 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1569 | request.argument; |
| 1570 | int callForwardingReason = args.first; |
| 1571 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1572 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1573 | } |
| 1574 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1575 | ar = (AsyncResult) msg.obj; |
| 1576 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1577 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1578 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1579 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1580 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1581 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1582 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1583 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1584 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1585 | // any service for voice call. |
| 1586 | if ((callForwardInfo.serviceClass |
| 1587 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1588 | callForwardingInfo = new CallForwardingInfo( |
| 1589 | callForwardInfo.status |
| 1590 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1591 | callForwardInfo.reason, |
| 1592 | callForwardInfo.number, |
| 1593 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1594 | break; |
| 1595 | } |
| 1596 | } |
| 1597 | // Didn't find a call forward info for voice call. |
| 1598 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1599 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1600 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1601 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1602 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1603 | } else { |
| 1604 | if (ar.result == null) { |
| 1605 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1606 | } |
| 1607 | if (ar.exception != null) { |
| 1608 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1609 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1610 | int errorCode = TelephonyManager |
| 1611 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1612 | if (ar.exception instanceof CommandException) { |
| 1613 | CommandException.Error error = |
| 1614 | ((CommandException) (ar.exception)).getCommandError(); |
| 1615 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1616 | errorCode = TelephonyManager |
| 1617 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1618 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1619 | errorCode = TelephonyManager |
| 1620 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1621 | } |
| 1622 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1623 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1624 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1625 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1626 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1627 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1628 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1629 | request = (MainThreadRequest) msg.obj; |
| 1630 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1631 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1632 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1633 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1634 | request.argument).first; |
| 1635 | request.phone.setCallForwardingOption( |
| 1636 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1637 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1638 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1639 | callForwardingInfoToSet.getReason(), |
| 1640 | callForwardingInfoToSet.getNumber(), |
| 1641 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1642 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1643 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1644 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1645 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1646 | ar = (AsyncResult) msg.obj; |
| 1647 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1648 | Consumer<Integer> callback = |
| 1649 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1650 | request.argument).second; |
| 1651 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1652 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1653 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1654 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1655 | if (ar.exception instanceof CommandException) { |
| 1656 | CommandException.Error error = |
| 1657 | ((CommandException) (ar.exception)).getCommandError(); |
| 1658 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1659 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1660 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1661 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1662 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1663 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1664 | } |
| 1665 | } |
| 1666 | callback.accept(errorCode); |
| 1667 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1668 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1669 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1670 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1671 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1672 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1673 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1674 | request = (MainThreadRequest) msg.obj; |
| 1675 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1676 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1677 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1678 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1679 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1680 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1681 | ar = (AsyncResult) msg.obj; |
| 1682 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1683 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1684 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1685 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1686 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1687 | // Service Class is a bit mask per 3gpp 27.007. |
| 1688 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1689 | if (callForwardResults.length > 1 |
| 1690 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1691 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1692 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1693 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1694 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1695 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1696 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1697 | } |
| 1698 | } else { |
| 1699 | if (ar.result == null) { |
| 1700 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1701 | } |
| 1702 | if (ar.exception != null) { |
| 1703 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1704 | } |
| 1705 | if (ar.exception instanceof CommandException) { |
| 1706 | CommandException.Error error = |
| 1707 | ((CommandException) (ar.exception)).getCommandError(); |
| 1708 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1709 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1710 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1711 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1712 | callWaitingStatus = |
| 1713 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1714 | } |
| 1715 | } |
| 1716 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1717 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1718 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1719 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1720 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1721 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1722 | request = (MainThreadRequest) msg.obj; |
| 1723 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1724 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1725 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1726 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1727 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1728 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1729 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1730 | ar = (AsyncResult) msg.obj; |
| 1731 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1732 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1733 | Consumer<Integer> callback = |
| 1734 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1735 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1736 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1737 | if (ar.exception instanceof CommandException) { |
| 1738 | CommandException.Error error = |
| 1739 | ((CommandException) (ar.exception)).getCommandError(); |
| 1740 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1741 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1742 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1743 | callback.accept( |
| 1744 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1745 | } else { |
| 1746 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1747 | } |
| 1748 | } else { |
| 1749 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1750 | } |
| 1751 | } else { |
| 1752 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1753 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1754 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1755 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1756 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1757 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1758 | ar = (AsyncResult) msg.obj; |
| 1759 | request = (MainThreadRequest) ar.userObj; |
| 1760 | CellNetworkScanResult cellScanResult; |
| 1761 | if (ar.exception == null && ar.result != null) { |
| 1762 | cellScanResult = new CellNetworkScanResult( |
| 1763 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1764 | (List<OperatorInfo>) ar.result); |
| 1765 | } else { |
| 1766 | if (ar.result == null) { |
| 1767 | loge("getCellNetworkScanResults: Empty response"); |
| 1768 | } |
| 1769 | if (ar.exception != null) { |
| 1770 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1771 | } |
| 1772 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1773 | if (ar.exception instanceof CommandException) { |
| 1774 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1775 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1776 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1777 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1778 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1779 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1780 | } |
| 1781 | } |
| 1782 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1783 | } |
| 1784 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1785 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1786 | break; |
| 1787 | |
| 1788 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1789 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1790 | ManualNetworkSelectionArgument selArg = |
| 1791 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1792 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1793 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1794 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1795 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1796 | break; |
| 1797 | |
| 1798 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1799 | ar = (AsyncResult) msg.obj; |
| 1800 | request = (MainThreadRequest) ar.userObj; |
| 1801 | if (ar.exception == null) { |
| 1802 | request.result = true; |
| 1803 | } else { |
| 1804 | request.result = false; |
| 1805 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1806 | } |
| 1807 | notifyRequester(request); |
| 1808 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1809 | break; |
| 1810 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1811 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1812 | request = (MainThreadRequest) msg.obj; |
| 1813 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1814 | if (defaultPhone != null) { |
| 1815 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1816 | } else { |
| 1817 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1818 | Bundle bundle = new Bundle(); |
| 1819 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1820 | new ModemActivityInfo(0, 0, 0, |
| 1821 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1822 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1823 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1824 | break; |
| 1825 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1826 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1827 | ar = (AsyncResult) msg.obj; |
| 1828 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1829 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1830 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1831 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1832 | if (mLastModemActivityInfo == null) { |
| 1833 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1834 | mLastModemActivitySpecificInfo[0] = |
| 1835 | new ActivityStatsTechSpecificInfo( |
| 1836 | 0, |
| 1837 | 0, |
| 1838 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1839 | 0); |
| 1840 | mLastModemActivityInfo = |
| 1841 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1842 | } |
| 1843 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1844 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1845 | // Update the last modem activity info and the result of the request. |
| 1846 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1847 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1848 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1849 | } else { |
| 1850 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1851 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1852 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1853 | // We don't want to return mLastModemActivityInfo which is updated |
| 1854 | // inside mergeModemActivityInfo() |
| 1855 | ret = new ModemActivityInfo( |
| 1856 | mLastModemActivityInfo.getTimestampMillis(), |
| 1857 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1858 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1859 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1860 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1861 | } else { |
| 1862 | if (ar.result == null) { |
| 1863 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1864 | error = TelephonyManager.ModemActivityInfoException |
| 1865 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1866 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1867 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1868 | error = TelephonyManager.ModemActivityInfoException |
| 1869 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1870 | } else { |
| 1871 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1872 | error = TelephonyManager.ModemActivityInfoException |
| 1873 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1874 | } |
| 1875 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1876 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1877 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1878 | bundle.putParcelable( |
| 1879 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1880 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1881 | } else { |
| 1882 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1883 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1884 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1885 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1886 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1887 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1888 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1889 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1890 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1891 | CarrierRestrictionRules argument = |
| 1892 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1893 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1894 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1895 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1896 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1897 | |
| 1898 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1899 | ar = (AsyncResult) msg.obj; |
| 1900 | request = (MainThreadRequest) ar.userObj; |
| 1901 | if (ar.exception == null && ar.result != null) { |
| 1902 | request.result = ar.result; |
| 1903 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1904 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1905 | if (ar.exception instanceof CommandException) { |
| 1906 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1907 | CommandException.Error error = |
| 1908 | ((CommandException) (ar.exception)).getCommandError(); |
| 1909 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1910 | request.result = |
| 1911 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1912 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1913 | } else { |
| 1914 | loge("setAllowedCarriers: Unknown exception"); |
| 1915 | } |
| 1916 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1917 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1918 | break; |
| 1919 | |
| 1920 | case CMD_GET_ALLOWED_CARRIERS: |
| 1921 | request = (MainThreadRequest) msg.obj; |
| 1922 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1923 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1924 | break; |
| 1925 | |
| 1926 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1927 | ar = (AsyncResult) msg.obj; |
| 1928 | request = (MainThreadRequest) ar.userObj; |
| 1929 | if (ar.exception == null && ar.result != null) { |
| 1930 | request.result = ar.result; |
| 1931 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1932 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1933 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1934 | if (ar.result == null) { |
| 1935 | loge("getAllowedCarriers: Empty response"); |
| 1936 | } else if (ar.exception instanceof CommandException) { |
| 1937 | loge("getAllowedCarriers: CommandException: " + |
| 1938 | ar.exception); |
| 1939 | } else { |
| 1940 | loge("getAllowedCarriers: Unknown exception"); |
| 1941 | } |
| 1942 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1943 | if (request.argument != null) { |
| 1944 | // This is for the implementation of carrierRestrictionStatus. |
| 1945 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1946 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1947 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1948 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1949 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1950 | CarrierRestrictionRules carrierRestrictionRules = |
| 1951 | (CarrierRestrictionRules) ar.result; |
| 1952 | int carrierId = -1; |
| 1953 | try { |
| 1954 | CarrierIdentifier carrierIdentifier = |
| 1955 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1956 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1957 | carrierIdentifier); |
| 1958 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1959 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1960 | } |
| 1961 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1962 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1963 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1964 | lockStatus = TelephonyManager |
| 1965 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1966 | } |
| 1967 | } else { |
| 1968 | Rlog.e(LOG_TAG, |
| 1969 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1970 | } |
| 1971 | callback.accept(lockStatus); |
| 1972 | } else { |
| 1973 | // This is for the implementation of getAllowedCarriers. |
| 1974 | notifyRequester(request); |
| 1975 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1976 | break; |
| 1977 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1978 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1979 | ar = (AsyncResult) msg.obj; |
| 1980 | request = (MainThreadRequest) ar.userObj; |
| 1981 | if (ar.exception == null && ar.result != null) { |
| 1982 | request.result = ar.result; |
| 1983 | } else { |
| 1984 | request.result = new IllegalArgumentException( |
| 1985 | "Failed to retrieve Forbidden Plmns"); |
| 1986 | if (ar.result == null) { |
| 1987 | loge("getForbiddenPlmns: Empty response"); |
| 1988 | } else { |
| 1989 | loge("getForbiddenPlmns: Unknown exception"); |
| 1990 | } |
| 1991 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1992 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1993 | break; |
| 1994 | |
| 1995 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1996 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1997 | uiccPort = getUiccPortFromRequest(request); |
| 1998 | if (uiccPort == null) { |
| 1999 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2000 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2001 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2002 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2003 | break; |
| 2004 | } |
| 2005 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2006 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2007 | if (uiccApp == null) { |
| 2008 | loge("getForbiddenPlmns() no app with specified type -- " |
| 2009 | + appType); |
| 2010 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2011 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2012 | break; |
| 2013 | } else { |
| 2014 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 2015 | + " specified type -- " + appType); |
| 2016 | } |
| 2017 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 2018 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2019 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2020 | break; |
| 2021 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 2022 | case CMD_SWITCH_SLOTS: |
| 2023 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 2024 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 2025 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 2026 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 2027 | break; |
| 2028 | |
| 2029 | case EVENT_SWITCH_SLOTS_DONE: |
| 2030 | ar = (AsyncResult) msg.obj; |
| 2031 | request = (MainThreadRequest) ar.userObj; |
| 2032 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2033 | notifyRequester(request); |
| 2034 | break; |
| 2035 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 2036 | request = (MainThreadRequest) msg.obj; |
| 2037 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 2038 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 2039 | break; |
| 2040 | |
| 2041 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 2042 | ar = (AsyncResult) msg.obj; |
| 2043 | request = (MainThreadRequest) ar.userObj; |
| 2044 | if (ar.exception != null) { |
| 2045 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2046 | } else { |
| 2047 | int mode = ((int[]) ar.result)[0]; |
| 2048 | if (mode == 0) { |
| 2049 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 2050 | } else { |
| 2051 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 2052 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 2053 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2054 | notifyRequester(request); |
| 2055 | break; |
| 2056 | case CMD_GET_CDMA_ROAMING_MODE: |
| 2057 | request = (MainThreadRequest) msg.obj; |
| 2058 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 2059 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 2060 | break; |
| 2061 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 2062 | ar = (AsyncResult) msg.obj; |
| 2063 | request = (MainThreadRequest) ar.userObj; |
| 2064 | if (ar.exception != null) { |
| 2065 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 2066 | } else { |
| 2067 | request.result = ((int[]) ar.result)[0]; |
| 2068 | } |
| 2069 | notifyRequester(request); |
| 2070 | break; |
| 2071 | case CMD_SET_CDMA_ROAMING_MODE: |
| 2072 | request = (MainThreadRequest) msg.obj; |
| 2073 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 2074 | int mode = (int) request.argument; |
| 2075 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 2076 | break; |
| 2077 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 2078 | ar = (AsyncResult) msg.obj; |
| 2079 | request = (MainThreadRequest) ar.userObj; |
| 2080 | request.result = ar.exception == null; |
| 2081 | notifyRequester(request); |
| 2082 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 2083 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 2084 | request = (MainThreadRequest) msg.obj; |
| 2085 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 2086 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 2087 | break; |
| 2088 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 2089 | ar = (AsyncResult) msg.obj; |
| 2090 | request = (MainThreadRequest) ar.userObj; |
| 2091 | if (ar.exception != null) { |
| 2092 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 2093 | } else { |
| 2094 | request.result = ((int[]) ar.result)[0]; |
| 2095 | } |
| 2096 | notifyRequester(request); |
| 2097 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2098 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 2099 | request = (MainThreadRequest) msg.obj; |
| 2100 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 2101 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 2102 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 2103 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2104 | break; |
| 2105 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 2106 | ar = (AsyncResult) msg.obj; |
| 2107 | request = (MainThreadRequest) ar.userObj; |
| 2108 | request.result = ar.exception == null; |
| 2109 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 2110 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2111 | case CMD_GET_ALL_CELL_INFO: |
| 2112 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2113 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2114 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2115 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2116 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 2117 | ar = (AsyncResult) msg.obj; |
| 2118 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 2119 | // If a timeout occurs, the response will be null |
| 2120 | request.result = (ar.exception == null && ar.result != null) |
| 2121 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2122 | synchronized (request) { |
| 2123 | request.notifyAll(); |
| 2124 | } |
| 2125 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2126 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 2127 | request = (MainThreadRequest) msg.obj; |
| 2128 | request.phone.requestCellInfoUpdate(request.workSource, |
| 2129 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 2130 | break; |
| 2131 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 2132 | ar = (AsyncResult) msg.obj; |
| 2133 | request = (MainThreadRequest) ar.userObj; |
| 2134 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 2135 | try { |
| 2136 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2137 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 2138 | cb.onError( |
| 2139 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 2140 | ar.exception.getClass().getName(), |
| 2141 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2142 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2143 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 2144 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2145 | } else { |
| 2146 | // use the result as returned |
| 2147 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 2148 | } |
| 2149 | } catch (RemoteException re) { |
| 2150 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 2151 | } |
| 2152 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2153 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2154 | request = (MainThreadRequest) msg.obj; |
| 2155 | WorkSource ws = (WorkSource) request.argument; |
| 2156 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2157 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2158 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2159 | } |
| 2160 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2161 | ar = (AsyncResult) msg.obj; |
| 2162 | request = (MainThreadRequest) ar.userObj; |
| 2163 | if (ar.exception == null) { |
| 2164 | request.result = ar.result; |
| 2165 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2166 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2167 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2168 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | synchronized (request) { |
| 2172 | request.notifyAll(); |
| 2173 | } |
| 2174 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2175 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 2176 | case CMD_MODEM_REBOOT: |
| 2177 | request = (MainThreadRequest) msg.obj; |
| 2178 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2179 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 2180 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 2181 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 2182 | handleNullReturnEvent(msg, "rebootModem"); |
| 2183 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2184 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 2185 | request = (MainThreadRequest) msg.obj; |
| 2186 | boolean enable = (boolean) request.argument; |
| 2187 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 2188 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 2189 | PhoneConfigurationManager.getInstance() |
| 2190 | .enablePhone(request.phone, enable, onCompleted); |
| 2191 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2192 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2193 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 2194 | ar = (AsyncResult) msg.obj; |
| 2195 | request = (MainThreadRequest) ar.userObj; |
| 2196 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 2197 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 2198 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 2199 | if ((boolean) request.result) { |
| 2200 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 2201 | updateModemStateMetrics(); |
| 2202 | } else { |
| 2203 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 2204 | + ar.exception); |
| 2205 | } |
| 2206 | notifyRequester(request); |
| 2207 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2208 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 2209 | case CMD_GET_MODEM_STATUS: |
| 2210 | request = (MainThreadRequest) msg.obj; |
| 2211 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 2212 | PhoneConfigurationManager.getInstance() |
| 2213 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 2214 | break; |
| 2215 | case EVENT_GET_MODEM_STATUS_DONE: |
| 2216 | ar = (AsyncResult) msg.obj; |
| 2217 | request = (MainThreadRequest) ar.userObj; |
| 2218 | int id = request.phone.getPhoneId(); |
| 2219 | if (ar.exception == null && ar.result != null) { |
| 2220 | request.result = ar.result; |
| 2221 | //update the cache as modem status has changed |
| 2222 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 2223 | (boolean) request.result); |
| 2224 | } else { |
| 2225 | // Return true if modem status cannot be retrieved. For most cases, |
| 2226 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 2227 | // and disable modem are not supported. Modem is always on. |
| 2228 | // TODO: this should be fixed in R to support a third |
| 2229 | // status UNKNOWN b/131631629 |
| 2230 | request.result = true; |
| 2231 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 2232 | + ar.exception); |
| 2233 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 2234 | notifyRequester(request); |
| 2235 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 2236 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 2237 | request = (MainThreadRequest) msg.obj; |
| 2238 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 2239 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 2240 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 2241 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 2242 | break; |
| 2243 | } |
| 2244 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 2245 | ar = (AsyncResult) msg.obj; |
| 2246 | request = (MainThreadRequest) ar.userObj; |
| 2247 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 2248 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 2249 | args.second.accept(ar.exception == null); |
| 2250 | notifyRequester(request); |
| 2251 | break; |
| 2252 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2253 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 2254 | request = (MainThreadRequest) msg.obj; |
| 2255 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 2256 | Phone phone = getPhoneFromRequest(request); |
| 2257 | if (phone != null) { |
| 2258 | phone.getSystemSelectionChannels(onCompleted); |
| 2259 | } else { |
| 2260 | loge("getSystemSelectionChannels: No phone object"); |
| 2261 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 2262 | notifyRequester(request); |
| 2263 | } |
| 2264 | break; |
| 2265 | } |
| 2266 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 2267 | ar = (AsyncResult) msg.obj; |
| 2268 | request = (MainThreadRequest) ar.userObj; |
| 2269 | if (ar.exception == null && ar.result != null) { |
| 2270 | request.result = ar.result; |
| 2271 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 2272 | request.result = new IllegalStateException( |
| 2273 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 2274 | if (ar.result == null) { |
| 2275 | loge("getSystemSelectionChannels: Empty response"); |
| 2276 | } else { |
| 2277 | loge("getSystemSelectionChannels: Unknown exception"); |
| 2278 | } |
| 2279 | } |
| 2280 | notifyRequester(request); |
| 2281 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2282 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 2283 | ar = (AsyncResult) msg.obj; |
| 2284 | request = (MainThreadRequest) ar.userObj; |
| 2285 | if (ar.exception == null && ar.result != null) { |
| 2286 | request.result = ar.result; |
| 2287 | } else { |
| 2288 | request.result = -1; |
| 2289 | loge("Failed to set Forbidden Plmns"); |
| 2290 | if (ar.result == null) { |
| 2291 | loge("setForbidenPlmns: Empty response"); |
| 2292 | } else if (ar.exception != null) { |
| 2293 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 2294 | request.result = -1; |
| 2295 | } else { |
| 2296 | loge("setForbiddenPlmns: Unknown exception"); |
| 2297 | } |
| 2298 | } |
| 2299 | notifyRequester(request); |
| 2300 | break; |
| 2301 | case CMD_SET_FORBIDDEN_PLMNS: |
| 2302 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2303 | uiccPort = getUiccPortFromRequest(request); |
| 2304 | if (uiccPort == null) { |
| 2305 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2306 | request.result = -1; |
| 2307 | notifyRequester(request); |
| 2308 | break; |
| 2309 | } |
| 2310 | Pair<Integer, List<String>> setFplmnsArgs = |
| 2311 | (Pair<Integer, List<String>>) request.argument; |
| 2312 | appType = setFplmnsArgs.first; |
| 2313 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2314 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2315 | if (uiccApp == null) { |
| 2316 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 2317 | request.result = -1; |
| 2318 | loge("Failed to get UICC App"); |
| 2319 | notifyRequester(request); |
| 2320 | } else { |
| 2321 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 2322 | ((SIMRecords) uiccApp.getIccRecords()) |
| 2323 | .setForbiddenPlmns(onCompleted, fplmns); |
| 2324 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 2325 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2326 | case CMD_ERASE_MODEM_CONFIG: |
| 2327 | request = (MainThreadRequest) msg.obj; |
| 2328 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 2329 | defaultPhone.eraseModemConfig(onCompleted); |
| 2330 | break; |
| 2331 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 2332 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 2333 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2334 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2335 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 2336 | request = (MainThreadRequest) msg.obj; |
| 2337 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 2338 | notifyRequester(request); |
| 2339 | break; |
| 2340 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2341 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 2342 | request = (MainThreadRequest) msg.obj; |
| 2343 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2344 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2345 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2346 | changed.first, changed.second, onCompleted); |
| 2347 | break; |
| 2348 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2349 | ar = (AsyncResult) msg.obj; |
| 2350 | request = (MainThreadRequest) ar.userObj; |
| 2351 | if (ar.exception == null) { |
| 2352 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2353 | // If the operation is successful, update the PIN storage |
| 2354 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2355 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2356 | UiccController.getInstance().getPinStorage() |
| 2357 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2358 | } else { |
| 2359 | request.result = msg.arg1; |
| 2360 | } |
| 2361 | notifyRequester(request); |
| 2362 | break; |
| 2363 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2364 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2365 | request = (MainThreadRequest) msg.obj; |
| 2366 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2367 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2368 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2369 | enabled.first, enabled.second, onCompleted); |
| 2370 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2371 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2372 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2373 | ar = (AsyncResult) msg.obj; |
| 2374 | request = (MainThreadRequest) ar.userObj; |
| 2375 | if (ar.exception == null) { |
| 2376 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2377 | // If the operation is successful, update the PIN storage |
| 2378 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2379 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2380 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2381 | UiccController.getInstance().getPinStorage() |
| 2382 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2383 | } else { |
| 2384 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2385 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2386 | } else { |
| 2387 | request.result = msg.arg1; |
| 2388 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2389 | |
| 2390 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2391 | notifyRequester(request); |
| 2392 | break; |
| 2393 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2394 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2395 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2396 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2397 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2398 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2399 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2400 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2401 | |
| 2402 | case CMD_SET_DATA_THROTTLING: { |
| 2403 | request = (MainThreadRequest) msg.obj; |
| 2404 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2405 | DataThrottlingRequest dataThrottlingRequest = |
| 2406 | (DataThrottlingRequest) request.argument; |
| 2407 | Phone phone = getPhoneFromRequest(request); |
| 2408 | if (phone != null) { |
| 2409 | phone.setDataThrottling(onCompleted, |
| 2410 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2411 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2412 | } else { |
| 2413 | loge("setDataThrottling: No phone object"); |
| 2414 | request.result = |
| 2415 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2416 | notifyRequester(request); |
| 2417 | } |
| 2418 | |
| 2419 | break; |
| 2420 | } |
| 2421 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2422 | ar = (AsyncResult) msg.obj; |
| 2423 | request = (MainThreadRequest) ar.userObj; |
| 2424 | |
| 2425 | if (ar.exception == null) { |
| 2426 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2427 | } else if (ar.exception instanceof CommandException) { |
| 2428 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2429 | CommandException.Error error = |
| 2430 | ((CommandException) (ar.exception)).getCommandError(); |
| 2431 | |
| 2432 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2433 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2434 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2435 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2436 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2437 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2438 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2439 | } else { |
| 2440 | request.result = |
| 2441 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2442 | } |
| 2443 | } else { |
| 2444 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2445 | } |
| 2446 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2447 | notifyRequester(request); |
| 2448 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2449 | |
| 2450 | case CMD_SET_SIM_POWER: { |
| 2451 | request = (MainThreadRequest) msg.obj; |
| 2452 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2453 | request = (MainThreadRequest) msg.obj; |
| 2454 | int stateToSet = |
| 2455 | ((Pair<Integer, IIntegerConsumer>) |
| 2456 | request.argument).first; |
| 2457 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2458 | break; |
| 2459 | } |
| 2460 | case EVENT_SET_SIM_POWER_DONE: { |
| 2461 | ar = (AsyncResult) msg.obj; |
| 2462 | request = (MainThreadRequest) ar.userObj; |
| 2463 | IIntegerConsumer callback = |
| 2464 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2465 | if (ar.exception != null) { |
| 2466 | loge("setSimPower exception: " + ar.exception); |
| 2467 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2468 | .RESULT_ERROR_UNKNOWN; |
| 2469 | if (ar.exception instanceof CommandException) { |
| 2470 | CommandException.Error error = |
| 2471 | ((CommandException) (ar.exception)).getCommandError(); |
| 2472 | if (error == CommandException.Error.SIM_ERR) { |
| 2473 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2474 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2475 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2476 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2477 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2478 | } else { |
| 2479 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2480 | } |
| 2481 | } |
| 2482 | try { |
| 2483 | callback.accept(errorCode); |
| 2484 | } catch (RemoteException e) { |
| 2485 | // Ignore if the remote process is no longer available to call back. |
| 2486 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2487 | } |
| 2488 | } else { |
| 2489 | try { |
| 2490 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2491 | } catch (RemoteException e) { |
| 2492 | // Ignore if the remote process is no longer available to call back. |
| 2493 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2494 | } |
| 2495 | } |
| 2496 | break; |
| 2497 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2498 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2499 | request = (MainThreadRequest) msg.obj; |
| 2500 | |
| 2501 | final Phone phone = getPhoneFromRequest(request); |
| 2502 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2503 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2504 | notifyRequester(request); |
| 2505 | break; |
| 2506 | } |
| 2507 | |
| 2508 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2509 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2510 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2511 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2512 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2513 | request.subId, pair.first /*callingUid*/, |
| 2514 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2515 | break; |
| 2516 | } |
| 2517 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2518 | ar = (AsyncResult) msg.obj; |
| 2519 | request = (MainThreadRequest) ar.userObj; |
| 2520 | // request.result will be the exception of ar if present, true otherwise. |
| 2521 | // Be cautious not to leave result null which will wait() forever |
| 2522 | request.result = ar.exception != null ? ar.exception : true; |
| 2523 | notifyRequester(request); |
| 2524 | break; |
| 2525 | } |
| 2526 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2527 | request = (MainThreadRequest) msg.obj; |
| 2528 | |
| 2529 | Phone phone = getPhoneFromRequest(request); |
| 2530 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2531 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2532 | notifyRequester(request); |
| 2533 | break; |
| 2534 | } |
| 2535 | |
| 2536 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2537 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2538 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2539 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2540 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2541 | request.subId, pair.first /*callingUid*/, |
| 2542 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2543 | break; |
| 2544 | } |
| 2545 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2546 | ar = (AsyncResult) msg.obj; |
| 2547 | request = (MainThreadRequest) ar.userObj; |
| 2548 | request.result = ar.exception != null ? ar.exception : true; |
| 2549 | notifyRequester(request); |
| 2550 | break; |
| 2551 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2552 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2553 | case CMD_GET_SLICING_CONFIG: { |
| 2554 | request = (MainThreadRequest) msg.obj; |
| 2555 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2556 | request.phone.getSlicingConfig(onCompleted); |
| 2557 | break; |
| 2558 | } |
| 2559 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2560 | ar = (AsyncResult) msg.obj; |
| 2561 | request = (MainThreadRequest) ar.userObj; |
| 2562 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2563 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2564 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2565 | Bundle bundle = new Bundle(); |
| 2566 | int resultCode = 0; |
| 2567 | if (ar.exception != null) { |
| 2568 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2569 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2570 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2571 | } else if (ar.result == null) { |
| 2572 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2573 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2574 | } else { |
| 2575 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2576 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2577 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2581 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2582 | } |
| 2583 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2584 | result.send(resultCode, bundle); |
| 2585 | notifyRequester(request); |
| 2586 | break; |
| 2587 | } |
| 2588 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2589 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2590 | request = (MainThreadRequest) msg.obj; |
| 2591 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2592 | PurchasePremiumCapabilityArgument arg = |
| 2593 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2594 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2595 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2596 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2597 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2598 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2599 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2600 | ar = (AsyncResult) msg.obj; |
| 2601 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2602 | PurchasePremiumCapabilityArgument arg = |
| 2603 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2604 | try { |
| 2605 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2606 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2607 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2608 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2609 | + ", result= " |
| 2610 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2611 | } catch (RemoteException e) { |
| 2612 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2613 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2614 | + " failed: " + e; |
| 2615 | if (DBG) log(logStr); |
| 2616 | AnomalyReporter.reportAnomaly( |
| 2617 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2618 | } |
| 2619 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2620 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2621 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2622 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2623 | request = (MainThreadRequest) msg.obj; |
| 2624 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2625 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2626 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2627 | notifyRequester(request); |
| 2628 | break; |
| 2629 | |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2630 | case CMD_START_SATELLITE_POSITION_UPDATES: { |
| 2631 | request = (MainThreadRequest) msg.obj; |
| 2632 | onCompleted = |
| 2633 | obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2634 | if (mIsSatelliteServiceSupported) { |
| 2635 | mSatelliteServiceController.startSendingSatellitePointingInfo(onCompleted); |
| 2636 | break; |
| 2637 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2638 | Phone phone = getPhoneFromRequest(request); |
| 2639 | if (phone != null) { |
| 2640 | phone.startSatellitePositionUpdates(onCompleted); |
| 2641 | } else { |
| 2642 | loge("startSatellitePositionUpdates: No phone object"); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 2643 | SatellitePositionUpdateArgument arg = |
| 2644 | (SatellitePositionUpdateArgument) request.argument; |
| 2645 | arg.errorCallback.accept( |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2646 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2647 | } |
| 2648 | break; |
| 2649 | } |
| 2650 | |
| 2651 | case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 2652 | handleStartSatellitePositionUpdatesDone((AsyncResult) msg.obj); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2653 | break; |
| 2654 | } |
| 2655 | |
| 2656 | case CMD_STOP_SATELLITE_POSITION_UPDATES: { |
| 2657 | request = (MainThreadRequest) msg.obj; |
| 2658 | onCompleted = |
| 2659 | obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2660 | if (mIsSatelliteServiceSupported) { |
| 2661 | mSatelliteServiceController.stopSendingSatellitePointingInfo(onCompleted); |
| 2662 | break; |
| 2663 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2664 | Phone phone = getPhoneFromRequest(request); |
| 2665 | if (phone != null) { |
| 2666 | phone.stopSatellitePositionUpdates(onCompleted); |
| 2667 | } else { |
| 2668 | loge("stopSatellitePositionUpdates: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2669 | ((Consumer<Integer>) request.argument).accept( |
| 2670 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2671 | } |
| 2672 | break; |
| 2673 | } |
| 2674 | |
| 2675 | case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: { |
| 2676 | ar = (AsyncResult) msg.obj; |
| 2677 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2678 | int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false); |
| 2679 | ((Consumer<Integer>) request.argument).accept(error); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 2680 | break; |
| 2681 | } |
| 2682 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2683 | case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: { |
| 2684 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2685 | onCompleted = |
| 2686 | obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE, request); |
| 2687 | if (mIsSatelliteServiceSupported) { |
| 2688 | mSatelliteServiceController |
| 2689 | .requestMaxCharactersPerMOTextMessage(onCompleted); |
| 2690 | break; |
| 2691 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2692 | Phone phone = getPhoneFromRequest(request); |
| 2693 | if (phone != null) { |
| 2694 | phone.getMaxCharactersPerSatelliteTextMessage(onCompleted); |
| 2695 | } else { |
| 2696 | loge("getMaxCharactersPerSatelliteTextMessage: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2697 | ((ResultReceiver) request.argument).send( |
| 2698 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2699 | } |
| 2700 | break; |
| 2701 | } |
| 2702 | |
| 2703 | case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: { |
| 2704 | ar = (AsyncResult) msg.obj; |
| 2705 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2706 | int error = |
| 2707 | getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true); |
| 2708 | Bundle bundle = new Bundle(); |
| 2709 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2710 | int maxCharLimit = ((int[]) ar.result)[0]; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2711 | if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2712 | bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT, |
| 2713 | maxCharLimit); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2714 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2715 | ((ResultReceiver) request.argument).send(error, bundle); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 2716 | break; |
| 2717 | } |
| 2718 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2719 | case CMD_PROVISION_SATELLITE_SERVICE: { |
| 2720 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2721 | ProvisionSatelliteServiceArgument argument = |
| 2722 | (ProvisionSatelliteServiceArgument) request.argument; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2723 | if (mSatelliteProvisionCallbacks.containsKey(argument.subId)) { |
| 2724 | argument.callback.accept( |
| 2725 | SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS); |
| 2726 | notifyRequester(request); |
| 2727 | break; |
| 2728 | } |
| 2729 | mSatelliteProvisionCallbacks.put(argument.subId, argument.callback); |
| 2730 | onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request); |
| 2731 | if (mIsSatelliteServiceSupported) { |
| 2732 | mSatelliteServiceController |
| 2733 | .provisionSatelliteService(argument.token, onCompleted); |
| 2734 | break; |
| 2735 | } |
| 2736 | Phone phone = getPhoneFromRequest(request); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2737 | if (phone != null) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2738 | phone.provisionSatelliteService(onCompleted, argument.token); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2739 | } else { |
| 2740 | loge("provisionSatelliteService: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2741 | argument.callback.accept( |
| 2742 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2743 | notifyRequester(request); |
| 2744 | } |
| 2745 | break; |
| 2746 | } |
| 2747 | |
| 2748 | case EVENT_PROVISION_SATELLITE_SERVICE_DONE: { |
| 2749 | ar = (AsyncResult) msg.obj; |
| 2750 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2751 | int errorCode = getSatelliteError(ar, "provisionSatelliteService", false); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 2752 | handleEventProvisionSatelliteServiceDone( |
| 2753 | (ProvisionSatelliteServiceArgument) request.argument, errorCode); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2754 | notifyRequester(request); |
| 2755 | break; |
| 2756 | } |
| 2757 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 2758 | case CMD_DEPROVISION_SATELLITE_SERVICE: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2759 | request = (MainThreadRequest) msg.obj; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 2760 | ProvisionSatelliteServiceArgument argument = |
| 2761 | (ProvisionSatelliteServiceArgument) request.argument; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2762 | onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request); |
| 2763 | if (mIsSatelliteServiceSupported) { |
| 2764 | mSatelliteServiceController |
| 2765 | .deprovisionSatelliteService(argument.token, onCompleted); |
| 2766 | break; |
| 2767 | } |
| 2768 | Phone phone = getPhoneFromRequest(request); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 2769 | if (phone != null) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2770 | phone.deprovisionSatelliteService(onCompleted, argument.token); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 2771 | } else { |
| 2772 | loge("deprovisionSatelliteService: No phone object"); |
| 2773 | if (argument.callback != null) { |
| 2774 | argument.callback.accept( |
| 2775 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 2776 | } |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 2777 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2778 | break; |
| 2779 | } |
| 2780 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 2781 | case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2782 | ar = (AsyncResult) msg.obj; |
| 2783 | request = (MainThreadRequest) ar.userObj; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 2784 | int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false); |
| 2785 | handleEventDeprovisionSatelliteServiceDone( |
| 2786 | (ProvisionSatelliteServiceArgument) request.argument, errorCode); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2787 | break; |
| 2788 | } |
| 2789 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2790 | case CMD_SET_SATELLITE_ENABLED: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2791 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2792 | Pair<Boolean, Consumer<Integer>> argument = |
| 2793 | (Pair<Boolean, Consumer<Integer>>) request.argument; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2794 | onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request); |
| 2795 | if (mIsSatelliteServiceSupported) { |
| 2796 | mSatelliteServiceController |
| 2797 | .requestSatelliteEnabled(argument.first, onCompleted); |
| 2798 | break; |
| 2799 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2800 | Phone phone = getPhoneFromRequest(request); |
| 2801 | if (phone != null) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2802 | phone.setSatellitePower(onCompleted, argument.first); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2803 | } else { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2804 | loge("requestSatelliteEnabled: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2805 | argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2806 | } |
| 2807 | break; |
| 2808 | } |
| 2809 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2810 | case EVENT_SET_SATELLITE_ENABLED_DONE: { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2811 | ar = (AsyncResult) msg.obj; |
| 2812 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2813 | Pair<Boolean, Consumer<Integer>> argument = |
| 2814 | (Pair<Boolean, Consumer<Integer>>) request.argument; |
| 2815 | int error = getSatelliteError(ar, "setSatelliteEnabled", false); |
| 2816 | argument.second.accept(error); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2817 | break; |
| 2818 | } |
| 2819 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2820 | case CMD_IS_SATELLITE_ENABLED: { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2821 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2822 | onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2823 | if (mIsSatelliteServiceSupported) { |
| 2824 | mSatelliteServiceController.requestIsSatelliteEnabled(onCompleted); |
| 2825 | break; |
| 2826 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2827 | Phone phone = getPhoneFromRequest(request); |
| 2828 | if (phone != null) { |
| 2829 | phone.isSatellitePowerOn(onCompleted); |
| 2830 | } else { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2831 | loge("isSatelliteEnabled: No phone object"); |
| 2832 | ((ResultReceiver) request.argument).send( |
| 2833 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2834 | } |
| 2835 | break; |
| 2836 | } |
| 2837 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2838 | case EVENT_IS_SATELLITE_ENABLED_DONE: { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2839 | ar = (AsyncResult) msg.obj; |
| 2840 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2841 | int error = getSatelliteError(ar, "isSatelliteEnabled", true); |
| 2842 | Bundle bundle = new Bundle(); |
| 2843 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 2844 | boolean enabled = ((int[]) ar.result)[0] == 1; |
| 2845 | if (DBG) log("isSatelliteEnabled: " + enabled); |
| 2846 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2847 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2848 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2849 | break; |
| 2850 | } |
| 2851 | |
| 2852 | case CMD_IS_SATELLITE_SUPPORTED: { |
| 2853 | request = (MainThreadRequest) msg.obj; |
| 2854 | onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2855 | if (mIsSatelliteServiceSupported) { |
| 2856 | mSatelliteServiceController.requestIsSatelliteSupported(onCompleted); |
| 2857 | break; |
| 2858 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2859 | Phone phone = getPhoneFromRequest(request); |
| 2860 | if (phone != null) { |
| 2861 | phone.isSatelliteSupported(onCompleted); |
| 2862 | } else { |
| 2863 | loge("isSatelliteSupported: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2864 | ((ResultReceiver) request.argument).send( |
| 2865 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2866 | } |
| 2867 | break; |
| 2868 | } |
| 2869 | |
| 2870 | case EVENT_IS_SATELLITE_SUPPORTED_DONE: { |
| 2871 | ar = (AsyncResult) msg.obj; |
| 2872 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2873 | int error = getSatelliteError(ar, "isSatelliteSupported", true); |
| 2874 | Bundle bundle = new Bundle(); |
| 2875 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 2876 | boolean supported = (boolean) ar.result; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2877 | if (DBG) log("isSatelliteSupported: " + supported); |
| 2878 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 2879 | synchronized (mIsSatelliteSupportedLock) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2880 | mIsSatelliteSupported = supported; |
| 2881 | } |
| 2882 | } else { |
| 2883 | synchronized (mIsSatelliteSupportedLock) { |
| 2884 | mIsSatelliteSupported = null; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 2885 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2886 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2887 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2888 | break; |
| 2889 | } |
| 2890 | |
| 2891 | case CMD_GET_SATELLITE_CAPABILITIES: { |
| 2892 | request = (MainThreadRequest) msg.obj; |
| 2893 | onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2894 | if (mIsSatelliteServiceSupported) { |
| 2895 | mSatelliteServiceController.requestSatelliteCapabilities(onCompleted); |
| 2896 | break; |
| 2897 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2898 | Phone phone = getPhoneFromRequest(request); |
| 2899 | if (phone != null) { |
| 2900 | phone.getSatelliteCapabilities(onCompleted); |
| 2901 | } else { |
| 2902 | loge("getSatelliteCapabilities: No phone object"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2903 | ((ResultReceiver) request.argument).send( |
| 2904 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2905 | } |
| 2906 | break; |
| 2907 | } |
| 2908 | |
| 2909 | case EVENT_GET_SATELLITE_CAPABILITIES_DONE: { |
| 2910 | ar = (AsyncResult) msg.obj; |
| 2911 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2912 | int error = getSatelliteError(ar, "getSatelliteCapabilities", true); |
| 2913 | Bundle bundle = new Bundle(); |
| 2914 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2915 | SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result; |
| 2916 | if (DBG) log("getSatelliteCapabilities: " + capabilities); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2917 | bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES, |
| 2918 | capabilities); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2919 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 2920 | ((ResultReceiver) request.argument).send(error, bundle); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 2921 | break; |
| 2922 | } |
| 2923 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 2924 | case CMD_POLL_PENDING_SATELLITE_DATAGRAMS: { |
| 2925 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2926 | onCompleted = |
| 2927 | obtainMessage(EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE, request); |
| 2928 | if (mIsSatelliteServiceSupported) { |
| 2929 | mSatelliteServiceController.pollPendingSatelliteDatagrams(onCompleted); |
| 2930 | break; |
| 2931 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 2932 | Phone phone = getPhoneFromRequest(request); |
| 2933 | if (phone != null) { |
| 2934 | phone.pollPendingSatelliteDatagrams(onCompleted); |
| 2935 | } else { |
| 2936 | loge("pollPendingSatelliteDatagrams: No phone object"); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2937 | ((Consumer<Integer>) request.argument).accept( |
| 2938 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 2939 | } |
| 2940 | break; |
| 2941 | } |
| 2942 | |
| 2943 | case EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE: { |
| 2944 | ar = (AsyncResult) msg.obj; |
| 2945 | request = (MainThreadRequest) ar.userObj; |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 2946 | int error = getSatelliteError(ar, "pollPendingSatelliteDatagrams", false); |
| 2947 | ((Consumer<Integer>) request.argument).accept(error); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | } |
| 2950 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 2951 | case CMD_SEND_SATELLITE_DATAGRAM: { |
| 2952 | request = (MainThreadRequest) msg.obj; |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 2953 | SendSatelliteDatagramArgument argument = |
| 2954 | (SendSatelliteDatagramArgument) request.argument; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2955 | onCompleted = obtainMessage(EVENT_SEND_SATELLITE_DATAGRAM_DONE, request); |
| 2956 | if (mIsSatelliteServiceSupported) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 2957 | mSatelliteServiceController.sendSatelliteDatagram( |
| 2958 | argument.datagram, |
| 2959 | argument.datagramType == SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE, |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame^] | 2960 | argument.needFullScreenPointingUI, onCompleted); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2961 | break; |
| 2962 | } |
| 2963 | Phone phone = getPhoneFromRequest(request); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 2964 | if (phone != null) { |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame^] | 2965 | phone.sendSatelliteDatagram(onCompleted, argument.datagram, |
| 2966 | argument.needFullScreenPointingUI); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 2967 | } else { |
| 2968 | loge("sendSatelliteDatagram: No phone object"); |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 2969 | argument.result.send( |
| 2970 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 2971 | } |
| 2972 | break; |
| 2973 | } |
| 2974 | |
| 2975 | case EVENT_SEND_SATELLITE_DATAGRAM_DONE: { |
| 2976 | ar = (AsyncResult) msg.obj; |
| 2977 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2978 | int error = getSatelliteError(ar, "sendSatelliteDatagram", false); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 2979 | SendSatelliteDatagramArgument argument = |
| 2980 | (SendSatelliteDatagramArgument) request.argument; |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 2981 | Bundle bundle = new Bundle(); |
| 2982 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 2983 | bundle.putLong(SatelliteManager.KEY_SEND_SATELLITE_DATAGRAM, |
| 2984 | argument.datagramId); |
| 2985 | } |
| 2986 | argument.result.send(error, bundle); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 2987 | break; |
| 2988 | } |
| 2989 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 2990 | case CMD_IS_SATELLITE_COMMUNICATION_ALLOWED: { |
| 2991 | request = (MainThreadRequest) msg.obj; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2992 | onCompleted = |
| 2993 | obtainMessage(EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE, request); |
| 2994 | if (mIsSatelliteServiceSupported) { |
| 2995 | mSatelliteServiceController |
| 2996 | .requestIsSatelliteCommunicationAllowedForCurrentLocation( |
| 2997 | onCompleted); |
| 2998 | break; |
| 2999 | } |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 3000 | Phone phone = getPhoneFromRequest(request); |
| 3001 | if (phone != null) { |
| 3002 | phone.isSatelliteCommunicationAllowedForCurrentLocation(onCompleted); |
| 3003 | } else { |
| 3004 | loge("isSatelliteCommunicationAllowedForCurrentLocation: No phone object"); |
| 3005 | ((ResultReceiver) request.argument).send( |
| 3006 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 3007 | } |
| 3008 | break; |
| 3009 | } |
| 3010 | |
| 3011 | case EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE: { |
| 3012 | ar = (AsyncResult) msg.obj; |
| 3013 | request = (MainThreadRequest) ar.userObj; |
| 3014 | int error = getSatelliteError( |
| 3015 | ar, "isSatelliteCommunicationAllowedForCurrentLocation", true); |
| 3016 | Bundle bundle = new Bundle(); |
| 3017 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 3018 | boolean communicationAllowed = (boolean) ar.result; |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 3019 | if (DBG) { |
| 3020 | log("isSatelliteCommunicationAllowedForCurrentLocation: " |
| 3021 | + communicationAllowed); |
| 3022 | } |
| 3023 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED, |
| 3024 | communicationAllowed); |
| 3025 | } |
| 3026 | ((ResultReceiver) request.argument).send(error, bundle); |
| 3027 | break; |
| 3028 | } |
| 3029 | |
| 3030 | case CMD_GET_TIME_SATELLITE_NEXT_VISIBLE: { |
| 3031 | request = (MainThreadRequest) msg.obj; |
| 3032 | onCompleted = obtainMessage(EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE, |
| 3033 | request); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3034 | if (mIsSatelliteServiceSupported) { |
| 3035 | mSatelliteServiceController |
| 3036 | .requestTimeForNextSatelliteVisibility(onCompleted); |
| 3037 | break; |
| 3038 | } |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 3039 | Phone phone = getPhoneFromRequest(request); |
| 3040 | if (phone != null) { |
| 3041 | phone.requestTimeForNextSatelliteVisibility(onCompleted); |
| 3042 | } else { |
| 3043 | loge("requestTimeForNextSatelliteVisibility: No phone object"); |
| 3044 | ((ResultReceiver) request.argument).send( |
| 3045 | SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 3046 | } |
| 3047 | break; |
| 3048 | } |
| 3049 | |
| 3050 | case EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE: { |
| 3051 | ar = (AsyncResult) msg.obj; |
| 3052 | request = (MainThreadRequest) ar.userObj; |
| 3053 | int error = |
| 3054 | getSatelliteError(ar, "requestTimeForNextSatelliteVisibility", true); |
| 3055 | Bundle bundle = new Bundle(); |
| 3056 | if (error == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 3057 | int nextVisibilityDuration = ((int[]) ar.result)[0]; |
| 3058 | if (DBG) { |
| 3059 | log("requestTimeForNextSatelliteVisibility: " + nextVisibilityDuration); |
| 3060 | } |
| 3061 | bundle.putInt(SatelliteManager.KEY_SATELLITE_NEXT_VISIBILITY, |
| 3062 | nextVisibilityDuration); |
| 3063 | } |
| 3064 | ((ResultReceiver) request.argument).send(error, bundle); |
| 3065 | break; |
| 3066 | } |
| 3067 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3068 | default: |
| 3069 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 3070 | break; |
| 3071 | } |
| 3072 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3073 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3074 | private void notifyRequester(MainThreadRequest request) { |
| 3075 | synchronized (request) { |
| 3076 | request.notifyAll(); |
| 3077 | } |
| 3078 | } |
| 3079 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3080 | private void handleNullReturnEvent(Message msg, String command) { |
| 3081 | AsyncResult ar = (AsyncResult) msg.obj; |
| 3082 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 3083 | if (ar.exception == null) { |
| 3084 | request.result = true; |
| 3085 | } else { |
| 3086 | request.result = false; |
| 3087 | if (ar.exception instanceof CommandException) { |
| 3088 | loge(command + ": CommandException: " + ar.exception); |
| 3089 | } else { |
| 3090 | loge(command + ": Unknown exception"); |
| 3091 | } |
| 3092 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3093 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3094 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | /** |
| 3098 | * Posts the specified command to be executed on the main thread, |
| 3099 | * waits for the request to complete, and returns the result. |
| 3100 | * @see #sendRequestAsync |
| 3101 | */ |
| 3102 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3103 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 3104 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | /** |
| 3108 | * Posts the specified command to be executed on the main thread, |
| 3109 | * waits for the request to complete, and returns the result. |
| 3110 | * @see #sendRequestAsync |
| 3111 | */ |
| 3112 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 3113 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3114 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | /** |
| 3118 | * Posts the specified command to be executed on the main thread, |
| 3119 | * waits for the request to complete, and returns the result. |
| 3120 | * @see #sendRequestAsync |
| 3121 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3122 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3123 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 3124 | } |
| 3125 | |
| 3126 | /** |
| 3127 | * Posts the specified command to be executed on the main thread, |
| 3128 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 3129 | * if not timeout or null otherwise. |
| 3130 | * @see #sendRequestAsync |
| 3131 | */ |
| 3132 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 3133 | long timeoutInMs) { |
| 3134 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | /** |
| 3138 | * Posts the specified command to be executed on the main thread, |
| 3139 | * waits for the request to complete, and returns the result. |
| 3140 | * @see #sendRequestAsync |
| 3141 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3142 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3143 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | /** |
| 3147 | * Posts the specified command to be executed on the main thread, |
| 3148 | * waits for the request to complete, and returns the result. |
| 3149 | * @see #sendRequestAsync |
| 3150 | */ |
| 3151 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3152 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 3153 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3157 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 3158 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 3159 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3160 | * @see #sendRequestAsync |
| 3161 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3162 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 3163 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3164 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 3165 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 3166 | } |
| 3167 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3168 | MainThreadRequest request = null; |
| 3169 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 3170 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 3171 | } else if (phone != null) { |
| 3172 | request = new MainThreadRequest(argument, phone, workSource); |
| 3173 | } else { |
| 3174 | request = new MainThreadRequest(argument, subId, workSource); |
| 3175 | } |
| 3176 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3177 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 3178 | msg.sendToTarget(); |
| 3179 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3180 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3181 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3182 | if (timeoutInMs >= 0) { |
| 3183 | // Wait for at least timeoutInMs before returning null request result |
| 3184 | long now = SystemClock.elapsedRealtime(); |
| 3185 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 3186 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3187 | try { |
| 3188 | request.wait(deadline - now); |
| 3189 | } catch (InterruptedException e) { |
| 3190 | // Do nothing, go back and check if request is completed or timeout |
| 3191 | } finally { |
| 3192 | now = SystemClock.elapsedRealtime(); |
| 3193 | } |
| 3194 | } |
| 3195 | } else { |
| 3196 | // Wait for the request to complete |
| 3197 | while (request.result == null) { |
| 3198 | try { |
| 3199 | request.wait(); |
| 3200 | } catch (InterruptedException e) { |
| 3201 | // Do nothing, go back and wait until the request is complete |
| 3202 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3203 | } |
| 3204 | } |
| 3205 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 3206 | if (request.result == null) { |
| 3207 | Log.wtf(LOG_TAG, |
| 3208 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 3209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3210 | return request.result; |
| 3211 | } |
| 3212 | |
| 3213 | /** |
| 3214 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 3215 | * Posts the specified command to be executed on the main thread, and |
| 3216 | * returns immediately. |
| 3217 | * @see #sendRequest |
| 3218 | */ |
| 3219 | private void sendRequestAsync(int command) { |
| 3220 | mMainThreadHandler.sendEmptyMessage(command); |
| 3221 | } |
| 3222 | |
| 3223 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3224 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3225 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3226 | */ |
| 3227 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3228 | sendRequestAsync(command, argument, null, null); |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 3233 | * @see {@link #sendRequest(int,Object)} |
| 3234 | */ |
| 3235 | private void sendRequestAsync( |
| 3236 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 3237 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3238 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 3239 | msg.sendToTarget(); |
| 3240 | } |
| 3241 | |
| 3242 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3243 | * Initialize the singleton PhoneInterfaceManager instance. |
| 3244 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 3245 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3246 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3247 | synchronized (PhoneInterfaceManager.class) { |
| 3248 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3249 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3250 | } else { |
| 3251 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 3252 | } |
| 3253 | return sInstance; |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 3258 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3259 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3260 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 3261 | mImsResolver = ImsResolver.getInstance(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3262 | mSatelliteServiceController = SatelliteServiceController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 3263 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3264 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 3265 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 3266 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 3267 | mSubscriptionController = SubscriptionController.getInstance(); |
| 3268 | } else { |
| 3269 | mSubscriptionController = null; |
| 3270 | } |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3271 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3272 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 3273 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 3274 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 3275 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 3276 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3277 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3278 | CarrierAllowListInfo.loadInstance(mApp); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 3279 | mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) { |
| 3280 | @Override |
| 3281 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 3282 | if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE |
| 3283 | && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) { |
| 3284 | synchronized (mIsSatelliteSupportedLock) { |
| 3285 | mIsSatelliteSupported = resultData.getBoolean( |
| 3286 | SatelliteManager.KEY_SATELLITE_SUPPORTED); |
| 3287 | } |
| 3288 | } else { |
| 3289 | synchronized (mIsSatelliteSupportedLock) { |
| 3290 | mIsSatelliteSupported = null; |
| 3291 | } |
| 3292 | } |
| 3293 | } |
| 3294 | }; |
| 3295 | requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
| 3296 | mSatelliteSupportedReceiver); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3297 | } |
| 3298 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3299 | @VisibleForTesting |
| 3300 | public SharedPreferences getSharedPreferences() { |
| 3301 | return mTelephonySharedPreferences; |
| 3302 | } |
| 3303 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 3304 | /** |
| 3305 | * Get the default phone for this device. |
| 3306 | */ |
| 3307 | @VisibleForTesting |
| 3308 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3309 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 3310 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 3311 | } |
| 3312 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3313 | private void publish() { |
| 3314 | if (DBG) log("publish: " + this); |
| 3315 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 3316 | TelephonyFrameworkInitializer |
| 3317 | .getTelephonyServiceManager() |
| 3318 | .getTelephonyServiceRegisterer() |
| 3319 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 3322 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3323 | if (request.phone != null) { |
| 3324 | return request.phone; |
| 3325 | } else { |
| 3326 | return getPhoneFromSubId(request.subId); |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | private Phone getPhoneFromSubId(int subId) { |
| 3331 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 3332 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 3333 | } |
| 3334 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 3335 | /** |
| 3336 | * Get phone object associated with a subscription. |
| 3337 | * Return default phone if phone object associated with subscription is null |
| 3338 | * @param subId - subscriptionId |
| 3339 | * @return phone object associated with a subscription or default phone if null. |
| 3340 | */ |
| 3341 | private Phone getPhoneFromSubIdOrDefault(int subId) { |
| 3342 | Phone phone = getPhoneFromSubId(subId); |
| 3343 | if (phone == null) { |
| 3344 | phone = getDefaultPhone(); |
| 3345 | } |
| 3346 | return phone; |
| 3347 | } |
| 3348 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 3349 | @Nullable |
| 3350 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3351 | Phone phone = getPhoneFromRequest(request); |
| 3352 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 3353 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3354 | } |
| 3355 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3356 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3357 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3358 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3359 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3360 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 3361 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 3362 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 3363 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3364 | } |
| 3365 | |
| 3366 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 3367 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 3368 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3371 | private boolean isImsAvailableOnDevice() { |
| 3372 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 3373 | if (pm == null) { |
| 3374 | // For some reason package manger is not available.. This will fail internally anyway, |
| 3375 | // so do not throw error and allow. |
| 3376 | return true; |
| 3377 | } |
| 3378 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 3379 | } |
| 3380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3381 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3382 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3385 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3386 | if (DBG) log("dial: " + number); |
| 3387 | // No permission check needed here: This is just a wrapper around the |
| 3388 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 3389 | // the UI before it does anything. |
| 3390 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3391 | final long identity = Binder.clearCallingIdentity(); |
| 3392 | try { |
| 3393 | String url = createTelUrl(number); |
| 3394 | if (url == null) { |
| 3395 | return; |
| 3396 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3397 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3398 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 3399 | PhoneConstants.State state = mCM.getState(subId); |
| 3400 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 3401 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 3402 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3403 | mApp.startActivity(intent); |
| 3404 | } |
| 3405 | } finally { |
| 3406 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3411 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3414 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3415 | if (DBG) log("call: " + number); |
| 3416 | |
| 3417 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 3418 | // need to do a permission check since we're calling startActivity() |
| 3419 | // from the context of the phone app. |
| 3420 | enforceCallPermission(); |
| 3421 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3422 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3423 | != AppOpsManager.MODE_ALLOWED) { |
| 3424 | return; |
| 3425 | } |
| 3426 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3427 | final long identity = Binder.clearCallingIdentity(); |
| 3428 | try { |
| 3429 | String url = createTelUrl(number); |
| 3430 | if (url == null) { |
| 3431 | return; |
| 3432 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3433 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3434 | boolean isValid = false; |
| 3435 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 3436 | if (slist != null) { |
| 3437 | for (SubscriptionInfo subInfoRecord : slist) { |
| 3438 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 3439 | isValid = true; |
| 3440 | break; |
| 3441 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 3442 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 3443 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3444 | if (!isValid) { |
| 3445 | return; |
| 3446 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 3447 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 3449 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 3450 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3451 | mApp.startActivity(intent); |
| 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(identity); |
| 3454 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3457 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3458 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3459 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 3460 | } |
| 3461 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3462 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3463 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3464 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 3465 | } |
| 3466 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3467 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3468 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3469 | |
| 3470 | final long identity = Binder.clearCallingIdentity(); |
| 3471 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3472 | Phone phone = getPhone(subId); |
| 3473 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3474 | checkSimPin.start(); |
| 3475 | return checkSimPin.unlockSim(null, pin); |
| 3476 | } finally { |
| 3477 | Binder.restoreCallingIdentity(identity); |
| 3478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3479 | } |
| 3480 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3481 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3482 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3483 | |
| 3484 | final long identity = Binder.clearCallingIdentity(); |
| 3485 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3486 | Phone phone = getPhone(subId); |
| 3487 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3488 | checkSimPuk.start(); |
| 3489 | return checkSimPuk.unlockSim(puk, pin); |
| 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(identity); |
| 3492 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3496 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3497 | * a synchronous one. |
| 3498 | */ |
| 3499 | private static class UnlockSim extends Thread { |
| 3500 | |
| 3501 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3502 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3503 | |
| 3504 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3505 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 3506 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3507 | |
| 3508 | // For replies from SimCard interface |
| 3509 | private Handler mHandler; |
| 3510 | |
| 3511 | // For async handler to identify request type |
| 3512 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 3513 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3514 | UnlockSim(int phoneId, IccCard simCard) { |
| 3515 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3516 | mSimCard = simCard; |
| 3517 | } |
| 3518 | |
| 3519 | @Override |
| 3520 | public void run() { |
| 3521 | Looper.prepare(); |
| 3522 | synchronized (UnlockSim.this) { |
| 3523 | mHandler = new Handler() { |
| 3524 | @Override |
| 3525 | public void handleMessage(Message msg) { |
| 3526 | AsyncResult ar = (AsyncResult) msg.obj; |
| 3527 | switch (msg.what) { |
| 3528 | case SUPPLY_PIN_COMPLETE: |
| 3529 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 3530 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3531 | mRetryCount = msg.arg1; |
| 3532 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 3533 | CommandException.Error error = null; |
| 3534 | if (ar.exception instanceof CommandException) { |
| 3535 | error = ((CommandException) (ar.exception)) |
| 3536 | .getCommandError(); |
| 3537 | } |
| 3538 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3539 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 3540 | } else if (error == CommandException.Error.ABORTED) { |
| 3541 | /* When UiccCardApp dispose, handle message and return |
| 3542 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 3543 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3544 | } else { |
| 3545 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 3546 | } |
| 3547 | } else { |
| 3548 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 3549 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3550 | mDone = true; |
| 3551 | UnlockSim.this.notifyAll(); |
| 3552 | } |
| 3553 | break; |
| 3554 | } |
| 3555 | } |
| 3556 | }; |
| 3557 | UnlockSim.this.notifyAll(); |
| 3558 | } |
| 3559 | Looper.loop(); |
| 3560 | } |
| 3561 | |
| 3562 | /* |
| 3563 | * Use PIN or PUK to unlock SIM card |
| 3564 | * |
| 3565 | * If PUK is null, unlock SIM card with PIN |
| 3566 | * |
| 3567 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 3568 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3569 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3570 | |
| 3571 | while (mHandler == null) { |
| 3572 | try { |
| 3573 | wait(); |
| 3574 | } catch (InterruptedException e) { |
| 3575 | Thread.currentThread().interrupt(); |
| 3576 | } |
| 3577 | } |
| 3578 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 3579 | |
| 3580 | if (puk == null) { |
| 3581 | mSimCard.supplyPin(pin, callback); |
| 3582 | } else { |
| 3583 | mSimCard.supplyPuk(puk, pin, callback); |
| 3584 | } |
| 3585 | |
| 3586 | while (!mDone) { |
| 3587 | try { |
| 3588 | Log.d(LOG_TAG, "wait for done"); |
| 3589 | wait(); |
| 3590 | } catch (InterruptedException e) { |
| 3591 | // Restore the interrupted status |
| 3592 | Thread.currentThread().interrupt(); |
| 3593 | } |
| 3594 | } |
| 3595 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3596 | int[] resultArray = new int[2]; |
| 3597 | resultArray[0] = mResult; |
| 3598 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3599 | |
| 3600 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 3601 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3602 | } |
| 3603 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 3604 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3605 | } |
| 3606 | } |
| 3607 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3608 | /** |
| 3609 | * This method has been removed due to privacy and stability concerns. |
| 3610 | */ |
| 3611 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3612 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3613 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 3614 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3617 | @Override |
| 3618 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 3619 | mApp.getSystemService(AppOpsManager.class) |
| 3620 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3621 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3622 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3623 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 3624 | // Callers targeting S have no business invoking this method. |
| 3625 | return; |
| 3626 | } |
| 3627 | |
| 3628 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3629 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3630 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3631 | .setCallingPackage(callingPackage) |
| 3632 | .setCallingFeatureId(null) |
| 3633 | .setCallingPid(Binder.getCallingPid()) |
| 3634 | .setCallingUid(Binder.getCallingUid()) |
| 3635 | .setMethod("updateServiceLocation") |
| 3636 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3637 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3638 | .build()); |
| 3639 | // Apps that lack location permission have no business calling this method; |
| 3640 | // however, because no permission was declared in the public API, denials must |
| 3641 | // all be "soft". |
| 3642 | switch (locationResult) { |
| 3643 | case DENIED_HARD: /* fall through */ |
| 3644 | case DENIED_SOFT: |
| 3645 | return; |
| 3646 | } |
| 3647 | |
| 3648 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3649 | final long identity = Binder.clearCallingIdentity(); |
| 3650 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3651 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 3653 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | } |
| 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3660 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3661 | @Override |
| 3662 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3663 | return isRadioOnWithFeature(callingPackage, null); |
| 3664 | } |
| 3665 | |
| 3666 | |
| 3667 | @Override |
| 3668 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 3669 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 3670 | callingFeatureId); |
| 3671 | } |
| 3672 | |
| 3673 | @Deprecated |
| 3674 | @Override |
| 3675 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 3676 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3679 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3680 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 3681 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3682 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3683 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3684 | return false; |
| 3685 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3686 | |
| 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
| 3689 | return isRadioOnForSubscriber(subId); |
| 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(identity); |
| 3692 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3696 | final long identity = Binder.clearCallingIdentity(); |
| 3697 | try { |
| 3698 | final Phone phone = getPhone(subId); |
| 3699 | if (phone != null) { |
| 3700 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 3701 | } else { |
| 3702 | return false; |
| 3703 | } |
| 3704 | } finally { |
| 3705 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3706 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3710 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3711 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3712 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3713 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3714 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3715 | |
| 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
| 3718 | final Phone phone = getPhone(subId); |
| 3719 | if (phone != null) { |
| 3720 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 3721 | } |
| 3722 | } finally { |
| 3723 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3724 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3728 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3731 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3732 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3733 | |
| 3734 | final long identity = Binder.clearCallingIdentity(); |
| 3735 | try { |
| 3736 | final Phone phone = getPhone(subId); |
| 3737 | if (phone == null) { |
| 3738 | return false; |
| 3739 | } |
| 3740 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 3741 | toggleRadioOnOffForSubscriber(subId); |
| 3742 | } |
| 3743 | return true; |
| 3744 | } finally { |
| 3745 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3746 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3747 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3748 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3749 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 3750 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3751 | /* |
| 3752 | * If any of the Radios are available, it will need to be |
| 3753 | * shutdown. So return true if any Radio is available. |
| 3754 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3755 | final long identity = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3758 | Phone phone = PhoneFactory.getPhone(i); |
| 3759 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3760 | } |
| 3761 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3762 | return false; |
| 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3765 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3769 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3770 | enforceModifyPermission(); |
| 3771 | |
| 3772 | final long identity = Binder.clearCallingIdentity(); |
| 3773 | try { |
| 3774 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3775 | logv("Shutting down Phone " + i); |
| 3776 | shutdownRadioUsingPhoneId(i); |
| 3777 | } |
| 3778 | } finally { |
| 3779 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3780 | } |
| 3781 | } |
| 3782 | |
| 3783 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3784 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3785 | if (phone != null && phone.isRadioAvailable()) { |
| 3786 | phone.shutdownRadio(); |
| 3787 | } |
| 3788 | } |
| 3789 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3790 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3791 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3793 | if (!turnOn) { |
| 3794 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3795 | } |
| 3796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3797 | final long identity = Binder.clearCallingIdentity(); |
| 3798 | try { |
| 3799 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3800 | if (defaultPhone != null) { |
| 3801 | defaultPhone.setRadioPower(turnOn); |
| 3802 | return true; |
| 3803 | } else { |
| 3804 | loge("There's no default phone."); |
| 3805 | return false; |
| 3806 | } |
| 3807 | } finally { |
| 3808 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3809 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3812 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3813 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3814 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3815 | if (!turnOn) { |
| 3816 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3817 | + ",callingPackage=" + getCurrentPackageName()); |
| 3818 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | final long identity = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | final Phone phone = getPhone(subId); |
| 3822 | if (phone != null) { |
| 3823 | phone.setRadioPower(turnOn); |
| 3824 | return true; |
| 3825 | } else { |
| 3826 | return false; |
| 3827 | } |
| 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3830 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3833 | /** |
| 3834 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3835 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3836 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3837 | * powering it off, and these radio off votes will be cleared. |
| 3838 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3839 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3840 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3841 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3842 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3843 | * check its vote. |
| 3844 | * |
| 3845 | * @param subId The subscription ID. |
| 3846 | * @param reason The reason for powering off radio. |
| 3847 | * @return true on success and false on failure. |
| 3848 | */ |
| 3849 | public boolean requestRadioPowerOffForReason(int subId, |
| 3850 | @TelephonyManager.RadioPowerReason int reason) { |
| 3851 | enforceModifyPermission(); |
| 3852 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3853 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3854 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3855 | final long identity = Binder.clearCallingIdentity(); |
| 3856 | try { |
| 3857 | final Phone phone = getPhone(subId); |
| 3858 | if (phone != null) { |
| 3859 | phone.setRadioPowerForReason(false, reason); |
| 3860 | return true; |
| 3861 | } else { |
| 3862 | return false; |
| 3863 | } |
| 3864 | } finally { |
| 3865 | Binder.restoreCallingIdentity(identity); |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | /** |
| 3870 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3871 | * {@link requestRadioPowerOffForReason}. |
| 3872 | * |
| 3873 | * @param subId The subscription ID. |
| 3874 | * @param reason The reason for powering off radio. |
| 3875 | * @return true on success and false on failure. |
| 3876 | */ |
| 3877 | public boolean clearRadioPowerOffForReason(int subId, |
| 3878 | @TelephonyManager.RadioPowerReason int reason) { |
| 3879 | enforceModifyPermission(); |
| 3880 | |
| 3881 | final long identity = Binder.clearCallingIdentity(); |
| 3882 | try { |
| 3883 | final Phone phone = getPhone(subId); |
| 3884 | if (phone != null) { |
| 3885 | phone.setRadioPowerForReason(true, reason); |
| 3886 | return true; |
| 3887 | } else { |
| 3888 | return false; |
| 3889 | } |
| 3890 | } finally { |
| 3891 | Binder.restoreCallingIdentity(identity); |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | /** |
| 3896 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3897 | * |
| 3898 | * @param subId The subscription ID. |
| 3899 | * @param callingPackage The package making the call. |
| 3900 | * @param callingFeatureId The feature in the package. |
| 3901 | * @return List of reasons for powering off radio. |
| 3902 | */ |
| 3903 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3904 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3905 | |
| 3906 | final long identity = Binder.clearCallingIdentity(); |
| 3907 | List result = new ArrayList(); |
| 3908 | try { |
| 3909 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3910 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3911 | return result; |
| 3912 | } |
| 3913 | |
| 3914 | final Phone phone = getPhone(subId); |
| 3915 | if (phone != null) { |
| 3916 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3917 | } |
| 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(identity); |
| 3920 | } |
| 3921 | return result; |
| 3922 | } |
| 3923 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3924 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3925 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3926 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3927 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3928 | |
| 3929 | final long identity = Binder.clearCallingIdentity(); |
| 3930 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3931 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3932 | final Phone phone = getPhone(subId); |
| 3933 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3934 | phone.getDataSettingsManager().setDataEnabled( |
| 3935 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3936 | return true; |
| 3937 | } else { |
| 3938 | return false; |
| 3939 | } |
| 3940 | } finally { |
| 3941 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3942 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3943 | } |
| 3944 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3945 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3946 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3947 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3948 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3949 | |
| 3950 | final long identity = Binder.clearCallingIdentity(); |
| 3951 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3952 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3953 | final Phone phone = getPhone(subId); |
| 3954 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3955 | phone.getDataSettingsManager().setDataEnabled( |
| 3956 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3957 | return true; |
| 3958 | } else { |
| 3959 | return false; |
| 3960 | } |
| 3961 | } finally { |
| 3962 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3963 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3964 | } |
| 3965 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3966 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3967 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3968 | final long identity = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | final Phone phone = getPhone(subId); |
| 3971 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3972 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3973 | } else { |
| 3974 | return false; |
| 3975 | } |
| 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3978 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3982 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3983 | } |
| 3984 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3985 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3986 | enforceCallPermission(); |
| 3987 | |
| 3988 | final long identity = Binder.clearCallingIdentity(); |
| 3989 | try { |
| 3990 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3991 | return; |
| 3992 | } |
| 3993 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3994 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3995 | } finally { |
| 3996 | Binder.restoreCallingIdentity(identity); |
| 3997 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3998 | }; |
| 3999 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4000 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4001 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4002 | |
| 4003 | final long identity = Binder.clearCallingIdentity(); |
| 4004 | try { |
| 4005 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4006 | return false; |
| 4007 | } |
| 4008 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 4009 | } finally { |
| 4010 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4011 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 4014 | /** |
| 4015 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 4016 | * tag on getCallState Binder call. |
| 4017 | */ |
| 4018 | @Deprecated |
| 4019 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4020 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 4021 | if (CompatChanges.isChangeEnabled( |
| 4022 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 4023 | Binder.getCallingUid())) { |
| 4024 | // Do not allow this API to be called on API version 31+, it should only be |
| 4025 | // called on old apps using this Binder call directly. |
| 4026 | throw new SecurityException("This method can only be used for applications " |
| 4027 | + "targeting API version 30 or less."); |
| 4028 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4029 | final long identity = Binder.clearCallingIdentity(); |
| 4030 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 4031 | Phone phone = getPhone(getDefaultSubscription()); |
| 4032 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 4033 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 4034 | } finally { |
| 4035 | Binder.restoreCallingIdentity(identity); |
| 4036 | } |
| 4037 | } |
| 4038 | |
| 4039 | @Override |
| 4040 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 4041 | if (CompatChanges.isChangeEnabled( |
| 4042 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 4043 | Binder.getCallingUid())) { |
| 4044 | // Check READ_PHONE_STATE for API version 31+ |
| 4045 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4046 | featureId, "getCallStateForSubscription")) { |
| 4047 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 4048 | + "targeting API level 31+."); |
| 4049 | } |
| 4050 | } |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4054 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 4055 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(identity); |
| 4058 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4061 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 4062 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 4063 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | @Override |
| 4067 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 | final long identity = Binder.clearCallingIdentity(); |
| 4069 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 4070 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4071 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 4072 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4073 | } else { |
| 4074 | return PhoneConstantConversions.convertDataState( |
| 4075 | PhoneConstants.DataState.DISCONNECTED); |
| 4076 | } |
| 4077 | } finally { |
| 4078 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4079 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4082 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 4083 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 4084 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 4088 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4089 | final long identity = Binder.clearCallingIdentity(); |
| 4090 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 4091 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 4093 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4094 | } else { |
| 4095 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 4096 | } |
| 4097 | } finally { |
| 4098 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4099 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 4103 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4104 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 4105 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4106 | |
| 4107 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4108 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4109 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4110 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4111 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4112 | .setCallingPid(Binder.getCallingPid()) |
| 4113 | .setCallingUid(Binder.getCallingUid()) |
| 4114 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 4115 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4116 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4117 | .build()); |
| 4118 | switch (locationResult) { |
| 4119 | case DENIED_HARD: |
| 4120 | throw new SecurityException("Not allowed to access cell location"); |
| 4121 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 4122 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 4123 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4124 | } |
| 4125 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 4126 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4127 | final long identity = Binder.clearCallingIdentity(); |
| 4128 | try { |
| 4129 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 4130 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 4131 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | } finally { |
| 4133 | Binder.restoreCallingIdentity(identity); |
| 4134 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4137 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 4138 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 4139 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 4140 | // registered cell info, so return a NULL country instead. |
| 4141 | final long identity = Binder.clearCallingIdentity(); |
| 4142 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 4143 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 4144 | // Get default phone in this case. |
| 4145 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 4146 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 4147 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 4149 | if (phone == null) return ""; |
| 4150 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 4151 | if (sst == null) return ""; |
| 4152 | LocaleTracker lt = sst.getLocaleTracker(); |
| 4153 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 4154 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 4155 | } finally { |
| 4156 | Binder.restoreCallingIdentity(identity); |
| 4157 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 4160 | /** |
| 4161 | * This method was removed due to potential issues caused by performing partial |
| 4162 | * updates of service state, and lack of a credible use case. |
| 4163 | * |
| 4164 | * This has the ability to break the telephony implementation by disabling notification of |
| 4165 | * changes in device connectivity. DO NOT USE THIS! |
| 4166 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 4167 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4168 | public void enableLocationUpdates() { |
| 4169 | mApp.enforceCallingOrSelfPermission( |
| 4170 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 4173 | /** |
| 4174 | * This method was removed due to potential issues caused by performing partial |
| 4175 | * updates of service state, and lack of a credible use case. |
| 4176 | * |
| 4177 | * This has the ability to break the telephony implementation by disabling notification of |
| 4178 | * changes in device connectivity. DO NOT USE THIS! |
| 4179 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4180 | @Override |
| 4181 | public void disableLocationUpdates() { |
| 4182 | mApp.enforceCallingOrSelfPermission( |
| 4183 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | @Override |
| 4187 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4188 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 4189 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 4190 | try { |
| 4191 | mApp.getSystemService(AppOpsManager.class) |
| 4192 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 4193 | } catch (SecurityException e) { |
| 4194 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 4195 | throw e; |
| 4196 | } |
| 4197 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4198 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 4199 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 4200 | throw new SecurityException( |
| 4201 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 4202 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 4203 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 4204 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4205 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 4206 | return null; |
| 4207 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 4208 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 4209 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4210 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4211 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 4212 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4213 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 4214 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 4215 | for (CellInfo ci : info) { |
| 4216 | if (ci instanceof CellInfoGsm) { |
| 4217 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 4218 | } else if (ci instanceof CellInfoWcdma) { |
| 4219 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 4220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4221 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 4222 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4223 | } |
| 4224 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 4225 | private List<CellInfo> getCachedCellInfo() { |
| 4226 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 4227 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4228 | List<CellInfo> info = phone.getAllCellInfo(); |
| 4229 | if (info != null) cellInfos.addAll(info); |
| 4230 | } |
| 4231 | return cellInfos; |
| 4232 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4233 | |
| 4234 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4235 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4236 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 4237 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4238 | |
| 4239 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4240 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4241 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4242 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4243 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4244 | .setCallingPid(Binder.getCallingPid()) |
| 4245 | .setCallingUid(Binder.getCallingUid()) |
| 4246 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 4247 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4248 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4249 | .build()); |
| 4250 | switch (locationResult) { |
| 4251 | case DENIED_HARD: |
| 4252 | throw new SecurityException("Not allowed to access cell info"); |
| 4253 | case DENIED_SOFT: |
| 4254 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4257 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 4258 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 4259 | return getCachedCellInfo(); |
| 4260 | } |
| 4261 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 4262 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 4263 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4264 | final long identity = Binder.clearCallingIdentity(); |
| 4265 | try { |
| 4266 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 4267 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 4268 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 4269 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4270 | if (info != null) cellInfos.addAll(info); |
| 4271 | } |
| 4272 | return cellInfos; |
| 4273 | } finally { |
| 4274 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4275 | } |
| 4276 | } |
| 4277 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 4278 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4279 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 4280 | String callingFeatureId) { |
| 4281 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 4282 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4286 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 4287 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 4288 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4289 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4292 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 4293 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4294 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 4295 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4296 | |
| 4297 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4298 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4299 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4300 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4301 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4302 | .setCallingPid(Binder.getCallingPid()) |
| 4303 | .setCallingUid(Binder.getCallingUid()) |
| 4304 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 4305 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 4306 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4307 | .build()); |
| 4308 | switch (locationResult) { |
| 4309 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4310 | if (TelephonyPermissions |
| 4311 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 4312 | // Safetynet logging for b/154934934 |
| 4313 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 4314 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4315 | throw new SecurityException("Not allowed to access cell info"); |
| 4316 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4317 | if (TelephonyPermissions |
| 4318 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 4319 | // Safetynet logging for b/154934934 |
| 4320 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 4321 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 4322 | try { |
| 4323 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 4324 | } catch (RemoteException re) { |
| 4325 | // Drop without consequences |
| 4326 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4327 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 4328 | } |
| 4329 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 4330 | |
| 4331 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 4332 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 4333 | |
| 4334 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 4335 | } |
| 4336 | |
| 4337 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 4338 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 4339 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 4340 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | |
| 4342 | final long identity = Binder.clearCallingIdentity(); |
| 4343 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 4344 | Phone phone = getPhone(subId); |
| 4345 | if (phone == null) { |
| 4346 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 4347 | } else { |
| 4348 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 4349 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4350 | } finally { |
| 4351 | Binder.restoreCallingIdentity(identity); |
| 4352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4353 | } |
| 4354 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4355 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4356 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4357 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4358 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4359 | return null; |
| 4360 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4361 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4362 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 4363 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4364 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4365 | return null; |
| 4366 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4367 | |
| 4368 | final long identity = Binder.clearCallingIdentity(); |
| 4369 | try { |
| 4370 | return phone.getImei(); |
| 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(identity); |
| 4373 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4374 | } |
| 4375 | |
| 4376 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 4377 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 4378 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 4379 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 4380 | callingFeatureId, "getPrimaryImei")) { |
| 4381 | throw new SecurityException("Caller does not have permission"); |
| 4382 | } |
| 4383 | final long identity = Binder.clearCallingIdentity(); |
| 4384 | try { |
| 4385 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4386 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 4387 | return phone.getImei(); |
| 4388 | } |
| 4389 | } |
| 4390 | throw new UnsupportedOperationException("Operation not supported"); |
| 4391 | } finally { |
| 4392 | Binder.restoreCallingIdentity(identity); |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4397 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 4398 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4399 | String tac = null; |
| 4400 | if (phone != null) { |
| 4401 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 4402 | try { |
| 4403 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 4404 | } catch (IndexOutOfBoundsException e) { |
| 4405 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 4406 | return null; |
| 4407 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4408 | } |
| 4409 | return tac; |
| 4410 | } |
| 4411 | |
| 4412 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4413 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4414 | try { |
| 4415 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4416 | } catch (SecurityException se) { |
| 4417 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 4418 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 4419 | + Binder.getCallingUid()); |
| 4420 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4421 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4422 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 4423 | return null; |
| 4424 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4425 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4426 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 4427 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4428 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4429 | return null; |
| 4430 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4431 | |
| 4432 | final long identity = Binder.clearCallingIdentity(); |
| 4433 | try { |
| 4434 | return phone.getMeid(); |
| 4435 | } finally { |
| 4436 | Binder.restoreCallingIdentity(identity); |
| 4437 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4441 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 4442 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4443 | String manufacturerCode = null; |
| 4444 | if (phone != null) { |
| 4445 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 4446 | try { |
| 4447 | manufacturerCode = |
| 4448 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 4449 | } catch (IndexOutOfBoundsException e) { |
| 4450 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 4451 | return null; |
| 4452 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 4453 | } |
| 4454 | return manufacturerCode; |
| 4455 | } |
| 4456 | |
| 4457 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4458 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 4459 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4460 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4461 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4462 | return null; |
| 4463 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4464 | int subId = phone.getSubId(); |
| 4465 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4466 | mApp, subId, callingPackage, callingFeatureId, |
| 4467 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4468 | return null; |
| 4469 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4470 | |
| 4471 | final long identity = Binder.clearCallingIdentity(); |
| 4472 | try { |
| 4473 | return phone.getDeviceSvn(); |
| 4474 | } finally { |
| 4475 | Binder.restoreCallingIdentity(identity); |
| 4476 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4477 | } |
| 4478 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4479 | @Override |
| 4480 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4481 | final long identity = Binder.clearCallingIdentity(); |
| 4482 | try { |
| 4483 | final Phone phone = getPhone(subId); |
| 4484 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
| 4487 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | @Override |
| 4491 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4492 | final long identity = Binder.clearCallingIdentity(); |
| 4493 | try { |
| 4494 | final Phone phone = getPhone(subId); |
| 4495 | return phone == null ? null : phone.getCarrierName(); |
| 4496 | } finally { |
| 4497 | Binder.restoreCallingIdentity(identity); |
| 4498 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 4499 | } |
| 4500 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 4501 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4502 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4503 | final long identity = Binder.clearCallingIdentity(); |
| 4504 | try { |
| 4505 | final Phone phone = getPhone(subId); |
| 4506 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4507 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4514 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4515 | final long identity = Binder.clearCallingIdentity(); |
| 4516 | try { |
| 4517 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 4518 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 4519 | } finally { |
| 4520 | Binder.restoreCallingIdentity(identity); |
| 4521 | } |
| 4522 | } |
| 4523 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 4524 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 4525 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 4526 | if (!isSubscriptionMccMnc) { |
| 4527 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 4528 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 4529 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4530 | if (phone == null) { |
| 4531 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 4532 | } |
| 4533 | final long identity = Binder.clearCallingIdentity(); |
| 4534 | try { |
| 4535 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 4536 | } finally { |
| 4537 | Binder.restoreCallingIdentity(identity); |
| 4538 | } |
| 4539 | } |
| 4540 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4541 | // |
| 4542 | // Internal helper methods. |
| 4543 | // |
| 4544 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 4545 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4546 | * Make sure the caller is the calling package itself |
| 4547 | * |
| 4548 | * @throws SecurityException if the caller is not the calling package |
| 4549 | */ |
| 4550 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 4551 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 4552 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 4553 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4554 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 4555 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 4556 | } catch (PackageManager.NameNotFoundException e) { |
| 4557 | // packageUid is -1 |
| 4558 | } |
| 4559 | if (packageUid != callingUid) { |
| 4560 | throw new SecurityException(message + ": Package " + callingPackage |
| 4561 | + " does not belong to " + callingUid); |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4566 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 4567 | * |
| 4568 | * @throws SecurityException if the caller does not have the required permission |
| 4569 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4570 | @VisibleForTesting |
| 4571 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4572 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 4573 | } |
| 4574 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4575 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 4576 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4577 | * |
| 4578 | * @throws SecurityException if the caller does not have the required permission |
| 4579 | */ |
| 4580 | @VisibleForTesting |
| 4581 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 4582 | enforceReadPermission(null); |
| 4583 | } |
| 4584 | |
| 4585 | /** |
| 4586 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 4587 | * |
| 4588 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 4589 | */ |
| 4590 | @VisibleForTesting |
| 4591 | public void enforceReadPermission(String msg) { |
| 4592 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 4593 | } |
| 4594 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 4595 | private void enforceActiveEmergencySessionPermission() { |
| 4596 | mApp.enforceCallingOrSelfPermission( |
| 4597 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 4598 | } |
| 4599 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4600 | /** |
| 4601 | * Make sure the caller has the CALL_PHONE permission. |
| 4602 | * |
| 4603 | * @throws SecurityException if the caller does not have the required permission |
| 4604 | */ |
| 4605 | private void enforceCallPermission() { |
| 4606 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 4607 | } |
| 4608 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 4609 | private void enforceSettingsPermission() { |
| 4610 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4611 | } |
| 4612 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 4613 | private void enforceRebootPermission() { |
| 4614 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 4615 | } |
| 4616 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 4617 | /** |
| 4618 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 4619 | * @param message - log message to print. |
| 4620 | * @throws SecurityException if the caller does not have the required permission |
| 4621 | */ |
| 4622 | private void enforceSatelliteCommunicationPermission(String message) { |
| 4623 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 4624 | } |
| 4625 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4626 | private String createTelUrl(String number) { |
| 4627 | if (TextUtils.isEmpty(number)) { |
| 4628 | return null; |
| 4629 | } |
| 4630 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4631 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4632 | } |
| 4633 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4634 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 4635 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4636 | } |
| 4637 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 4638 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 4639 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4642 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 4643 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4644 | } |
| 4645 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4646 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4647 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4648 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4651 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4652 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4653 | final long identity = Binder.clearCallingIdentity(); |
| 4654 | try { |
| 4655 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4656 | if (phone == null) { |
| 4657 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4658 | } else { |
| 4659 | return phone.getPhoneType(); |
| 4660 | } |
| 4661 | } finally { |
| 4662 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4663 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | /** |
| 4667 | * Returns the CDMA ERI icon index to display |
| 4668 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4669 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4670 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4671 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4672 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4675 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4676 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4677 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4679 | mApp, subId, callingPackage, callingFeatureId, |
| 4680 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4681 | return -1; |
| 4682 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | |
| 4684 | final long identity = Binder.clearCallingIdentity(); |
| 4685 | try { |
| 4686 | final Phone phone = getPhone(subId); |
| 4687 | if (phone != null) { |
| 4688 | return phone.getCdmaEriIconIndex(); |
| 4689 | } else { |
| 4690 | return -1; |
| 4691 | } |
| 4692 | } finally { |
| 4693 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4694 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | /** |
| 4698 | * Returns the CDMA ERI icon mode, |
| 4699 | * 0 - ON |
| 4700 | * 1 - FLASHING |
| 4701 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4702 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4703 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4704 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4705 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4706 | } |
| 4707 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4708 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4709 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4710 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4711 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4712 | mApp, subId, callingPackage, callingFeatureId, |
| 4713 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4714 | return -1; |
| 4715 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4716 | |
| 4717 | final long identity = Binder.clearCallingIdentity(); |
| 4718 | try { |
| 4719 | final Phone phone = getPhone(subId); |
| 4720 | if (phone != null) { |
| 4721 | return phone.getCdmaEriIconMode(); |
| 4722 | } else { |
| 4723 | return -1; |
| 4724 | } |
| 4725 | } finally { |
| 4726 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4727 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | /** |
| 4731 | * Returns the CDMA ERI text, |
| 4732 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4733 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4734 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4735 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4736 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4737 | } |
| 4738 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4739 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4740 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4741 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4742 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4743 | mApp, subId, callingPackage, callingFeatureId, |
| 4744 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4745 | return null; |
| 4746 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4747 | |
| 4748 | final long identity = Binder.clearCallingIdentity(); |
| 4749 | try { |
| 4750 | final Phone phone = getPhone(subId); |
| 4751 | if (phone != null) { |
| 4752 | return phone.getCdmaEriText(); |
| 4753 | } else { |
| 4754 | return null; |
| 4755 | } |
| 4756 | } finally { |
| 4757 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4758 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4762 | * Returns the CDMA MDN. |
| 4763 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4764 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4765 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4767 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4768 | |
| 4769 | final long identity = Binder.clearCallingIdentity(); |
| 4770 | try { |
| 4771 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4772 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4773 | return phone.getLine1Number(); |
| 4774 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4775 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4776 | return null; |
| 4777 | } |
| 4778 | } finally { |
| 4779 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | /** |
| 4784 | * Returns the CDMA MIN. |
| 4785 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4786 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4787 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4788 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4789 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4790 | |
| 4791 | final long identity = Binder.clearCallingIdentity(); |
| 4792 | try { |
| 4793 | final Phone phone = getPhone(subId); |
| 4794 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4795 | return phone.getCdmaMin(); |
| 4796 | } else { |
| 4797 | return null; |
| 4798 | } |
| 4799 | } finally { |
| 4800 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4801 | } |
| 4802 | } |
| 4803 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4804 | @Override |
| 4805 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4806 | INumberVerificationCallback callback, String callingPackage) { |
| 4807 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4808 | != PERMISSION_GRANTED) { |
| 4809 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4810 | } |
| 4811 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4812 | |
| 4813 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4814 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4815 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4816 | + "calling package: " + callingPackage |
| 4817 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | if (range == null) { |
| 4821 | throw new NullPointerException("Range must be non-null"); |
| 4822 | } |
| 4823 | |
| 4824 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4825 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4826 | |
| 4827 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4828 | } |
| 4829 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4830 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4831 | * Returns true if CDMA provisioning needs to run. |
| 4832 | */ |
| 4833 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | final long identity = Binder.clearCallingIdentity(); |
| 4835 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4836 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4837 | } finally { |
| 4838 | Binder.restoreCallingIdentity(identity); |
| 4839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4843 | * Sets the voice mail number of a given subId. |
| 4844 | */ |
| 4845 | @Override |
| 4846 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4847 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4848 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4849 | |
| 4850 | final long identity = Binder.clearCallingIdentity(); |
| 4851 | try { |
| 4852 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4853 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4854 | return success; |
| 4855 | } finally { |
| 4856 | Binder.restoreCallingIdentity(identity); |
| 4857 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4858 | } |
| 4859 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4860 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4861 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4862 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4863 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4864 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4865 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4866 | throw new SecurityException("caller must be system dialer"); |
| 4867 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4868 | |
| 4869 | final long identity = Binder.clearCallingIdentity(); |
| 4870 | try { |
| 4871 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4872 | if (phoneAccountHandle == null) { |
| 4873 | return null; |
| 4874 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4875 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4878 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4882 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4883 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4884 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4885 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4886 | mApp, subId, callingPackage, callingFeatureId, |
| 4887 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4888 | return null; |
| 4889 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4890 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4891 | final long identity = Binder.clearCallingIdentity(); |
| 4892 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4893 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4894 | } finally { |
| 4895 | Binder.restoreCallingIdentity(identity); |
| 4896 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4897 | } |
| 4898 | |
| 4899 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4900 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4901 | VisualVoicemailSmsFilterSettings settings) { |
| 4902 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4903 | |
| 4904 | final long identity = Binder.clearCallingIdentity(); |
| 4905 | try { |
| 4906 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4907 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4908 | } finally { |
| 4909 | Binder.restoreCallingIdentity(identity); |
| 4910 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4914 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4915 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4916 | |
| 4917 | final long identity = Binder.clearCallingIdentity(); |
| 4918 | try { |
| 4919 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4920 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4921 | } finally { |
| 4922 | Binder.restoreCallingIdentity(identity); |
| 4923 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4927 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4928 | String callingPackage, int subId) { |
| 4929 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4930 | |
| 4931 | final long identity = Binder.clearCallingIdentity(); |
| 4932 | try { |
| 4933 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4934 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4935 | } finally { |
| 4936 | Binder.restoreCallingIdentity(identity); |
| 4937 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4941 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4942 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | |
| 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
| 4946 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4947 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4948 | } finally { |
| 4949 | Binder.restoreCallingIdentity(identity); |
| 4950 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4951 | } |
| 4952 | |
| 4953 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4954 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4955 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4956 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4957 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4958 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4959 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4960 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4961 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4962 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4963 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4964 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4965 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4966 | * Sets the voice activation state of a given subId. |
| 4967 | */ |
| 4968 | @Override |
| 4969 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4970 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4971 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | |
| 4973 | final long identity = Binder.clearCallingIdentity(); |
| 4974 | try { |
| 4975 | final Phone phone = getPhone(subId); |
| 4976 | if (phone != null) { |
| 4977 | phone.setVoiceActivationState(activationState); |
| 4978 | } else { |
| 4979 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4980 | } |
| 4981 | } finally { |
| 4982 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4983 | } |
| 4984 | } |
| 4985 | |
| 4986 | /** |
| 4987 | * Sets the data activation state of a given subId. |
| 4988 | */ |
| 4989 | @Override |
| 4990 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4992 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | |
| 4994 | final long identity = Binder.clearCallingIdentity(); |
| 4995 | try { |
| 4996 | final Phone phone = getPhone(subId); |
| 4997 | if (phone != null) { |
| 4998 | phone.setDataActivationState(activationState); |
| 4999 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5000 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | } |
| 5002 | } finally { |
| 5003 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 5004 | } |
| 5005 | } |
| 5006 | |
| 5007 | /** |
| 5008 | * Returns the voice activation state of a given subId. |
| 5009 | */ |
| 5010 | @Override |
| 5011 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5012 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 5014 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5015 | final long identity = Binder.clearCallingIdentity(); |
| 5016 | try { |
| 5017 | if (phone != null) { |
| 5018 | return phone.getVoiceActivationState(); |
| 5019 | } else { |
| 5020 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 5021 | } |
| 5022 | } finally { |
| 5023 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 5024 | } |
| 5025 | } |
| 5026 | |
| 5027 | /** |
| 5028 | * Returns the data activation state of a given subId. |
| 5029 | */ |
| 5030 | @Override |
| 5031 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5032 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5033 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 5034 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5035 | final long identity = Binder.clearCallingIdentity(); |
| 5036 | try { |
| 5037 | if (phone != null) { |
| 5038 | return phone.getDataActivationState(); |
| 5039 | } else { |
| 5040 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 5041 | } |
| 5042 | } finally { |
| 5043 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5048 | * Returns the unread count of voicemails for a subId |
| 5049 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5050 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5051 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 5052 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 5053 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5054 | mApp, subId, callingPackage, callingFeatureId, |
| 5055 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 5056 | return 0; |
| 5057 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5058 | final long identity = Binder.clearCallingIdentity(); |
| 5059 | try { |
| 5060 | final Phone phone = getPhone(subId); |
| 5061 | if (phone != null) { |
| 5062 | return phone.getVoiceMessageCount(); |
| 5063 | } else { |
| 5064 | return 0; |
| 5065 | } |
| 5066 | } finally { |
| 5067 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5068 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5072 | * returns true, if the device is in a state where both voice and data |
| 5073 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 5074 | */ |
| 5075 | @Override |
| 5076 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5077 | final long identity = Binder.clearCallingIdentity(); |
| 5078 | try { |
| 5079 | final Phone phone = getPhone(subId); |
| 5080 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 5081 | } finally { |
| 5082 | Binder.restoreCallingIdentity(identity); |
| 5083 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 5087 | * Send the dialer code if called from the current default dialer or the caller has |
| 5088 | * carrier privilege. |
| 5089 | * @param inputCode The dialer code to send |
| 5090 | */ |
| 5091 | @Override |
| 5092 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5093 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 5094 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 5095 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 5096 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 5097 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5098 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5099 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 5100 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5101 | |
| 5102 | final long identity = Binder.clearCallingIdentity(); |
| 5103 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5104 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5105 | } finally { |
| 5106 | Binder.restoreCallingIdentity(identity); |
| 5107 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 5108 | } |
| 5109 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5110 | @Override |
| 5111 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5112 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5113 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5114 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5115 | final long identity = Binder.clearCallingIdentity(); |
| 5116 | try { |
| 5117 | if (!isActiveSubscription(subId)) { |
| 5118 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 5119 | } |
| 5120 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 5121 | } finally { |
| 5122 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5123 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5124 | } |
| 5125 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5126 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 5127 | public boolean isInEmergencySmsMode() { |
| 5128 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 5129 | final long identity = Binder.clearCallingIdentity(); |
| 5130 | try { |
| 5131 | for (Phone phone : PhoneFactory.getPhones()) { |
| 5132 | if (phone.isInEmergencySmsMode()) { |
| 5133 | return true; |
| 5134 | } |
| 5135 | } |
| 5136 | } finally { |
| 5137 | Binder.restoreCallingIdentity(identity); |
| 5138 | } |
| 5139 | return false; |
| 5140 | } |
| 5141 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5142 | /** |
| 5143 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5144 | * @param subId The subscription to use to check the configuration. |
| 5145 | * @param c The callback that will be used to send the result. |
| 5146 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 5147 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5148 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 5149 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5150 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5151 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5152 | |
| 5153 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5154 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5155 | "IMS not available on device."); |
| 5156 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5157 | final long token = Binder.clearCallingIdentity(); |
| 5158 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5159 | int slotId = getSlotIndexOrException(subId); |
| 5160 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 5161 | |
| 5162 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5163 | if (controller != null) { |
| 5164 | ImsManager imsManager = controller.getImsManager(subId); |
| 5165 | if (imsManager != null) { |
| 5166 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 5167 | } else { |
| 5168 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5169 | } |
| 5170 | } else { |
| 5171 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5172 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5173 | } catch (ImsException e) { |
| 5174 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5175 | } finally { |
| 5176 | Binder.restoreCallingIdentity(token); |
| 5177 | } |
| 5178 | } |
| 5179 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5180 | /** |
| 5181 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5182 | * @param subId The subscription to use to check the configuration. |
| 5183 | * @param c The callback that will be used to send the result. |
| 5184 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5185 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5186 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5187 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5188 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5189 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5190 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5191 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 5192 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 5193 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 5194 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 5195 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5196 | if (controller != null) { |
| 5197 | ImsManager imsManager = controller.getImsManager(subId); |
| 5198 | if (imsManager != null) { |
| 5199 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 5200 | } else { |
| 5201 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 5202 | + "is inactive, ignoring unregister."); |
| 5203 | // If the ImsManager is not valid, just return, since the callback |
| 5204 | // will already have been removed internally. |
| 5205 | } |
| 5206 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 5207 | } finally { |
| 5208 | Binder.restoreCallingIdentity(token); |
| 5209 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5210 | } |
| 5211 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 5212 | /** |
| 5213 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 5214 | */ |
| 5215 | @Override |
| 5216 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 5217 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 5218 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5219 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5220 | "IMS not available on device."); |
| 5221 | } |
| 5222 | final long token = Binder.clearCallingIdentity(); |
| 5223 | try { |
| 5224 | Phone phone = getPhone(subId); |
| 5225 | if (phone == null) { |
| 5226 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 5227 | + subId + "'"); |
| 5228 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5229 | } |
| 5230 | phone.getImsRegistrationState(regState -> { |
| 5231 | try { |
| 5232 | consumer.accept((regState == null) |
| 5233 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 5234 | } catch (RemoteException e) { |
| 5235 | // Ignore if the remote process is no longer available to call back. |
| 5236 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 5237 | } |
| 5238 | }); |
| 5239 | } finally { |
| 5240 | Binder.restoreCallingIdentity(token); |
| 5241 | } |
| 5242 | } |
| 5243 | |
| 5244 | /** |
| 5245 | * Get the transport type for the IMS service registration state. |
| 5246 | */ |
| 5247 | @Override |
| 5248 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5249 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5250 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 5251 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5252 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5253 | "IMS not available on device."); |
| 5254 | } |
| 5255 | final long token = Binder.clearCallingIdentity(); |
| 5256 | try { |
| 5257 | Phone phone = getPhone(subId); |
| 5258 | if (phone == null) { |
| 5259 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 5260 | + subId + "'"); |
| 5261 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5262 | } |
| 5263 | phone.getImsRegistrationTech(regTech -> { |
| 5264 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 5265 | int regTechConverted = (regTech == null) |
| 5266 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 5267 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 5268 | regTechConverted); |
| 5269 | try { |
| 5270 | consumer.accept(regTechConverted); |
| 5271 | } catch (RemoteException e) { |
| 5272 | // Ignore if the remote process is no longer available to call back. |
| 5273 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 5274 | } |
| 5275 | }); |
| 5276 | } finally { |
| 5277 | Binder.restoreCallingIdentity(token); |
| 5278 | } |
| 5279 | } |
| 5280 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5281 | /** |
| 5282 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5283 | * @param subId The subscription to use to check the configuration. |
| 5284 | * @param c The callback that will be used to send the result. |
| 5285 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5286 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5287 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 5288 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5289 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5290 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5291 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5292 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5293 | "IMS not available on device."); |
| 5294 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5295 | final long token = Binder.clearCallingIdentity(); |
| 5296 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5297 | int slotId = getSlotIndexOrException(subId); |
| 5298 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5299 | |
| 5300 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5301 | if (controller != null) { |
| 5302 | ImsManager imsManager = controller.getImsManager(subId); |
| 5303 | if (imsManager != null) { |
| 5304 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 5305 | } else { |
| 5306 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5307 | } |
| 5308 | } else { |
| 5309 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5310 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5311 | } catch (ImsException e) { |
| 5312 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5313 | } finally { |
| 5314 | Binder.restoreCallingIdentity(token); |
| 5315 | } |
| 5316 | } |
| 5317 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5318 | /** |
| 5319 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5320 | * @param subId The subscription to use to check the configuration. |
| 5321 | * @param c The callback that will be used to send the result. |
| 5322 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5323 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5324 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5325 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5326 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5327 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5328 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5329 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 5330 | |
| 5331 | final long token = Binder.clearCallingIdentity(); |
| 5332 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5333 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5334 | if (controller != null) { |
| 5335 | ImsManager imsManager = controller.getImsManager(subId); |
| 5336 | if (imsManager != null) { |
| 5337 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 5338 | } else { |
| 5339 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 5340 | + " is inactive, ignoring unregister."); |
| 5341 | // If the ImsManager is not valid, just return, since the callback |
| 5342 | // will already have been removed internally. |
| 5343 | } |
| 5344 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 5345 | } finally { |
| 5346 | Binder.restoreCallingIdentity(token); |
| 5347 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5351 | public boolean isCapable(int subId, int capability, int regTech) { |
| 5352 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5353 | final long token = Binder.clearCallingIdentity(); |
| 5354 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5355 | int slotId = getSlotIndexOrException(subId); |
| 5356 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 5357 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 5358 | } catch (com.android.ims.ImsException e) { |
| 5359 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 5360 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5361 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 5362 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 5363 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5364 | } finally { |
| 5365 | Binder.restoreCallingIdentity(token); |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5370 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 5371 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5372 | final long token = Binder.clearCallingIdentity(); |
| 5373 | try { |
| 5374 | Phone phone = getPhone(subId); |
| 5375 | if (phone == null) return false; |
| 5376 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 5377 | } catch (com.android.ims.ImsException e) { |
| 5378 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 5379 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5380 | } finally { |
| 5381 | Binder.restoreCallingIdentity(token); |
| 5382 | } |
| 5383 | } |
| 5384 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5385 | /** |
| 5386 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 5387 | * subscription. |
| 5388 | * @param subId The subscription to use to check the configuration. |
| 5389 | * @param callback The callback that will be used to send the result. |
| 5390 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 5391 | * @param transportType The transport type of the MmTelFeature capability. |
| 5392 | */ |
| 5393 | @Override |
| 5394 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 5395 | int transportType) { |
| 5396 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5397 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5398 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5399 | "IMS not available on device."); |
| 5400 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5401 | final long token = Binder.clearCallingIdentity(); |
| 5402 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5403 | int slotId = getSlotIndex(subId); |
| 5404 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5405 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 5406 | + subId + "'"); |
| 5407 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5408 | } |
| 5409 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 5410 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 5411 | transportType, aBoolean -> { |
| 5412 | try { |
| 5413 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 5414 | } catch (RemoteException e) { |
| 5415 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 5416 | + "running. Ignore"); |
| 5417 | } |
| 5418 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5419 | } catch (ImsException e) { |
| 5420 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5421 | } finally { |
| 5422 | Binder.restoreCallingIdentity(token); |
| 5423 | } |
| 5424 | } |
| 5425 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5426 | /** |
| 5427 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5428 | * @param subId The subscription to use to check the configuration. |
| 5429 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5430 | @Override |
| 5431 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5432 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5433 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5434 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5435 | final long token = Binder.clearCallingIdentity(); |
| 5436 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5437 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5438 | // 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] | 5439 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5440 | } catch (ImsException e) { |
| 5441 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5442 | } finally { |
| 5443 | Binder.restoreCallingIdentity(token); |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5448 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5449 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5450 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5451 | final long identity = Binder.clearCallingIdentity(); |
| 5452 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5453 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5454 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5455 | // 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] | 5456 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5457 | } catch (ImsException e) { |
| 5458 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5459 | } finally { |
| 5460 | Binder.restoreCallingIdentity(identity); |
| 5461 | } |
| 5462 | } |
| 5463 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5464 | /** |
| 5465 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5466 | * @param subId The subscription to use to check the configuration. |
| 5467 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5468 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 5469 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5470 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5471 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5472 | final long identity = Binder.clearCallingIdentity(); |
| 5473 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5474 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5475 | // 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] | 5476 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5477 | } catch (ImsException e) { |
| 5478 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5479 | } finally { |
| 5480 | Binder.restoreCallingIdentity(identity); |
| 5481 | } |
| 5482 | } |
| 5483 | |
| 5484 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5485 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5486 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5487 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5488 | final long identity = Binder.clearCallingIdentity(); |
| 5489 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5490 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5491 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5492 | // 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] | 5493 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5494 | } catch (ImsException e) { |
| 5495 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5496 | } finally { |
| 5497 | Binder.restoreCallingIdentity(identity); |
| 5498 | } |
| 5499 | } |
| 5500 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5501 | /** |
| 5502 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5503 | * @param subId The subscription to use to check the configuration. |
| 5504 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5505 | @Override |
| 5506 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5507 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5508 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5509 | final long identity = Binder.clearCallingIdentity(); |
| 5510 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5511 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5512 | // 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] | 5513 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5514 | } catch (ImsException e) { |
| 5515 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5516 | } finally { |
| 5517 | Binder.restoreCallingIdentity(identity); |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5522 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5524 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5525 | final long identity = Binder.clearCallingIdentity(); |
| 5526 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5527 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5528 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5529 | // 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] | 5530 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5531 | } catch (ImsException e) { |
| 5532 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5533 | } finally { |
| 5534 | Binder.restoreCallingIdentity(identity); |
| 5535 | } |
| 5536 | } |
| 5537 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5538 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5539 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5540 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5541 | * @param subId The subscription to use to check the configuration. |
| 5542 | */ |
| 5543 | @Override |
| 5544 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5545 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5546 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 5547 | final long identity = Binder.clearCallingIdentity(); |
| 5548 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5549 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5550 | // 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] | 5551 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5552 | } catch (ImsException e) { |
| 5553 | throw new ServiceSpecificException(e.getCode()); |
| 5554 | } finally { |
| 5555 | Binder.restoreCallingIdentity(identity); |
| 5556 | } |
| 5557 | } |
| 5558 | |
| 5559 | /** |
| 5560 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5561 | * Requires MODIFY_PHONE_STATE permission. |
| 5562 | * @param subId The subscription to use to check the configuration. |
| 5563 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5564 | * false otherwise |
| 5565 | */ |
| 5566 | @Override |
| 5567 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5569 | "setCrossSimCallingEnabled"); |
| 5570 | final long identity = Binder.clearCallingIdentity(); |
| 5571 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5572 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5573 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5574 | // 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] | 5575 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5576 | } catch (ImsException e) { |
| 5577 | throw new ServiceSpecificException(e.getCode()); |
| 5578 | } finally { |
| 5579 | Binder.restoreCallingIdentity(identity); |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5584 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5585 | * @param subId The subscription to use to check the configuration. |
| 5586 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5587 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5588 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5589 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5590 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5591 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5592 | final long identity = Binder.clearCallingIdentity(); |
| 5593 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5594 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5595 | // 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] | 5596 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5597 | } catch (ImsException e) { |
| 5598 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5599 | } finally { |
| 5600 | Binder.restoreCallingIdentity(identity); |
| 5601 | } |
| 5602 | } |
| 5603 | |
| 5604 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5605 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5606 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5607 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5608 | final long identity = Binder.clearCallingIdentity(); |
| 5609 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5610 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5611 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5612 | // 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] | 5613 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5614 | } catch (ImsException e) { |
| 5615 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5616 | } finally { |
| 5617 | Binder.restoreCallingIdentity(identity); |
| 5618 | } |
| 5619 | } |
| 5620 | |
| 5621 | @Override |
| 5622 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5623 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5624 | "setVoWiFiNonPersistent"); |
| 5625 | final long identity = Binder.clearCallingIdentity(); |
| 5626 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5627 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5628 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5629 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5630 | } catch (ImsException e) { |
| 5631 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5632 | } finally { |
| 5633 | Binder.restoreCallingIdentity(identity); |
| 5634 | } |
| 5635 | } |
| 5636 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5637 | /** |
| 5638 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5639 | * @param subId The subscription to use to check the configuration. |
| 5640 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5641 | @Override |
| 5642 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5643 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5644 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5645 | final long identity = Binder.clearCallingIdentity(); |
| 5646 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5647 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5648 | // 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] | 5649 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5650 | } catch (ImsException e) { |
| 5651 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5652 | } finally { |
| 5653 | Binder.restoreCallingIdentity(identity); |
| 5654 | } |
| 5655 | } |
| 5656 | |
| 5657 | @Override |
| 5658 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5660 | "setVoWiFiModeSetting"); |
| 5661 | final long identity = Binder.clearCallingIdentity(); |
| 5662 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5663 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5664 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5665 | // 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] | 5666 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5667 | } catch (ImsException e) { |
| 5668 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
| 5671 | } |
| 5672 | } |
| 5673 | |
| 5674 | @Override |
| 5675 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5676 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 5677 | final long identity = Binder.clearCallingIdentity(); |
| 5678 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5679 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5680 | // 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] | 5681 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5682 | } catch (ImsException e) { |
| 5683 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5684 | } finally { |
| 5685 | Binder.restoreCallingIdentity(identity); |
| 5686 | } |
| 5687 | } |
| 5688 | |
| 5689 | @Override |
| 5690 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5691 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5692 | "setVoWiFiRoamingModeSetting"); |
| 5693 | final long identity = Binder.clearCallingIdentity(); |
| 5694 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5695 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5696 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5697 | // 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] | 5698 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5699 | } catch (ImsException e) { |
| 5700 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5701 | } finally { |
| 5702 | Binder.restoreCallingIdentity(identity); |
| 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | @Override |
| 5707 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5708 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5709 | "setRttCapabilityEnabled"); |
| 5710 | final long identity = Binder.clearCallingIdentity(); |
| 5711 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5712 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5713 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5714 | // 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] | 5715 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5716 | } catch (ImsException e) { |
| 5717 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5718 | } finally { |
| 5719 | Binder.restoreCallingIdentity(identity); |
| 5720 | } |
| 5721 | } |
| 5722 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5723 | /** |
| 5724 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5725 | * @param subId The subscription to use to check the configuration. |
| 5726 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5727 | @Override |
| 5728 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5729 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5730 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5731 | final long identity = Binder.clearCallingIdentity(); |
| 5732 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5733 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5734 | // 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] | 5735 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5736 | } catch (ImsException e) { |
| 5737 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5738 | } finally { |
| 5739 | Binder.restoreCallingIdentity(identity); |
| 5740 | } |
| 5741 | } |
| 5742 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5743 | @Override |
| 5744 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5745 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5746 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5747 | final long identity = Binder.clearCallingIdentity(); |
| 5748 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5749 | if (!isImsAvailableOnDevice()) { |
| 5750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5751 | "IMS not available on device."); |
| 5752 | } |
| 5753 | int slotId = getSlotIndexOrException(subId); |
| 5754 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5755 | |
| 5756 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5757 | if (controller != null) { |
| 5758 | ImsManager imsManager = controller.getImsManager(subId); |
| 5759 | if (imsManager != null) { |
| 5760 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5761 | } else { |
| 5762 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5763 | } |
| 5764 | } else { |
| 5765 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5766 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5767 | } catch (ImsException e) { |
| 5768 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5769 | } finally { |
| 5770 | Binder.restoreCallingIdentity(identity); |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | @Override |
| 5775 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5776 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5777 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5778 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5779 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5780 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5781 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5782 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5783 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5784 | if (controller != null) { |
| 5785 | ImsManager imsManager = controller.getImsManager(subId); |
| 5786 | if (imsManager != null) { |
| 5787 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5788 | } else { |
| 5789 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5790 | + " is inactive, ignoring unregister."); |
| 5791 | // If the ImsManager is not valid, just return, since the callback will already |
| 5792 | // have been removed internally. |
| 5793 | } |
| 5794 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5795 | } finally { |
| 5796 | Binder.restoreCallingIdentity(identity); |
| 5797 | } |
| 5798 | } |
| 5799 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5800 | @Override |
| 5801 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5802 | IFeatureProvisioningCallback callback) { |
| 5803 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5804 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5805 | |
| 5806 | final long identity = Binder.clearCallingIdentity(); |
| 5807 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5808 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5809 | } |
| 5810 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5811 | try { |
| 5812 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5813 | if (controller == null) { |
| 5814 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5815 | "Device does not support IMS"); |
| 5816 | } |
| 5817 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5818 | } finally { |
| 5819 | Binder.restoreCallingIdentity(identity); |
| 5820 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5821 | } |
| 5822 | |
| 5823 | @Override |
| 5824 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5825 | IFeatureProvisioningCallback callback) { |
| 5826 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5827 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5828 | |
| 5829 | final long identity = Binder.clearCallingIdentity(); |
| 5830 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5831 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5832 | } |
| 5833 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5834 | try { |
| 5835 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5836 | if (controller == null) { |
| 5837 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5838 | return; |
| 5839 | } |
| 5840 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5841 | } finally { |
| 5842 | Binder.restoreCallingIdentity(identity); |
| 5843 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5844 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5845 | |
| 5846 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5847 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5848 | message); |
| 5849 | } |
| 5850 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5851 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5852 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5853 | boolean isProvisioned) { |
| 5854 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5855 | |
| 5856 | final long identity = Binder.clearCallingIdentity(); |
| 5857 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5858 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5859 | if (controller == null) { |
| 5860 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5861 | return; |
| 5862 | } |
| 5863 | controller.setRcsProvisioningStatusForCapability( |
| 5864 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5865 | } finally { |
| 5866 | Binder.restoreCallingIdentity(identity); |
| 5867 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | |
| 5871 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5872 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5873 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5874 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5875 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5876 | final long identity = Binder.clearCallingIdentity(); |
| 5877 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5878 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5879 | if (controller == null) { |
| 5880 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5881 | |
| 5882 | // device does not support IMS, this method will return true always. |
| 5883 | return true; |
| 5884 | } |
| 5885 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5886 | } finally { |
| 5887 | Binder.restoreCallingIdentity(identity); |
| 5888 | } |
| 5889 | } |
| 5890 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5891 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5892 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5893 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5894 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5895 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5896 | final long identity = Binder.clearCallingIdentity(); |
| 5897 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5898 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5899 | if (controller == null) { |
| 5900 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5901 | return; |
| 5902 | } |
| 5903 | controller.setImsProvisioningStatusForCapability( |
| 5904 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5905 | } finally { |
| 5906 | Binder.restoreCallingIdentity(identity); |
| 5907 | } |
| 5908 | } |
| 5909 | |
| 5910 | @Override |
| 5911 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5912 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5913 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5914 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5915 | final long identity = Binder.clearCallingIdentity(); |
| 5916 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5917 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5918 | if (controller == null) { |
| 5919 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5920 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5921 | // device does not support IMS, this method will return true always. |
| 5922 | return true; |
| 5923 | } |
| 5924 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5925 | } finally { |
| 5926 | Binder.restoreCallingIdentity(identity); |
| 5927 | } |
| 5928 | } |
| 5929 | |
| 5930 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5931 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5932 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5933 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5934 | |
| 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5937 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5938 | if (controller == null) { |
| 5939 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5940 | |
| 5941 | // device does not support IMS, this method will return false |
| 5942 | return false; |
| 5943 | } |
| 5944 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5945 | } finally { |
| 5946 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5947 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5948 | } |
| 5949 | |
| 5950 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5951 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5952 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5953 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5954 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5955 | final long identity = Binder.clearCallingIdentity(); |
| 5956 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5957 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5958 | if (controller == null) { |
| 5959 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5960 | |
| 5961 | // device does not support IMS, this method will return false |
| 5962 | return false; |
| 5963 | } |
| 5964 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5965 | } finally { |
| 5966 | Binder.restoreCallingIdentity(identity); |
| 5967 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5968 | } |
| 5969 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5970 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5971 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5972 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5973 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5974 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5975 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5976 | mApp, subId, "getImsProvisioningInt"); |
| 5977 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5978 | final long identity = Binder.clearCallingIdentity(); |
| 5979 | try { |
| 5980 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5981 | int slotId = getSlotIndex(subId); |
| 5982 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5983 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5984 | + subId + "' for key:" + key); |
| 5985 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5986 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5987 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5988 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5989 | if (controller == null) { |
| 5990 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5991 | |
| 5992 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5993 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5994 | } |
| 5995 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5996 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5997 | return retVal; |
| 5998 | } |
| 5999 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 6000 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 6001 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6002 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 6003 | + subId + "' for key:" + key); |
| 6004 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 6005 | } finally { |
| 6006 | Binder.restoreCallingIdentity(identity); |
| 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | @Override |
| 6011 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6012 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 6013 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 6014 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 6015 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6016 | mApp, subId, "getImsProvisioningString"); |
| 6017 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 6018 | final long identity = Binder.clearCallingIdentity(); |
| 6019 | try { |
| 6020 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6021 | int slotId = getSlotIndex(subId); |
| 6022 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6023 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 6024 | + subId + "' for key:" + key); |
| 6025 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 6026 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 6027 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 6028 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6029 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 6030 | + subId + "' for key:" + key); |
| 6031 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 6032 | } finally { |
| 6033 | Binder.restoreCallingIdentity(identity); |
| 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | @Override |
| 6038 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6039 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 6040 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 6041 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 6042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 6043 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 6044 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 6045 | final long identity = Binder.clearCallingIdentity(); |
| 6046 | try { |
| 6047 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6048 | int slotId = getSlotIndex(subId); |
| 6049 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6050 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 6051 | + subId + "' for key:" + key); |
| 6052 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 6053 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 6054 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 6055 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 6056 | if (controller == null) { |
| 6057 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 6058 | |
| 6059 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 6060 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 6061 | } |
| 6062 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 6063 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 6064 | return retVal; |
| 6065 | } |
| 6066 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 6067 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 6068 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6069 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 6070 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6071 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 6072 | } finally { |
| 6073 | Binder.restoreCallingIdentity(identity); |
| 6074 | } |
| 6075 | } |
| 6076 | |
| 6077 | @Override |
| 6078 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6079 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 6080 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 6081 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 6082 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 6083 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 6084 | final long identity = Binder.clearCallingIdentity(); |
| 6085 | try { |
| 6086 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6087 | int slotId = getSlotIndex(subId); |
| 6088 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6089 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 6090 | + subId + "' for key:" + key); |
| 6091 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 6092 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 6093 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 6094 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6095 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 6096 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6097 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 6098 | } finally { |
| 6099 | Binder.restoreCallingIdentity(identity); |
| 6100 | } |
| 6101 | } |
| 6102 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6103 | /** |
| 6104 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 6105 | * for the given slot ID or no ImsResolver instance has been created. |
| 6106 | * @param slotId The slot ID that the IMS service is created for. |
| 6107 | * @throws ImsException If there is no ImsService configured for this slot. |
| 6108 | */ |
| 6109 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 6110 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 6111 | ImsFeature.FEATURE_MMTEL)) { |
| 6112 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 6113 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 6114 | } |
| 6115 | } |
| 6116 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 6117 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6118 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 6119 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 6120 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 6121 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6122 | } |
| 6123 | return slotId; |
| 6124 | } |
| 6125 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 6126 | private int getSlotIndex(int subId) { |
| 6127 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 6128 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 6129 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 6130 | } |
| 6131 | return slotId; |
| 6132 | } |
| 6133 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6134 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 6135 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6136 | */ |
| 6137 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6138 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 6139 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 6140 | try { |
| 6141 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 6142 | } catch (SecurityException se) { |
| 6143 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 6144 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 6145 | + Binder.getCallingUid()); |
| 6146 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 6147 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 6148 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6149 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 6150 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 6151 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6152 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6153 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6154 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 6155 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 6156 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | final long identity = Binder.clearCallingIdentity(); |
| 6158 | try { |
| 6159 | final Phone phone = getPhone(subId); |
| 6160 | if (phone != null) { |
| 6161 | return phone.getServiceState().getDataNetworkType(); |
| 6162 | } else { |
| 6163 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 6164 | } |
| 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6167 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6168 | } |
| 6169 | |
| 6170 | /** |
| 6171 | * Returns the data network type |
| 6172 | */ |
| 6173 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6174 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6175 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 6176 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | /** |
| 6180 | * Returns the data network type for a subId |
| 6181 | */ |
| 6182 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6183 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 6184 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6185 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 6186 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 6187 | mApp, functionName)) { |
| 6188 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6189 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 6190 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 6191 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6192 | } |
| 6193 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6194 | final long identity = Binder.clearCallingIdentity(); |
| 6195 | try { |
| 6196 | final Phone phone = getPhone(subId); |
| 6197 | if (phone != null) { |
| 6198 | return phone.getServiceState().getDataNetworkType(); |
| 6199 | } else { |
| 6200 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 6201 | } |
| 6202 | } finally { |
| 6203 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6204 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6208 | * Returns the Voice network type for a subId |
| 6209 | */ |
| 6210 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6211 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 6212 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6213 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 6214 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 6215 | mApp, functionName)) { |
| 6216 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6217 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 6218 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 6219 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 6220 | } |
| 6221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6222 | final long identity = Binder.clearCallingIdentity(); |
| 6223 | try { |
| 6224 | final Phone phone = getPhone(subId); |
| 6225 | if (phone != null) { |
| 6226 | return phone.getServiceState().getVoiceNetworkType(); |
| 6227 | } else { |
| 6228 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 6229 | } |
| 6230 | } finally { |
| 6231 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6232 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | /** |
| 6236 | * @return true if a ICC card is present |
| 6237 | */ |
| 6238 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6239 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6240 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6241 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6245 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6246 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6247 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6248 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6249 | final long identity = Binder.clearCallingIdentity(); |
| 6250 | try { |
| 6251 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6252 | if (phone != null) { |
| 6253 | return phone.getIccCard().hasIccCard(); |
| 6254 | } else { |
| 6255 | return false; |
| 6256 | } |
| 6257 | } finally { |
| 6258 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 6259 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6260 | } |
| 6261 | |
| 6262 | /** |
| 6263 | * Return if the current radio is LTE on CDMA. This |
| 6264 | * is a tri-state return value as for a period of time |
| 6265 | * the mode may be unknown. |
| 6266 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6267 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6268 | * @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] | 6269 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6270 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6271 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6272 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 6273 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 6274 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6275 | } |
| 6276 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6277 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6278 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 6279 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 6280 | try { |
| 6281 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 6282 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6283 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 6284 | } |
| 6285 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | final long identity = Binder.clearCallingIdentity(); |
| 6287 | try { |
| 6288 | final Phone phone = getPhone(subId); |
| 6289 | if (phone == null) { |
| 6290 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 6291 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 6292 | return TelephonyProperties.lte_on_cdma_device() |
| 6293 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6294 | } |
| 6295 | } finally { |
| 6296 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6297 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6298 | } |
| 6299 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6300 | /** |
| 6301 | * {@hide} |
| 6302 | * Returns Default subId, 0 in the case of single standby. |
| 6303 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6304 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6305 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6306 | } |
| 6307 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 6308 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6309 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 6310 | } |
| 6311 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6312 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6313 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6314 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 6315 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6316 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6317 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 6318 | return getSubscriptionManagerService().isActiveSubId(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6319 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 6320 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6321 | return mSubscriptionController.isActiveSubId(subId); |
| 6322 | } |
| 6323 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 6324 | /** |
| 6325 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 6326 | */ |
| 6327 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6328 | final long identity = Binder.clearCallingIdentity(); |
| 6329 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6330 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6331 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 6332 | getWhenToMakeWifiCallsDefaultPreference()); |
| 6333 | } finally { |
| 6334 | Binder.restoreCallingIdentity(identity); |
| 6335 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | /** |
| 6339 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 6340 | */ |
| 6341 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6342 | final long identity = Binder.clearCallingIdentity(); |
| 6343 | try { |
| 6344 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6345 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6346 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 6347 | } finally { |
| 6348 | Binder.restoreCallingIdentity(identity); |
| 6349 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 6350 | } |
| 6351 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 6352 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 6353 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 6354 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 6355 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 6356 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6357 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 6358 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 6359 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6360 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6361 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6362 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6363 | } |
| 6364 | return PhoneFactory.getPhone(phoneId); |
| 6365 | } |
| 6366 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6367 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6368 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6369 | @NonNull IccLogicalChannelRequest request) { |
| 6370 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6371 | /*message=*/ "iccOpenLogicalChannel"); |
| 6372 | |
| 6373 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 6374 | // Verify that the callingPackage in the request belongs to the calling UID |
| 6375 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 6376 | |
| 6377 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6378 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6379 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6380 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 6381 | @NonNull IccLogicalChannelRequest request, String message) { |
| 6382 | Phone phone; |
| 6383 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 6384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6385 | mApp, request.subId, message); |
| 6386 | phone = getPhoneFromSubId(request.subId); |
| 6387 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6388 | enforceModifyPermission(); |
| 6389 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 6390 | } else { |
| 6391 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6392 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6393 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6394 | } |
| 6395 | |
| 6396 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6397 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6398 | final long identity = Binder.clearCallingIdentity(); |
| 6399 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6400 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6401 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6402 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6403 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6404 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6405 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6406 | loge("The calling package is not allowed to access ISD-R."); |
| 6407 | throw new SecurityException( |
| 6408 | "The calling package is not allowed to access ISD-R."); |
| 6409 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6410 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6411 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6413 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6414 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | return response; |
| 6416 | } finally { |
| 6417 | Binder.restoreCallingIdentity(identity); |
| 6418 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6422 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 6423 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6424 | /*message=*/"iccCloseLogicalChannel"); |
| 6425 | |
| 6426 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6427 | |
| 6428 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6429 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6430 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6431 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6432 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6433 | // before this feature is enabled, this API should only return false if |
| 6434 | // the operation fails instead of throwing runtime exception for |
| 6435 | // backward-compatibility. |
| 6436 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6437 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6438 | final long identity = Binder.clearCallingIdentity(); |
| 6439 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6440 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6441 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6442 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6443 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6444 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6445 | Boolean success = false; |
| 6446 | if (result instanceof RuntimeException) { |
| 6447 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6448 | if (shouldThrowExceptionOnFailure) { |
| 6449 | throw (RuntimeException) result; |
| 6450 | } else { |
| 6451 | return false; |
| 6452 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6453 | } else if (result instanceof Boolean) { |
| 6454 | success = (Boolean) result; |
| 6455 | } else { |
| 6456 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6457 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6458 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6459 | return success; |
| 6460 | } finally { |
| 6461 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6462 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6463 | } |
| 6464 | |
| 6465 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6466 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6467 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6468 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6469 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6470 | if (DBG) { |
| 6471 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6472 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6473 | + p3 + " data=" + data); |
| 6474 | } |
| 6475 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6476 | command, p1, p2, p3, data); |
| 6477 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6478 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6479 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6480 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6481 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6482 | enforceModifyPermission(); |
| 6483 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6484 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6485 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6486 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6487 | } |
| 6488 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6489 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6490 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6491 | } |
| 6492 | |
| 6493 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6494 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6495 | final long identity = Binder.clearCallingIdentity(); |
| 6496 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6497 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6498 | return ""; |
| 6499 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6500 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6501 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6502 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6503 | null /* workSource */); |
| 6504 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6505 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6506 | // Append the returned status code to the end of the response payload. |
| 6507 | String s = Integer.toHexString( |
| 6508 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6509 | if (response.payload != null) { |
| 6510 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6511 | } |
| 6512 | return s; |
| 6513 | } finally { |
| 6514 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6515 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6516 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6517 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6518 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6519 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6520 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6521 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6522 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6523 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6524 | if (DBG) { |
| 6525 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6526 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6527 | } |
| 6528 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6529 | cla, command, p1, p2, p3, data); |
| 6530 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6531 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6532 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6533 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6534 | 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] | 6535 | enforceModifyPermission(); |
| 6536 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 6537 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6538 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6539 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6540 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6541 | } |
| 6542 | |
| 6543 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6544 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6545 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6549 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6550 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6551 | final long identity = Binder.clearCallingIdentity(); |
| 6552 | try { |
| 6553 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6554 | && TextUtils.equals(ISDR_AID, data)) { |
| 6555 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6556 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6557 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6558 | if (bestComponent == null |
| 6559 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6560 | loge("The calling package is not allowed to select ISD-R."); |
| 6561 | throw new SecurityException( |
| 6562 | "The calling package is not allowed to select ISD-R."); |
| 6563 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6564 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6565 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6566 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6567 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6568 | null /* workSource */); |
| 6569 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6570 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6571 | // Append the returned status code to the end of the response payload. |
| 6572 | String s = Integer.toHexString( |
| 6573 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6574 | if (response.payload != null) { |
| 6575 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6576 | } |
| 6577 | return s; |
| 6578 | } finally { |
| 6579 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6580 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6581 | } |
| 6582 | |
| 6583 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6584 | 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] | 6585 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6587 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | final long identity = Binder.clearCallingIdentity(); |
| 6590 | try { |
| 6591 | if (DBG) { |
| 6592 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6593 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6594 | } |
| 6595 | |
| 6596 | IccIoResult response = |
| 6597 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6598 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6599 | subId); |
| 6600 | |
| 6601 | if (DBG) { |
| 6602 | log("Exchange SIM_IO [R]" + response); |
| 6603 | } |
| 6604 | |
| 6605 | byte[] result = null; |
| 6606 | int length = 2; |
| 6607 | if (response.payload != null) { |
| 6608 | length = 2 + response.payload.length; |
| 6609 | result = new byte[length]; |
| 6610 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6611 | } else { |
| 6612 | result = new byte[length]; |
| 6613 | } |
| 6614 | |
| 6615 | result[length - 1] = (byte) response.sw2; |
| 6616 | result[length - 2] = (byte) response.sw1; |
| 6617 | return result; |
| 6618 | } finally { |
| 6619 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6620 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6623 | /** |
| 6624 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6625 | * on a particular subscription |
| 6626 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6627 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6628 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6629 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6630 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6631 | return null; |
| 6632 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6633 | |
| 6634 | final long identity = Binder.clearCallingIdentity(); |
| 6635 | try { |
| 6636 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6637 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6638 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6639 | return null; |
| 6640 | } |
| 6641 | Object response = sendRequest( |
| 6642 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6643 | if (response instanceof String[]) { |
| 6644 | return (String[]) response; |
| 6645 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6646 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6647 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6648 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6649 | } finally { |
| 6650 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6651 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6652 | } |
| 6653 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6654 | /** |
| 6655 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6656 | * subscription. |
| 6657 | * |
| 6658 | * @param subId the id of the subscription. |
| 6659 | * @param appType the uicc app type, must be USIM or SIM. |
| 6660 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6661 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6662 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6663 | * @return number of fplmns that is successfully written to the SIM. |
| 6664 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6665 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6666 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6667 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6668 | mApp, subId, "setForbiddenPlmns"); |
| 6669 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6670 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6671 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6672 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6673 | } |
| 6674 | if (fplmns == null) { |
| 6675 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6676 | } |
| 6677 | for (String fplmn : fplmns) { |
| 6678 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6679 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6680 | } |
| 6681 | } |
| 6682 | final long identity = Binder.clearCallingIdentity(); |
| 6683 | try { |
| 6684 | Object response = sendRequest( |
| 6685 | CMD_SET_FORBIDDEN_PLMNS, |
| 6686 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6687 | subId); |
| 6688 | return (int) response; |
| 6689 | } finally { |
| 6690 | Binder.restoreCallingIdentity(identity); |
| 6691 | } |
| 6692 | } |
| 6693 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6694 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6695 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6696 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6697 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6698 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6699 | final long identity = Binder.clearCallingIdentity(); |
| 6700 | try { |
| 6701 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6702 | if (response.payload == null) { |
| 6703 | return ""; |
| 6704 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6705 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | // Append the returned status code to the end of the response payload. |
| 6707 | String s = Integer.toHexString( |
| 6708 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6709 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6710 | return s; |
| 6711 | } finally { |
| 6712 | Binder.restoreCallingIdentity(identity); |
| 6713 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6714 | } |
| 6715 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6716 | /** |
| 6717 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6718 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6719 | * |
| 6720 | * @param itemID the ID of the item to read |
| 6721 | * @return the NV item as a String, or null on error. |
| 6722 | */ |
| 6723 | @Override |
| 6724 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6725 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6726 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6727 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | |
| 6729 | final long identity = Binder.clearCallingIdentity(); |
| 6730 | try { |
| 6731 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6732 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6733 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6734 | return value; |
| 6735 | } finally { |
| 6736 | Binder.restoreCallingIdentity(identity); |
| 6737 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | /** |
| 6741 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6742 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6743 | * |
| 6744 | * @param itemID the ID of the item to read |
| 6745 | * @param itemValue the value to write, as a String |
| 6746 | * @return true on success; false on any failure |
| 6747 | */ |
| 6748 | @Override |
| 6749 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6750 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6751 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6752 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6753 | |
| 6754 | final long identity = Binder.clearCallingIdentity(); |
| 6755 | try { |
| 6756 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6757 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6758 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6760 | return success; |
| 6761 | } finally { |
| 6762 | Binder.restoreCallingIdentity(identity); |
| 6763 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6764 | } |
| 6765 | |
| 6766 | /** |
| 6767 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6768 | * Used for device configuration by some CDMA operators. |
| 6769 | * |
| 6770 | * @param preferredRoamingList byte array containing the new PRL |
| 6771 | * @return true on success; false on any failure |
| 6772 | */ |
| 6773 | @Override |
| 6774 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6775 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6776 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6777 | |
| 6778 | final long identity = Binder.clearCallingIdentity(); |
| 6779 | try { |
| 6780 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6781 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6782 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6783 | return success; |
| 6784 | } finally { |
| 6785 | Binder.restoreCallingIdentity(identity); |
| 6786 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6790 | * 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] | 6791 | * Used for device configuration by some CDMA operators. |
| 6792 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6793 | * @param slotIndex - device slot. |
| 6794 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6795 | * @return true on success; false on any failure |
| 6796 | */ |
| 6797 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6798 | public boolean resetModemConfig(int slotIndex) { |
| 6799 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6800 | if (phone != null) { |
| 6801 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6802 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6803 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6804 | final long identity = Binder.clearCallingIdentity(); |
| 6805 | try { |
| 6806 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6807 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6808 | return success; |
| 6809 | } finally { |
| 6810 | Binder.restoreCallingIdentity(identity); |
| 6811 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6812 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6813 | return false; |
| 6814 | } |
| 6815 | |
| 6816 | /** |
| 6817 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6818 | * |
| 6819 | * @param slotIndex - device slot. |
| 6820 | * |
| 6821 | * @return true on success; false on any failure |
| 6822 | */ |
| 6823 | @Override |
| 6824 | public boolean rebootModem(int slotIndex) { |
| 6825 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6826 | if (phone != null) { |
| 6827 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6828 | mApp, phone.getSubId(), "rebootModem"); |
| 6829 | |
| 6830 | final long identity = Binder.clearCallingIdentity(); |
| 6831 | try { |
| 6832 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6833 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6834 | return success; |
| 6835 | } finally { |
| 6836 | Binder.restoreCallingIdentity(identity); |
| 6837 | } |
| 6838 | } |
| 6839 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6840 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6841 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6842 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6843 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6844 | * {@link #disableIms(int)}. |
| 6845 | * @param slotIndex device slot. |
| 6846 | */ |
| 6847 | public void resetIms(int slotIndex) { |
| 6848 | enforceModifyPermission(); |
| 6849 | |
| 6850 | final long identity = Binder.clearCallingIdentity(); |
| 6851 | try { |
| 6852 | if (mImsResolver == null) { |
| 6853 | // may happen if the does not support IMS. |
| 6854 | return; |
| 6855 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6856 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6857 | } finally { |
| 6858 | Binder.restoreCallingIdentity(identity); |
| 6859 | } |
| 6860 | } |
| 6861 | |
| 6862 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6863 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6864 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6865 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6866 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6867 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | |
| 6869 | final long identity = Binder.clearCallingIdentity(); |
| 6870 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6871 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6872 | // may happen if the device does not support IMS. |
| 6873 | return; |
| 6874 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6875 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6876 | } finally { |
| 6877 | Binder.restoreCallingIdentity(identity); |
| 6878 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6879 | } |
| 6880 | |
| 6881 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6882 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6883 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6884 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6885 | public void disableIms(int slotId) { |
| 6886 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6887 | |
| 6888 | final long identity = Binder.clearCallingIdentity(); |
| 6889 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6890 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6891 | // may happen if the device does not support IMS. |
| 6892 | return; |
| 6893 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6894 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6895 | } finally { |
| 6896 | Binder.restoreCallingIdentity(identity); |
| 6897 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6901 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6902 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6903 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6904 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6905 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6906 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6907 | |
| 6908 | final long identity = Binder.clearCallingIdentity(); |
| 6909 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6910 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6911 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6912 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6913 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6914 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6915 | } finally { |
| 6916 | Binder.restoreCallingIdentity(identity); |
| 6917 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6918 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6919 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6920 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6921 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6922 | @Override |
| 6923 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6924 | enforceModifyPermission(); |
| 6925 | |
| 6926 | final long identity = Binder.clearCallingIdentity(); |
| 6927 | try { |
| 6928 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6929 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6930 | } finally { |
| 6931 | Binder.restoreCallingIdentity(identity); |
| 6932 | } |
| 6933 | } |
| 6934 | |
| 6935 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6936 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6937 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6938 | */ |
| 6939 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6940 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6941 | |
| 6942 | final long identity = Binder.clearCallingIdentity(); |
| 6943 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6944 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6945 | // may happen if the device does not support IMS. |
| 6946 | return null; |
| 6947 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6948 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6949 | } finally { |
| 6950 | Binder.restoreCallingIdentity(identity); |
| 6951 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6952 | } |
| 6953 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6954 | /** |
| 6955 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6956 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6957 | */ |
| 6958 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6959 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6960 | |
| 6961 | final long identity = Binder.clearCallingIdentity(); |
| 6962 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6963 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6964 | // may happen if the device does not support IMS. |
| 6965 | return null; |
| 6966 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6967 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6968 | } finally { |
| 6969 | Binder.restoreCallingIdentity(identity); |
| 6970 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6971 | } |
| 6972 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6973 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6974 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6975 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6976 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6977 | * @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] | 6978 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6979 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6980 | * @param packageName The name of the package that the current configuration will be replaced |
| 6981 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6982 | * @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] | 6983 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6984 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6985 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6986 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6987 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6988 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6989 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6990 | final long identity = Binder.clearCallingIdentity(); |
| 6991 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6992 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6993 | // may happen if the device does not support IMS. |
| 6994 | return false; |
| 6995 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6996 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6997 | for (int featureType : featureTypes) { |
| 6998 | featureConfig.put(featureType, packageName); |
| 6999 | } |
| 7000 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 7001 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | } finally { |
| 7003 | Binder.restoreCallingIdentity(identity); |
| 7004 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7005 | } |
| 7006 | |
| 7007 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 7008 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 7009 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 7010 | * |
| 7011 | * This should only be used for testing. |
| 7012 | * |
| 7013 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 7014 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 7015 | */ |
| 7016 | @Override |
| 7017 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 7018 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7019 | "clearCarrierImsServiceOverride"); |
| 7020 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 7021 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 7022 | |
| 7023 | final long identity = Binder.clearCallingIdentity(); |
| 7024 | try { |
| 7025 | if (mImsResolver == null) { |
| 7026 | // may happen if the device does not support IMS. |
| 7027 | return false; |
| 7028 | } |
| 7029 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 7030 | } finally { |
| 7031 | Binder.restoreCallingIdentity(identity); |
| 7032 | } |
| 7033 | } |
| 7034 | |
| 7035 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 7036 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7037 | * |
| 7038 | * @param slotId The slot that the ImsService is associated with. |
| 7039 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 7040 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 7041 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7042 | * @return the package name of the ImsService configuration. |
| 7043 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 7044 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 7045 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 7046 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 7047 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 7048 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 7049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | final long identity = Binder.clearCallingIdentity(); |
| 7051 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 7052 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 7053 | // may happen if the device does not support IMS. |
| 7054 | return ""; |
| 7055 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 7056 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 7057 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 7058 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | } finally { |
| 7060 | Binder.restoreCallingIdentity(identity); |
| 7061 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7062 | } |
| 7063 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7064 | /** |
| 7065 | * Get the MmTelFeature state associated with the requested subscription id. |
| 7066 | * @param subId The subscription that the MmTelFeature is associated with. |
| 7067 | * @param callback A callback with an integer containing the |
| 7068 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 7069 | */ |
| 7070 | @Override |
| 7071 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 7072 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 7073 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 7074 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 7075 | "IMS not available on device."); |
| 7076 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7077 | final long token = Binder.clearCallingIdentity(); |
| 7078 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 7079 | int slotId = getSlotIndex(subId); |
| 7080 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7081 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 7082 | + subId + "'"); |
| 7083 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 7084 | } |
| 7085 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 7086 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 7087 | try { |
| 7088 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 7089 | } catch (RemoteException e) { |
| 7090 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 7091 | + "Ignore"); |
| 7092 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7093 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 7094 | } catch (ImsException e) { |
| 7095 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7096 | } finally { |
| 7097 | Binder.restoreCallingIdentity(token); |
| 7098 | } |
| 7099 | } |
| 7100 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 7101 | /** |
| 7102 | * Sets the ims registration state on all valid {@link Phone}s. |
| 7103 | */ |
| 7104 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 7105 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | |
| 7107 | final long identity = Binder.clearCallingIdentity(); |
| 7108 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 7109 | // NOTE: Before S, this method only set the default phone. |
| 7110 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 7111 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 7112 | phone.setImsRegistrationState(registered); |
| 7113 | } |
| 7114 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7115 | } finally { |
| 7116 | Binder.restoreCallingIdentity(identity); |
| 7117 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 7118 | } |
| 7119 | |
| 7120 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 7121 | * Set the network selection mode to automatic. |
| 7122 | * |
| 7123 | */ |
| 7124 | @Override |
| 7125 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7127 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7128 | |
| 7129 | final long identity = Binder.clearCallingIdentity(); |
| 7130 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 7131 | if (!isActiveSubscription(subId)) { |
| 7132 | return; |
| 7133 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7134 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 7135 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 7136 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7137 | } finally { |
| 7138 | Binder.restoreCallingIdentity(identity); |
| 7139 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 7140 | } |
| 7141 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 7142 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 7143 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 7144 | * |
| 7145 | * @param subId the id of the subscription. |
| 7146 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 7147 | * the operator to attach to. |
| 7148 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 7149 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 7150 | * normal network selection next time. |
| 7151 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 7152 | */ |
| 7153 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 7154 | public boolean setNetworkSelectionModeManual( |
| 7155 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7156 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7157 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 7158 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7159 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 7160 | if (!isActiveSubscription(subId)) { |
| 7161 | return false; |
| 7162 | } |
| 7163 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7164 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 7165 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7166 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 7167 | if (DBG) { |
| 7168 | log("setNetworkSelectionModeManual: subId: " + subId |
| 7169 | + " operator: " + operatorInfo); |
| 7170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 7172 | } finally { |
| 7173 | Binder.restoreCallingIdentity(identity); |
| 7174 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 7175 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7176 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 7177 | * Get the manual network selection |
| 7178 | * |
| 7179 | * @param subId the id of the subscription. |
| 7180 | * |
| 7181 | * @return the previously saved user selected PLMN |
| 7182 | */ |
| 7183 | @Override |
| 7184 | public String getManualNetworkSelectionPlmn(int subId) { |
| 7185 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7186 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 7187 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 7188 | |
| 7189 | final long identity = Binder.clearCallingIdentity(); |
| 7190 | try { |
| 7191 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 7192 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 7193 | } |
| 7194 | |
| 7195 | final Phone phone = getPhone(subId); |
| 7196 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 7197 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 7198 | } |
| 7199 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 7200 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7201 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 7202 | } finally { |
| 7203 | Binder.restoreCallingIdentity(identity); |
| 7204 | } |
| 7205 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 7206 | |
| 7207 | /** |
| 7208 | * Scans for available networks. |
| 7209 | */ |
| 7210 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7211 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 7212 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7213 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7214 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7215 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 7216 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7217 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7218 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7219 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7220 | .setCallingPid(Binder.getCallingPid()) |
| 7221 | .setCallingUid(Binder.getCallingUid()) |
| 7222 | .setMethod("getCellNetworkScanResults") |
| 7223 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7224 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7225 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7226 | .build()); |
| 7227 | switch (locationResult) { |
| 7228 | case DENIED_HARD: |
| 7229 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 7230 | case DENIED_SOFT: |
| 7231 | return null; |
| 7232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7233 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7234 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | try { |
| 7236 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7237 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7238 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7239 | } finally { |
| 7240 | Binder.restoreCallingIdentity(identity); |
| 7241 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 7242 | } |
| 7243 | |
| 7244 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7245 | * Get the call forwarding info, given the call forwarding reason. |
| 7246 | */ |
| 7247 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7248 | public void getCallForwarding(int subId, int callForwardingReason, |
| 7249 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7250 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 7251 | long identity = Binder.clearCallingIdentity(); |
| 7252 | try { |
| 7253 | if (DBG) { |
| 7254 | log("getCallForwarding: subId " + subId |
| 7255 | + " callForwardingReason" + callForwardingReason); |
| 7256 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7257 | |
| 7258 | Phone phone = getPhone(subId); |
| 7259 | if (phone == null) { |
| 7260 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 7261 | callback.onError( |
| 7262 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7263 | } catch (RemoteException e) { |
| 7264 | // ignore |
| 7265 | } |
| 7266 | return; |
| 7267 | } |
| 7268 | |
| 7269 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 7270 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 7271 | @Override |
| 7272 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 7273 | try { |
| 7274 | callback.onCallForwardingInfoAvailable(info); |
| 7275 | } catch (RemoteException e) { |
| 7276 | // ignore |
| 7277 | } |
| 7278 | } |
| 7279 | |
| 7280 | @Override |
| 7281 | public void onError(int error) { |
| 7282 | try { |
| 7283 | callback.onError(error); |
| 7284 | } catch (RemoteException e) { |
| 7285 | // ignore |
| 7286 | } |
| 7287 | } |
| 7288 | }); |
| 7289 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7290 | } finally { |
| 7291 | Binder.restoreCallingIdentity(identity); |
| 7292 | } |
| 7293 | } |
| 7294 | |
| 7295 | /** |
| 7296 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 7297 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 7298 | */ |
| 7299 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7300 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 7301 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7302 | enforceModifyPermission(); |
| 7303 | long identity = Binder.clearCallingIdentity(); |
| 7304 | try { |
| 7305 | if (DBG) { |
| 7306 | log("setCallForwarding: subId " + subId |
| 7307 | + " callForwardingInfo" + callForwardingInfo); |
| 7308 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7309 | |
| 7310 | Phone phone = getPhone(subId); |
| 7311 | if (phone == null) { |
| 7312 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 7313 | callback.accept( |
| 7314 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7315 | } catch (RemoteException e) { |
| 7316 | // ignore |
| 7317 | } |
| 7318 | return; |
| 7319 | } |
| 7320 | |
| 7321 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7322 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7323 | |
| 7324 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
| 7327 | } |
| 7328 | } |
| 7329 | |
| 7330 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7331 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7332 | */ |
| 7333 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7334 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7335 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7336 | long identity = Binder.clearCallingIdentity(); |
| 7337 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7338 | Phone phone = getPhone(subId); |
| 7339 | if (phone == null) { |
| 7340 | try { |
| 7341 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7342 | } catch (RemoteException e) { |
| 7343 | // ignore |
| 7344 | } |
| 7345 | return; |
| 7346 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7347 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7348 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7349 | boolean requireUssd = c.getBoolean( |
| 7350 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7351 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7352 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7353 | if (requireUssd) { |
| 7354 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7355 | getSubscriptionCarrierId(subId)); |
| 7356 | String newUssdCommand = ""; |
| 7357 | try { |
| 7358 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7359 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7360 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7361 | } catch (NullPointerException e) { |
| 7362 | loge("Failed to generate USSD number" + e); |
| 7363 | } |
| 7364 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7365 | mMainThreadHandler, callback, carrierXmlParser, |
| 7366 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7367 | final String ussdCommand = newUssdCommand; |
| 7368 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7369 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7370 | }); |
| 7371 | } else { |
| 7372 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7373 | callback::accept); |
| 7374 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7375 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7376 | } finally { |
| 7377 | Binder.restoreCallingIdentity(identity); |
| 7378 | } |
| 7379 | } |
| 7380 | |
| 7381 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7382 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7383 | */ |
| 7384 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7385 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7386 | enforceModifyPermission(); |
| 7387 | long identity = Binder.clearCallingIdentity(); |
| 7388 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7389 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7390 | |
| 7391 | Phone phone = getPhone(subId); |
| 7392 | if (phone == null) { |
| 7393 | try { |
| 7394 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7395 | } catch (RemoteException e) { |
| 7396 | // ignore |
| 7397 | } |
| 7398 | return; |
| 7399 | } |
| 7400 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7401 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7402 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7403 | boolean requireUssd = c.getBoolean( |
| 7404 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7405 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7406 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7407 | if (requireUssd) { |
| 7408 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7409 | getSubscriptionCarrierId(subId)); |
| 7410 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7411 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7412 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7413 | String newUssdCommand = ""; |
| 7414 | try { |
| 7415 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7416 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7417 | .makeCommand(ssAction, null); |
| 7418 | } catch (NullPointerException e) { |
| 7419 | loge("Failed to generate USSD number" + e); |
| 7420 | } |
| 7421 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7422 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7423 | final String ussdCommand = newUssdCommand; |
| 7424 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7425 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7426 | }); |
| 7427 | } else { |
| 7428 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7429 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7430 | |
| 7431 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7432 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7433 | } finally { |
| 7434 | Binder.restoreCallingIdentity(identity); |
| 7435 | } |
| 7436 | } |
| 7437 | |
| 7438 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7439 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7440 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7441 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7442 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7443 | * location related information which will be sent if the caller already possess |
| 7444 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7445 | * @param request contains the radio access networks with bands/channels to scan |
| 7446 | * @param messenger callback messenger for scan results or errors |
| 7447 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7448 | * @return the id of the requested scan which can be used to stop the scan. |
| 7449 | */ |
| 7450 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7451 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7452 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7453 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7455 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7456 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7457 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7458 | if (!renounceFineLocationAccess) { |
| 7459 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7460 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7461 | .setCallingPackage(callingPackage) |
| 7462 | .setCallingFeatureId(callingFeatureId) |
| 7463 | .setCallingPid(Binder.getCallingPid()) |
| 7464 | .setCallingUid(Binder.getCallingUid()) |
| 7465 | .setMethod("requestNetworkScan") |
| 7466 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7467 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7468 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7469 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7470 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7471 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7472 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7473 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7474 | if (e != null) { |
| 7475 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7476 | throw e; |
| 7477 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7478 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7479 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7480 | } |
| 7481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7482 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7483 | int callingUid = Binder.getCallingUid(); |
| 7484 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7485 | final long identity = Binder.clearCallingIdentity(); |
| 7486 | try { |
| 7487 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7488 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7489 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7490 | } finally { |
| 7491 | Binder.restoreCallingIdentity(identity); |
| 7492 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7493 | } |
| 7494 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7495 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7496 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7497 | boolean hasCarrierPriv; |
| 7498 | final long identity = Binder.clearCallingIdentity(); |
| 7499 | try { |
| 7500 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7501 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7502 | } finally { |
| 7503 | Binder.restoreCallingIdentity(identity); |
| 7504 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7505 | boolean hasNetworkScanPermission = |
| 7506 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7507 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7508 | |
| 7509 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7510 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7511 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7512 | } |
| 7513 | |
| 7514 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7515 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7516 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7517 | return new SecurityException("Specific channels must not be" |
| 7518 | + " scanned without location access."); |
| 7519 | } |
| 7520 | } |
| 7521 | } |
| 7522 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7523 | return null; |
| 7524 | } |
| 7525 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7526 | /** |
| 7527 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7528 | * |
| 7529 | * @param subId id of the subscription |
| 7530 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7531 | */ |
| 7532 | @Override |
| 7533 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7535 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7536 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7537 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | final long identity = Binder.clearCallingIdentity(); |
| 7539 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7540 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
| 7543 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7544 | } |
| 7545 | |
| 7546 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7547 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7548 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7549 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7550 | */ |
| 7551 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7552 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7553 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7554 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7555 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7556 | |
| 7557 | final long identity = Binder.clearCallingIdentity(); |
| 7558 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7559 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7560 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7561 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7562 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7563 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | } finally { |
| 7565 | Binder.restoreCallingIdentity(identity); |
| 7566 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7570 | * Get the allowed network types for certain reason. |
| 7571 | * |
| 7572 | * @param subId the id of the subscription. |
| 7573 | * @param reason the reason the allowed network type change is taking place |
| 7574 | * @return the allowed network types. |
| 7575 | */ |
| 7576 | @Override |
| 7577 | public long getAllowedNetworkTypesForReason(int subId, |
| 7578 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7579 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7580 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7581 | final long identity = Binder.clearCallingIdentity(); |
| 7582 | try { |
| 7583 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 7584 | } finally { |
| 7585 | Binder.restoreCallingIdentity(identity); |
| 7586 | } |
| 7587 | } |
| 7588 | |
| 7589 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7590 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7591 | * @param subId subscription id of the sim card |
| 7592 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7593 | * This can be passed following states |
| 7594 | * <ol> |
| 7595 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7596 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7597 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7598 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7599 | * </ol> |
| 7600 | * @return operation result. |
| 7601 | */ |
| 7602 | @Override |
| 7603 | public int setNrDualConnectivityState(int subId, |
| 7604 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7605 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7606 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7607 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7608 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7609 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7610 | } |
| 7611 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7612 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7613 | final long identity = Binder.clearCallingIdentity(); |
| 7614 | try { |
| 7615 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7616 | nrDualConnectivityState, subId, |
| 7617 | workSource); |
| 7618 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7619 | return result; |
| 7620 | } finally { |
| 7621 | Binder.restoreCallingIdentity(identity); |
| 7622 | } |
| 7623 | } |
| 7624 | |
| 7625 | /** |
| 7626 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7627 | * @return true if dual connectivity is enabled else false |
| 7628 | */ |
| 7629 | @Override |
| 7630 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7631 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7632 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7633 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7634 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7635 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7636 | return false; |
| 7637 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7638 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7639 | final long identity = Binder.clearCallingIdentity(); |
| 7640 | try { |
| 7641 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7642 | null, subId, workSource); |
| 7643 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7644 | return isEnabled; |
| 7645 | } finally { |
| 7646 | Binder.restoreCallingIdentity(identity); |
| 7647 | } |
| 7648 | } |
| 7649 | |
| 7650 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7651 | * Set the allowed network types of the device and |
| 7652 | * provide the reason triggering the allowed network change. |
| 7653 | * |
| 7654 | * @param subId the id of the subscription. |
| 7655 | * @param reason the reason the allowed network type change is taking place |
| 7656 | * @param allowedNetworkTypes the allowed network types. |
| 7657 | * @return true on success; false on any failure. |
| 7658 | */ |
| 7659 | @Override |
| 7660 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7661 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7662 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7664 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7665 | // If the caller only has carrier privileges, then they should not be able to override |
| 7666 | // any network types which were set for security reasons. |
| 7667 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7668 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7669 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7670 | throw new SecurityException( |
| 7671 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7672 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7673 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7674 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7675 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7676 | return false; |
| 7677 | } |
| 7678 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7679 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7680 | return false; |
| 7681 | } |
| 7682 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7683 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7684 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7685 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7686 | Phone phone = getPhone(subId); |
| 7687 | if (phone == null) { |
| 7688 | return false; |
| 7689 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7690 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7691 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7692 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7693 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7694 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7695 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7696 | final long identity = Binder.clearCallingIdentity(); |
| 7697 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7698 | Boolean success = (Boolean) sendRequest( |
| 7699 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7700 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7701 | |
| 7702 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7703 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7704 | } finally { |
| 7705 | Binder.restoreCallingIdentity(identity); |
| 7706 | } |
| 7707 | } |
| 7708 | |
| 7709 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7710 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7711 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7712 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7713 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7714 | * @hide |
| 7715 | */ |
| 7716 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7717 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7718 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7719 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7720 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7721 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7722 | if (phone != null) { |
| 7723 | return phone.hasMatchedTetherApnSetting(); |
| 7724 | } else { |
| 7725 | return false; |
| 7726 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7727 | } finally { |
| 7728 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7729 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7730 | } |
| 7731 | |
| 7732 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7733 | * Get the user enabled state of Mobile Data. |
| 7734 | * |
| 7735 | * TODO: remove and use isUserDataEnabled. |
| 7736 | * This can't be removed now because some vendor codes |
| 7737 | * calls through ITelephony directly while they should |
| 7738 | * use TelephonyManager. |
| 7739 | * |
| 7740 | * @return true on enabled |
| 7741 | */ |
| 7742 | @Override |
| 7743 | public boolean getDataEnabled(int subId) { |
| 7744 | return isUserDataEnabled(subId); |
| 7745 | } |
| 7746 | |
| 7747 | /** |
| 7748 | * Get whether mobile data is enabled per user setting. |
| 7749 | * |
| 7750 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7751 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7752 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7753 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7754 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7755 | * |
| 7756 | * @return {@code true} if data is enabled else {@code false} |
| 7757 | */ |
| 7758 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7759 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7760 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7761 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7762 | try { |
| 7763 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7764 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7765 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7766 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7767 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7768 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7770 | mApp, subId, functionName); |
| 7771 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7772 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7773 | |
| 7774 | final long identity = Binder.clearCallingIdentity(); |
| 7775 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7776 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7777 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7778 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7779 | if (phone != null) { |
| 7780 | boolean retVal = phone.isUserDataEnabled(); |
| 7781 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7782 | return retVal; |
| 7783 | } else { |
| 7784 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7785 | return false; |
| 7786 | } |
| 7787 | } finally { |
| 7788 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7789 | } |
| 7790 | } |
| 7791 | |
| 7792 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7793 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7794 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7795 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7796 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7797 | * @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] | 7798 | */ |
| 7799 | @Override |
| 7800 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7801 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7802 | try { |
| 7803 | try { |
| 7804 | mApp.enforceCallingOrSelfPermission( |
| 7805 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7806 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7807 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7808 | try { |
| 7809 | mApp.enforceCallingOrSelfPermission( |
| 7810 | android.Manifest.permission.READ_PHONE_STATE, |
| 7811 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7812 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7813 | mApp.enforceCallingOrSelfPermission( |
| 7814 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7815 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7816 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7817 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7818 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7819 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | |
| 7821 | final long identity = Binder.clearCallingIdentity(); |
| 7822 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7823 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7824 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7825 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7826 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7827 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7828 | return retVal; |
| 7829 | } else { |
| 7830 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7831 | return false; |
| 7832 | } |
| 7833 | } finally { |
| 7834 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7835 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7836 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7837 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7838 | /** |
| 7839 | * Check if data is enabled for a specific reason |
| 7840 | * @param subId Subscription index |
| 7841 | * @param reason the reason the data enable change is taking place |
| 7842 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7843 | */ |
| 7844 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7845 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7846 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7847 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7848 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7849 | try { |
| 7850 | mApp.enforceCallingOrSelfPermission( |
| 7851 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7852 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7853 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7854 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7855 | functionName); |
| 7856 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7857 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7858 | try { |
| 7859 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7860 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7861 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7863 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7864 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7865 | } |
| 7866 | |
| 7867 | |
| 7868 | final long identity = Binder.clearCallingIdentity(); |
| 7869 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7870 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7871 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7872 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7873 | + " reason=" + reason); |
| 7874 | } |
| 7875 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7876 | if (phone != null) { |
| 7877 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7878 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7879 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7880 | return retVal; |
| 7881 | } else { |
| 7882 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7883 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7884 | + subId + " retVal=false"); |
| 7885 | } |
| 7886 | return false; |
| 7887 | } |
| 7888 | } finally { |
| 7889 | Binder.restoreCallingIdentity(identity); |
| 7890 | } |
| 7891 | } |
| 7892 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7893 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7894 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7895 | // No permission needed; this only lets the caller inspect their own status. |
| 7896 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7897 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7898 | |
| 7899 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7900 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7901 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7902 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7903 | } |
| 7904 | |
| 7905 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7906 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7907 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7908 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7909 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7910 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7911 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7912 | if (cpt == null) { |
| 7913 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7914 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7915 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7916 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7917 | } |
| 7918 | |
| 7919 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7920 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7921 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7922 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7923 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7924 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7925 | Phone phone = getPhone(subId); |
| 7926 | if (phone == null) { |
| 7927 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7928 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7929 | } |
| 7930 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7931 | if (cpt == null) { |
| 7932 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7933 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7934 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7935 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7936 | } |
| 7937 | |
| 7938 | @Override |
| 7939 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7940 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7941 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7942 | } |
| 7943 | |
| 7944 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7945 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7946 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7947 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7948 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7949 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7950 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7951 | if (phone == null) { |
| 7952 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7953 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7954 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7955 | if (cpt == null) { |
| 7956 | continue; |
| 7957 | } |
| 7958 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7959 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7960 | break; |
| 7961 | } |
| 7962 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7963 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7964 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7965 | |
| 7966 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7967 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7968 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7969 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7970 | if (phone == null) { |
| 7971 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7972 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7973 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7974 | if (cpt == null) { |
| 7975 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7976 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7977 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7978 | } |
| 7979 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7980 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7981 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7982 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7983 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7984 | if (phone == null) { |
| 7985 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7986 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7987 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7988 | if (cpt == null) { |
| 7989 | return Collections.emptyList(); |
| 7990 | } |
| 7991 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7992 | } |
| 7993 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7994 | @Override |
| 7995 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7996 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7997 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7998 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7999 | try { |
| 8000 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 8001 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 8002 | } |
| 8003 | } finally { |
| 8004 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 8005 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8006 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 8007 | } |
| 8008 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 8009 | @Override |
| 8010 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 8011 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 8012 | |
| 8013 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 8014 | if (phone == null) { |
| 8015 | return null; |
| 8016 | } |
| 8017 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8018 | if (cpt == null) { |
| 8019 | return null; |
| 8020 | } |
| 8021 | return cpt.getCarrierServicePackageName(); |
| 8022 | } |
| 8023 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 8024 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 8025 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8026 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 8027 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 8028 | return null; |
| 8029 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8030 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 8031 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 8032 | return null; |
| 8033 | } |
| 8034 | return iccId; |
| 8035 | } |
| 8036 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 8037 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 8038 | public void setCallComposerStatus(int subId, int status) { |
| 8039 | enforceModifyPermission(); |
| 8040 | |
| 8041 | final long identity = Binder.clearCallingIdentity(); |
| 8042 | try { |
| 8043 | Phone phone = getPhone(subId); |
| 8044 | if (phone != null) { |
| 8045 | Phone defaultPhone = phone.getImsPhone(); |
| 8046 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8047 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8048 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 8049 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 8050 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 8051 | } |
| 8052 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 8053 | } catch (ImsException e) { |
| 8054 | throw new ServiceSpecificException(e.getCode()); |
| 8055 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 8056 | Binder.restoreCallingIdentity(identity); |
| 8057 | } |
| 8058 | } |
| 8059 | |
| 8060 | @Override |
| 8061 | public int getCallComposerStatus(int subId) { |
| 8062 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 8063 | |
| 8064 | final long identity = Binder.clearCallingIdentity(); |
| 8065 | try { |
| 8066 | Phone phone = getPhone(subId); |
| 8067 | if (phone != null) { |
| 8068 | Phone defaultPhone = phone.getImsPhone(); |
| 8069 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8070 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8071 | return imsPhone.getCallComposerStatus(); |
| 8072 | } |
| 8073 | } |
| 8074 | } finally { |
| 8075 | Binder.restoreCallingIdentity(identity); |
| 8076 | } |
| 8077 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 8078 | } |
| 8079 | |
| 8080 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8081 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 8082 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8083 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8084 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 8085 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8086 | final long identity = Binder.clearCallingIdentity(); |
| 8087 | try { |
| 8088 | final String iccId = getIccId(subId); |
| 8089 | final Phone phone = getPhone(subId); |
| 8090 | if (phone == null) { |
| 8091 | return false; |
| 8092 | } |
| 8093 | final String subscriberId = phone.getSubscriberId(); |
| 8094 | |
| 8095 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8096 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8097 | + subscriberId + " to " + number); |
| 8098 | } |
| 8099 | |
| 8100 | if (TextUtils.isEmpty(iccId)) { |
| 8101 | return false; |
| 8102 | } |
| 8103 | |
| 8104 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 8105 | |
| 8106 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 8107 | if (alphaTag == null) { |
| 8108 | editor.remove(alphaTagPrefKey); |
| 8109 | } else { |
| 8110 | editor.putString(alphaTagPrefKey, alphaTag); |
| 8111 | } |
| 8112 | |
| 8113 | // Record both the line number and IMSI for this ICCID, since we need to |
| 8114 | // track all merged IMSIs based on line number |
| 8115 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8116 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8117 | if (number == null) { |
| 8118 | editor.remove(numberPrefKey); |
| 8119 | editor.remove(subscriberPrefKey); |
| 8120 | } else { |
| 8121 | editor.putString(numberPrefKey, number); |
| 8122 | editor.putString(subscriberPrefKey, subscriberId); |
| 8123 | } |
| 8124 | |
| 8125 | editor.commit(); |
| 8126 | return true; |
| 8127 | } finally { |
| 8128 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 8129 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 8130 | } |
| 8131 | |
| 8132 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8133 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 8134 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 8135 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8136 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8137 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 8138 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8139 | return null; |
| 8140 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 8141 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8142 | final long identity = Binder.clearCallingIdentity(); |
| 8143 | try { |
| 8144 | String iccId = getIccId(subId); |
| 8145 | if (iccId != null) { |
| 8146 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8147 | if (DBG_MERGE) { |
| 8148 | log("getLine1NumberForDisplay returning " |
| 8149 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 8150 | } |
| 8151 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 8152 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8153 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 8154 | return null; |
| 8155 | } finally { |
| 8156 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 8157 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 8158 | } |
| 8159 | |
| 8160 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8161 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 8162 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8163 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8164 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8165 | return null; |
| 8166 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 8167 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8168 | final long identity = Binder.clearCallingIdentity(); |
| 8169 | try { |
| 8170 | String iccId = getIccId(subId); |
| 8171 | if (iccId != null) { |
| 8172 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 8173 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 8174 | } |
| 8175 | return null; |
| 8176 | } finally { |
| 8177 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 8178 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 8179 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8180 | |
| 8181 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8182 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 8183 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8184 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 8185 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8186 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8187 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8188 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8189 | return null; |
| 8190 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8191 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 8192 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 8193 | // the process, where TelephonyManager was instantiated. |
| 8194 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8195 | final long identity = Binder.clearCallingIdentity(); |
| 8196 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8197 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8198 | final TelephonyManager tele = TelephonyManager.from(context); |
| 8199 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 8200 | |
| 8201 | // Figure out what subscribers are currently active |
| 8202 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8203 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 8204 | // Only consider subs which match the current subId |
| 8205 | // This logic can be simplified. See b/131189269 for progress. |
| 8206 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8207 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 8208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8209 | |
| 8210 | // First pass, find a number override for an active subscriber |
| 8211 | String mergeNumber = null; |
| 8212 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 8213 | for (String key : prefs.keySet()) { |
| 8214 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 8215 | final String subscriberId = (String) prefs.get(key); |
| 8216 | if (activeSubscriberIds.contains(subscriberId)) { |
| 8217 | final String iccId = key.substring( |
| 8218 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 8219 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8220 | mergeNumber = (String) prefs.get(numberKey); |
| 8221 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8222 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8223 | + " for active subscriber " + subscriberId); |
| 8224 | } |
| 8225 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 8226 | break; |
| 8227 | } |
| 8228 | } |
| 8229 | } |
| 8230 | } |
| 8231 | |
| 8232 | // Shortcut when no active merged subscribers |
| 8233 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8234 | return null; |
| 8235 | } |
| 8236 | |
| 8237 | // Second pass, find all subscribers under that line override |
| 8238 | final ArraySet<String> result = new ArraySet<>(); |
| 8239 | for (String key : prefs.keySet()) { |
| 8240 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8241 | final String number = (String) prefs.get(key); |
| 8242 | if (mergeNumber.equals(number)) { |
| 8243 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8244 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8245 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8246 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8247 | result.add(subscriberId); |
| 8248 | } |
| 8249 | } |
| 8250 | } |
| 8251 | } |
| 8252 | |
| 8253 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8254 | Arrays.sort(resultArray); |
| 8255 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8256 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8257 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8258 | } |
| 8259 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8260 | } finally { |
| 8261 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8262 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8263 | } |
| 8264 | |
| 8265 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8266 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8267 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8268 | |
| 8269 | final long identity = Binder.clearCallingIdentity(); |
| 8270 | try { |
| 8271 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8272 | TelephonyManager.class); |
| 8273 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8274 | if (subscriberId == null) { |
| 8275 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8276 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8277 | + subId); |
| 8278 | } |
| 8279 | return null; |
| 8280 | } |
| 8281 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8282 | ParcelUuid groupUuid; |
| 8283 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8284 | final SubscriptionInfo info = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8285 | .getSubscriptionInfo(subId); |
| 8286 | groupUuid = info.getGroupUuid(); |
| 8287 | } else { |
| 8288 | final SubscriptionInfo info = mSubscriptionController |
| 8289 | .getSubscriptionInfo(subId); |
| 8290 | groupUuid = info.getGroupUuid(); |
| 8291 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8292 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8293 | if (groupUuid == null) { |
| 8294 | return new String[]{subscriberId}; |
| 8295 | } |
| 8296 | |
| 8297 | // Get all subscriberIds from the group. |
| 8298 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8299 | List<SubscriptionInfo> groupInfos; |
| 8300 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8301 | groupInfos = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8302 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8303 | mApp.getAttributionTag()); |
| 8304 | } else { |
| 8305 | groupInfos = mSubscriptionController |
| 8306 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8307 | mApp.getAttributionTag()); |
| 8308 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8309 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8310 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8311 | if (subscriberId != null) { |
| 8312 | mergedSubscriberIds.add(subscriberId); |
| 8313 | } |
| 8314 | } |
| 8315 | |
| 8316 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8317 | } finally { |
| 8318 | Binder.restoreCallingIdentity(identity); |
| 8319 | |
| 8320 | } |
| 8321 | } |
| 8322 | |
| 8323 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8324 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8325 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8326 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8327 | |
| 8328 | final long identity = Binder.clearCallingIdentity(); |
| 8329 | try { |
| 8330 | final Phone phone = getPhone(subId); |
| 8331 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8332 | } finally { |
| 8333 | Binder.restoreCallingIdentity(identity); |
| 8334 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8335 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8336 | |
| 8337 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8338 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8339 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8340 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8341 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8342 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8343 | |
| 8344 | final long identity = Binder.clearCallingIdentity(); |
| 8345 | try { |
| 8346 | final Phone phone = getPhone(subId); |
| 8347 | if (phone == null) { |
| 8348 | return false; |
| 8349 | } |
| 8350 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8351 | cdmaNonRoamingList); |
| 8352 | } finally { |
| 8353 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8354 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8355 | } |
| 8356 | |
| 8357 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 8358 | @Deprecated |
| 8359 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 8360 | enforceModifyPermission(); |
| 8361 | |
| 8362 | int returnValue = 0; |
| 8363 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8364 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 8365 | if(result.exception == null) { |
| 8366 | if (result.result != null) { |
| 8367 | byte[] responseData = (byte[])(result.result); |
| 8368 | if(responseData.length > oemResp.length) { |
| 8369 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 8370 | responseData.length + "bytes. Buffer Size is " + |
| 8371 | oemResp.length + "bytes."); |
| 8372 | } |
| 8373 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 8374 | returnValue = responseData.length; |
| 8375 | } |
| 8376 | } else { |
| 8377 | CommandException ex = (CommandException) result.exception; |
| 8378 | returnValue = ex.getCommandError().ordinal(); |
| 8379 | if(returnValue > 0) returnValue *= -1; |
| 8380 | } |
| 8381 | } catch (RuntimeException e) { |
| 8382 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 8383 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 8384 | if(returnValue > 0) returnValue *= -1; |
| 8385 | } |
| 8386 | |
| 8387 | return returnValue; |
| 8388 | } |
| 8389 | |
| 8390 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8391 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8392 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8393 | try { |
| 8394 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8395 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8396 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8397 | } catch (SecurityException e) { |
| 8398 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8399 | throw e; |
| 8400 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8401 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8402 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8403 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8404 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8405 | final long identity = Binder.clearCallingIdentity(); |
| 8406 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8407 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8408 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8409 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8410 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8411 | } finally { |
| 8412 | Binder.restoreCallingIdentity(identity); |
| 8413 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8414 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8415 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8416 | |
| 8417 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8418 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8419 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8420 | try { |
| 8421 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8422 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8423 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8424 | } |
| 8425 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8426 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8427 | } |
| 8428 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8429 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8430 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8431 | throw new SecurityException("App must be the dialer role holder to" |
| 8432 | + " upload a call composer pic"); |
| 8433 | } |
| 8434 | |
| 8435 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8436 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8437 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8438 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8439 | boolean readUntilEnd = false; |
| 8440 | int totalBytesRead = 0; |
| 8441 | byte[] buffer = new byte[16 * 1024]; |
| 8442 | while (true) { |
| 8443 | int numRead; |
| 8444 | try { |
| 8445 | numRead = input.read(buffer); |
| 8446 | } catch (IOException e) { |
| 8447 | try { |
| 8448 | fd.checkError(); |
| 8449 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8450 | null); |
| 8451 | } catch (IOException e1) { |
| 8452 | // This means that the other side closed explicitly with an error. If this |
| 8453 | // happens, log and ignore. |
| 8454 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8455 | } |
| 8456 | break; |
| 8457 | } |
| 8458 | if (numRead == -1) { |
| 8459 | readUntilEnd = true; |
| 8460 | break; |
| 8461 | } |
| 8462 | totalBytesRead += numRead; |
| 8463 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8464 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8465 | try { |
| 8466 | input.close(); |
| 8467 | } catch (IOException e) { |
| 8468 | // ignore |
| 8469 | } |
| 8470 | break; |
| 8471 | } |
| 8472 | output.write(buffer, 0, numRead); |
| 8473 | } |
| 8474 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8475 | // close is above, where the picture size is too big. |
| 8476 | |
| 8477 | try { |
| 8478 | fd.checkError(); |
| 8479 | } catch (IOException e) { |
| 8480 | loge("Remote end for call composer closed with an error: " + e); |
| 8481 | return; |
| 8482 | } |
| 8483 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8484 | if (!readUntilEnd) { |
| 8485 | loge("Did not finish reading entire image; aborting"); |
| 8486 | return; |
| 8487 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8488 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8489 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8490 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8491 | new CallComposerPictureTransfer.Factory() {}, |
| 8492 | imageData, |
| 8493 | (result) -> { |
| 8494 | if (result.first != null) { |
| 8495 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8496 | Bundle outputResult = new Bundle(); |
| 8497 | outputResult.putParcelable( |
| 8498 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8499 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8500 | outputResult); |
| 8501 | } else { |
| 8502 | callback.send(result.second, null); |
| 8503 | } |
| 8504 | } |
| 8505 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8506 | }); |
| 8507 | } |
| 8508 | |
| 8509 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8510 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8511 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8512 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8513 | |
| 8514 | final long identity = Binder.clearCallingIdentity(); |
| 8515 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8516 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8517 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8518 | } finally { |
| 8519 | Binder.restoreCallingIdentity(identity); |
| 8520 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8521 | } |
| 8522 | |
| 8523 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8524 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8525 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8526 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8527 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8528 | return false; |
| 8529 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8530 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8531 | final long identity = Binder.clearCallingIdentity(); |
| 8532 | try { |
| 8533 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8534 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8535 | // In the long run, we may instead need to check if there exists a connection service |
| 8536 | // which can support video calling. |
| 8537 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8538 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8539 | return imsManager.isVtEnabledByPlatform() |
| 8540 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8541 | && imsManager.isVtEnabledByUser(); |
| 8542 | } finally { |
| 8543 | Binder.restoreCallingIdentity(identity); |
| 8544 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8545 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8546 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8547 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8548 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8549 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8550 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8551 | mApp, subId, callingPackage, callingFeatureId, |
| 8552 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8553 | return false; |
| 8554 | } |
| 8555 | |
| 8556 | final long identity = Binder.clearCallingIdentity(); |
| 8557 | try { |
| 8558 | CarrierConfigManager configManager = |
| 8559 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8560 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8561 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8562 | } finally { |
| 8563 | Binder.restoreCallingIdentity(identity); |
| 8564 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8565 | } |
| 8566 | |
| 8567 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8568 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8569 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8570 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 | return false; |
| 8572 | } |
| 8573 | |
| 8574 | final long identity = Binder.clearCallingIdentity(); |
| 8575 | try { |
| 8576 | CarrierConfigManager configManager = |
| 8577 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8578 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8579 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8580 | } finally { |
| 8581 | Binder.restoreCallingIdentity(identity); |
| 8582 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8583 | } |
| 8584 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8585 | @Override |
| 8586 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8587 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8588 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8589 | } |
| 8590 | |
| 8591 | @Override |
| 8592 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8593 | final long identity = Binder.clearCallingIdentity(); |
| 8594 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8595 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8596 | } finally { |
| 8597 | Binder.restoreCallingIdentity(identity); |
| 8598 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8599 | } |
| 8600 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8601 | /** |
| 8602 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8603 | * support for the feature and device firmware support. |
| 8604 | * |
| 8605 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8606 | */ |
| 8607 | @Override |
| 8608 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8609 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8610 | final Phone phone = getPhone(subscriptionId); |
| 8611 | if (phone == null) { |
| 8612 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8613 | return false; |
| 8614 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8615 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8616 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8617 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 8618 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8619 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8620 | return isCarrierSupported && isDeviceSupported; |
| 8621 | } finally { |
| 8622 | Binder.restoreCallingIdentity(identity); |
| 8623 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8624 | } |
| 8625 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8626 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8627 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8628 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8629 | * 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] | 8630 | */ |
| 8631 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8632 | final long identity = Binder.clearCallingIdentity(); |
| 8633 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8634 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8635 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8636 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8637 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8638 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8639 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8640 | } finally { |
| 8641 | Binder.restoreCallingIdentity(identity); |
| 8642 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8643 | } |
| 8644 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8645 | @Deprecated |
| 8646 | @Override |
| 8647 | public String getDeviceId(String callingPackage) { |
| 8648 | return getDeviceIdWithFeature(callingPackage, null); |
| 8649 | } |
| 8650 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8651 | /** |
| 8652 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8653 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8654 | * |
| 8655 | * <p>Requires Permission: |
| 8656 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8657 | */ |
| 8658 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8659 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8660 | try { |
| 8661 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8662 | } catch (SecurityException se) { |
| 8663 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8664 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8665 | + Binder.getCallingUid()); |
| 8666 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8667 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8668 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8669 | return null; |
| 8670 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8671 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8672 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8673 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8674 | return null; |
| 8675 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8676 | |
| 8677 | final long identity = Binder.clearCallingIdentity(); |
| 8678 | try { |
| 8679 | return phone.getDeviceId(); |
| 8680 | } finally { |
| 8681 | Binder.restoreCallingIdentity(identity); |
| 8682 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8683 | } |
| 8684 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8685 | /** |
| 8686 | * {@hide} |
| 8687 | * Returns the IMS Registration Status on a particular subid |
| 8688 | * |
| 8689 | * @param subId |
| 8690 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8691 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8692 | Phone phone = getPhone(subId); |
| 8693 | if (phone != null) { |
| 8694 | return phone.isImsRegistered(); |
| 8695 | } else { |
| 8696 | return false; |
| 8697 | } |
| 8698 | } |
| 8699 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8700 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8701 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8702 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8703 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8704 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8705 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8706 | } |
| 8707 | final long identity = Binder.clearCallingIdentity(); |
| 8708 | try { |
| 8709 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8710 | } finally { |
| 8711 | Binder.restoreCallingIdentity(identity); |
| 8712 | } |
| 8713 | } |
| 8714 | |
| 8715 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8716 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8717 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8718 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8719 | mApp, |
| 8720 | subscriptionId, |
| 8721 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8722 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8723 | final long identity = Binder.clearCallingIdentity(); |
| 8724 | try { |
| 8725 | Phone phone = getPhone(subscriptionId); |
| 8726 | if (phone == null) { |
| 8727 | return null; |
| 8728 | } |
| 8729 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8730 | } finally { |
| 8731 | Binder.restoreCallingIdentity(identity); |
| 8732 | } |
| 8733 | } |
| 8734 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8735 | /** |
| 8736 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8737 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8738 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8739 | final long identity = Binder.clearCallingIdentity(); |
| 8740 | try { |
| 8741 | Phone phone = getPhone(subId); |
| 8742 | if (phone != null) { |
| 8743 | return phone.isWifiCallingEnabled(); |
| 8744 | } else { |
| 8745 | return false; |
| 8746 | } |
| 8747 | } finally { |
| 8748 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8749 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8750 | } |
| 8751 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8752 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8753 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8754 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8755 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8756 | final long identity = Binder.clearCallingIdentity(); |
| 8757 | try { |
| 8758 | Phone phone = getPhone(subId); |
| 8759 | if (phone != null) { |
| 8760 | return phone.isVideoEnabled(); |
| 8761 | } else { |
| 8762 | return false; |
| 8763 | } |
| 8764 | } finally { |
| 8765 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8766 | } |
| 8767 | } |
| 8768 | |
| 8769 | /** |
| 8770 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8771 | * defined in {@link ImsRegistrationImplBase}. |
| 8772 | */ |
| 8773 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8774 | final long identity = Binder.clearCallingIdentity(); |
| 8775 | try { |
| 8776 | Phone phone = getPhone(subId); |
| 8777 | if (phone != null) { |
| 8778 | return phone.getImsRegistrationTech(); |
| 8779 | } else { |
| 8780 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8781 | } |
| 8782 | } finally { |
| 8783 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8784 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8785 | } |
| 8786 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8787 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8788 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8789 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8790 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8791 | return; |
| 8792 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8793 | Phone defaultPhone = getDefaultPhone(); |
| 8794 | if (defaultPhone != null) { |
| 8795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8796 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8797 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8798 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8799 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8800 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8801 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8802 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8803 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8804 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8805 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8806 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8807 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8808 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8809 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8810 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8811 | // There has been issues when Sms raw table somehow stores orphan |
| 8812 | // fragments. They lead to garbled message when new fragments come |
| 8813 | // in and combined with those stale ones. In case this happens again, |
| 8814 | // user can reset all network settings which will clean up this table. |
| 8815 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8816 | // Clean up IMS settings as well here. |
| 8817 | int slotId = getSlotIndex(subId); |
| 8818 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8819 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8820 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8821 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8822 | if (defaultPhone == null) { |
| 8823 | return; |
| 8824 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8825 | // Erase modem config if erase modem on network setting is enabled. |
| 8826 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8827 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8828 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8829 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8830 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8831 | |
| 8832 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8833 | } finally { |
| 8834 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8835 | } |
| 8836 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8837 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8838 | @VisibleForTesting |
| 8839 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8840 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8841 | return; |
| 8842 | } |
| 8843 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8844 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8845 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8846 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8847 | "user=" + defaultNetworkType); |
| 8848 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8849 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8850 | defaultNetworkType, null); |
| 8851 | } |
| 8852 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8853 | private void cleanUpSmsRawTable(Context context) { |
| 8854 | ContentResolver resolver = context.getContentResolver(); |
| 8855 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8856 | resolver.delete(uri, null, null); |
| 8857 | } |
| 8858 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8859 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8860 | public String getSimLocaleForSubscriber(int subId) { |
| 8861 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8862 | final Phone phone = getPhone(subId); |
| 8863 | if (phone == null) { |
| 8864 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8865 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8866 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8867 | final long identity = Binder.clearCallingIdentity(); |
| 8868 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8869 | SubscriptionInfo info; |
| 8870 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8871 | info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8872 | phone.getContext().getOpPackageName(), |
| 8873 | phone.getContext().getAttributionTag()); |
| 8874 | if (info == null) { |
| 8875 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8876 | return null; |
| 8877 | } |
| 8878 | } else { |
| 8879 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 8880 | phone.getContext().getOpPackageName(), |
| 8881 | phone.getContext().getAttributionTag()); |
| 8882 | if (info == null) { |
| 8883 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8884 | return null; |
| 8885 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8886 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8887 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8888 | // preferences (EF-PL and EF-LI)... |
| 8889 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8890 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8891 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8892 | if (localeFromDefaultSim != null) { |
| 8893 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8894 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8895 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8896 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8897 | } else { |
| 8898 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8899 | } |
| 8900 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8901 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8902 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8903 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8904 | // the SIM and carrier preferences does not include a country we add the country |
| 8905 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8906 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8907 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8908 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8909 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8910 | } |
| 8911 | |
| 8912 | if (DBG) log("No locale found - returning null"); |
| 8913 | return null; |
| 8914 | } finally { |
| 8915 | Binder.restoreCallingIdentity(identity); |
| 8916 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8917 | } |
| 8918 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8919 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8920 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8921 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8922 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8923 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8924 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8925 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8926 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8927 | return localeTag; |
| 8928 | } |
| 8929 | } |
| 8930 | return inputLocale.toLanguageTag(); |
| 8931 | } |
| 8932 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8933 | /** |
| 8934 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8935 | */ |
| 8936 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8937 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8938 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8939 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8940 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8941 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8942 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8943 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8944 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8945 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8946 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8947 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8948 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8949 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8950 | * representing the state of the modem. |
| 8951 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8952 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8953 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8954 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8955 | */ |
| 8956 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8957 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8958 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8959 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8960 | |
| 8961 | final long identity = Binder.clearCallingIdentity(); |
| 8962 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8963 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8964 | } finally { |
| 8965 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8966 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8967 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8968 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8969 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8970 | // less than total activity duration. |
| 8971 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8972 | if (info == null) { |
| 8973 | return false; |
| 8974 | } |
| 8975 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8976 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8977 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8978 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8979 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8980 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8981 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8982 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8983 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8984 | } |
| 8985 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8986 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8987 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8988 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8989 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8990 | |
| 8991 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8992 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8993 | } |
| 8994 | |
| 8995 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8996 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8997 | rat, |
| 8998 | freq, |
| 8999 | info.getReceiveTimeMillis(rat, freq) |
| 9000 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 9001 | } |
| 9002 | |
| 9003 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 9004 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 9005 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 9006 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 9007 | |
| 9008 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 9009 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 9010 | } |
| 9011 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 9012 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 9013 | rat, |
| 9014 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 9015 | } |
| 9016 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9017 | /** |
| 9018 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 9019 | * @param info recent ModemActivityInfo |
| 9020 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 9021 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 9022 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 9023 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 9024 | boolean matched; |
| 9025 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 9026 | matched = false; |
| 9027 | int rat = info.getSpecificInfoRat(i); |
| 9028 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 9029 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 9030 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 9031 | //if it already exists |
| 9032 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 9033 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 9034 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 9035 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 9036 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 9037 | updateLastModemActivityInfo(info, rat, freq); |
| 9038 | matched = true; |
| 9039 | } |
| 9040 | } else { |
| 9041 | updateLastModemActivityInfo(info, rat); |
| 9042 | matched = true; |
| 9043 | } |
| 9044 | } |
| 9045 | } |
| 9046 | |
| 9047 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 9048 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 9049 | new ActivityStatsTechSpecificInfo( |
| 9050 | rat, |
| 9051 | freq, |
| 9052 | info.getTransmitTimeMillis(rat, freq), |
| 9053 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 9054 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 9055 | } |
| 9056 | } |
| 9057 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 9058 | mLastModemActivitySpecificInfo = |
| 9059 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 9060 | merged.toArray(mLastModemActivitySpecificInfo); |
| 9061 | |
| 9062 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 9063 | mLastModemActivityInfo.setSleepTimeMillis( |
| 9064 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9065 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 9066 | mLastModemActivityInfo.setIdleTimeMillis( |
| 9067 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9068 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 9069 | |
| 9070 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9071 | new ModemActivityInfo( |
| 9072 | mLastModemActivityInfo.getTimestampMillis(), |
| 9073 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 9074 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 9075 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 9076 | } |
| 9077 | |
| 9078 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 9079 | ActivityStatsTechSpecificInfo[] info) { |
| 9080 | int infoSize = info.length; |
| 9081 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 9082 | for (int i = 0; i < infoSize; i++) { |
| 9083 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 9084 | info[i].getRat(), info[i].getFrequencyRange(), |
| 9085 | info[i].getTransmitTimeMillis(), |
| 9086 | (int) info[i].getReceiveTimeMillis()); |
| 9087 | } |
| 9088 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 9089 | } |
| 9090 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 9091 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 9092 | * Returns the service state information on specified subscription. |
| 9093 | */ |
| 9094 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 9095 | public ServiceState getServiceStateForSubscriber(int subId, |
| 9096 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 9097 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9098 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9099 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 9100 | return null; |
| 9101 | } |
| 9102 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 9103 | boolean hasFinePermission = false; |
| 9104 | boolean hasCoarsePermission = false; |
| 9105 | if (!renounceFineLocationAccess) { |
| 9106 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 9107 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 9108 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 9109 | .setCallingPackage(callingPackage) |
| 9110 | .setCallingFeatureId(callingFeatureId) |
| 9111 | .setCallingPid(Binder.getCallingPid()) |
| 9112 | .setCallingUid(Binder.getCallingUid()) |
| 9113 | .setMethod("getServiceStateForSubscriber") |
| 9114 | .setLogAsInfo(true) |
| 9115 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 9116 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 9117 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 9118 | .build()); |
| 9119 | hasFinePermission = |
| 9120 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 9121 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 9122 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 9123 | if (!renounceCoarseLocationAccess) { |
| 9124 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 9125 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 9126 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 9127 | .setCallingPackage(callingPackage) |
| 9128 | .setCallingFeatureId(callingFeatureId) |
| 9129 | .setCallingPid(Binder.getCallingPid()) |
| 9130 | .setCallingUid(Binder.getCallingUid()) |
| 9131 | .setMethod("getServiceStateForSubscriber") |
| 9132 | .setLogAsInfo(true) |
| 9133 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 9134 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 9135 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 9136 | .build()); |
| 9137 | hasCoarsePermission = |
| 9138 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 9139 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 9140 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 9141 | final Phone phone = getPhone(subId); |
| 9142 | if (phone == null) { |
| 9143 | return null; |
| 9144 | } |
| 9145 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 9146 | final long identity = Binder.clearCallingIdentity(); |
| 9147 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 9148 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 9149 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9150 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 9151 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9152 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 9153 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9154 | .getSubscriptionInfoInternal(subId); |
| 9155 | if (subInfo == null || !subInfo.isActive()) { |
| 9156 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 9157 | + "subId=" + subId); |
| 9158 | return null; |
| 9159 | } |
| 9160 | } else { |
| 9161 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 9162 | callingFeatureId)) { |
| 9163 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 9164 | + "subId=" + subId); |
| 9165 | return null; |
| 9166 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 9167 | } |
| 9168 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 9169 | ServiceState ss = phone.getServiceState(); |
| 9170 | |
| 9171 | // Scrub out the location info in ServiceState depending on what level of access |
| 9172 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 9173 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 9174 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 9175 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9176 | } finally { |
| 9177 | Binder.restoreCallingIdentity(identity); |
| 9178 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 9179 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9180 | |
| 9181 | /** |
| 9182 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 9183 | * |
| 9184 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9185 | * voicemail ringtone. |
| 9186 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 9187 | * PhoneAccount. |
| 9188 | */ |
| 9189 | @Override |
| 9190 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9191 | final long identity = Binder.clearCallingIdentity(); |
| 9192 | try { |
| 9193 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9194 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9195 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9196 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9197 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9198 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 9199 | } finally { |
| 9200 | Binder.restoreCallingIdentity(identity); |
| 9201 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9202 | } |
| 9203 | |
| 9204 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9205 | * Sets the per-account voicemail ringtone. |
| 9206 | * |
| 9207 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9208 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9209 | * |
| 9210 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9211 | * voicemail ringtone. |
| 9212 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 9213 | * PhoneAccount. |
| 9214 | */ |
| 9215 | @Override |
| 9216 | public void setVoicemailRingtoneUri(String callingPackage, |
| 9217 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9218 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9219 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9220 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9221 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9222 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9223 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9224 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9225 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9226 | |
| 9227 | final long identity = Binder.clearCallingIdentity(); |
| 9228 | try { |
| 9229 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9230 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9231 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9232 | } |
| 9233 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9234 | } finally { |
| 9235 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9236 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9237 | } |
| 9238 | |
| 9239 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9240 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9241 | * |
| 9242 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9243 | * voicemail vibration setting. |
| 9244 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9245 | */ |
| 9246 | @Override |
| 9247 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9248 | final long identity = Binder.clearCallingIdentity(); |
| 9249 | try { |
| 9250 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9251 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9252 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9253 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9254 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9255 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9256 | } finally { |
| 9257 | Binder.restoreCallingIdentity(identity); |
| 9258 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9259 | } |
| 9260 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9261 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9262 | * Sets the per-account voicemail vibration. |
| 9263 | * |
| 9264 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9265 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9266 | * |
| 9267 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9268 | * voicemail vibration setting. |
| 9269 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9270 | * specific PhoneAccount. |
| 9271 | */ |
| 9272 | @Override |
| 9273 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9274 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9275 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9277 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9278 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9279 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9280 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9281 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9282 | } |
| 9283 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9284 | final long identity = Binder.clearCallingIdentity(); |
| 9285 | try { |
| 9286 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9287 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9288 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9289 | } |
| 9290 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9291 | } finally { |
| 9292 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9293 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9294 | } |
| 9295 | |
| 9296 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9297 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9298 | * |
| 9299 | * @throws SecurityException if the caller does not have the required permission |
| 9300 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9301 | @VisibleForTesting |
| 9302 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9303 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9304 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9305 | } |
| 9306 | |
| 9307 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9308 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9309 | * permission. |
| 9310 | * |
| 9311 | * @throws SecurityException if the caller does not have the required permission |
| 9312 | */ |
| 9313 | private void enforceSendSmsPermission() { |
| 9314 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9315 | } |
| 9316 | |
| 9317 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9318 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9319 | * users permission. |
| 9320 | * |
| 9321 | * @throws SecurityException if the caller does not have the required permission |
| 9322 | */ |
| 9323 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9324 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9325 | } |
| 9326 | |
| 9327 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9328 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9329 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9330 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9331 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9332 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9333 | final long identity = Binder.clearCallingIdentity(); |
| 9334 | try { |
| 9335 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9336 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9337 | if (componentName == null) { |
| 9338 | throw new SecurityException( |
| 9339 | "Caller not current active visual voicemail package[null]"); |
| 9340 | } |
| 9341 | String vvmPackage = componentName.getPackageName(); |
| 9342 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9343 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9344 | } |
| 9345 | } finally { |
| 9346 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9347 | } |
| 9348 | } |
| 9349 | |
| 9350 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9351 | * Return the application ID for the app type. |
| 9352 | * |
| 9353 | * @param subId the subscription ID that this request applies to. |
| 9354 | * @param appType the uicc app type. |
| 9355 | * @return Application ID for specificied app type, or null if no uicc. |
| 9356 | */ |
| 9357 | @Override |
| 9358 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9359 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9360 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9361 | |
| 9362 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9363 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9364 | if (phone == null) { |
| 9365 | return null; |
| 9366 | } |
| 9367 | String aid = null; |
| 9368 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9369 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9370 | .getApplicationByType(appType).getAid(); |
| 9371 | } catch (Exception e) { |
| 9372 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9373 | } |
| 9374 | return aid; |
| 9375 | } finally { |
| 9376 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9377 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9378 | } |
| 9379 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9380 | /** |
| 9381 | * Return the Electronic Serial Number. |
| 9382 | * |
| 9383 | * @param subId the subscription ID that this request applies to. |
| 9384 | * @return ESN or null if error. |
| 9385 | */ |
| 9386 | @Override |
| 9387 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9388 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9389 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9390 | |
| 9391 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9392 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9393 | if (phone == null) { |
| 9394 | return null; |
| 9395 | } |
| 9396 | String esn = null; |
| 9397 | try { |
| 9398 | esn = phone.getEsn(); |
| 9399 | } catch (Exception e) { |
| 9400 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9401 | } |
| 9402 | return esn; |
| 9403 | } finally { |
| 9404 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9405 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9406 | } |
| 9407 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9408 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9409 | * Return the Preferred Roaming List Version. |
| 9410 | * |
| 9411 | * @param subId the subscription ID that this request applies to. |
| 9412 | * @return PRLVersion or null if error. |
| 9413 | */ |
| 9414 | @Override |
| 9415 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9416 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9417 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9418 | |
| 9419 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9420 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9421 | if (phone == null) { |
| 9422 | return null; |
| 9423 | } |
| 9424 | String cdmaPrlVersion = null; |
| 9425 | try { |
| 9426 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9427 | } catch (Exception e) { |
| 9428 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9429 | } |
| 9430 | return cdmaPrlVersion; |
| 9431 | } finally { |
| 9432 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9433 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9434 | } |
| 9435 | |
| 9436 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9437 | * Get snapshot of Telephony histograms |
| 9438 | * @return List of Telephony histograms |
| 9439 | * @hide |
| 9440 | */ |
| 9441 | @Override |
| 9442 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9443 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9444 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9445 | |
| 9446 | final long identity = Binder.clearCallingIdentity(); |
| 9447 | try { |
| 9448 | return RIL.getTelephonyRILTimingHistograms(); |
| 9449 | } finally { |
| 9450 | Binder.restoreCallingIdentity(identity); |
| 9451 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9452 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9453 | |
| 9454 | /** |
| 9455 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9456 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9457 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9458 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9459 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9460 | * @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] | 9461 | */ |
| 9462 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9463 | @TelephonyManager.SetCarrierRestrictionResult |
| 9464 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9465 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9466 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9467 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9468 | if (carrierRestrictionRules == null) { |
| 9469 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9470 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9472 | final long identity = Binder.clearCallingIdentity(); |
| 9473 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9474 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9475 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9476 | } finally { |
| 9477 | Binder.restoreCallingIdentity(identity); |
| 9478 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9479 | } |
| 9480 | |
| 9481 | /** |
| 9482 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9483 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9484 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9485 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9486 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9487 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9488 | */ |
| 9489 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9490 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9491 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9492 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9493 | |
| 9494 | final long identity = Binder.clearCallingIdentity(); |
| 9495 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9496 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9497 | if (response instanceof CarrierRestrictionRules) { |
| 9498 | return (CarrierRestrictionRules) response; |
| 9499 | } |
| 9500 | // Response is an Exception of some kind, |
| 9501 | // which is signalled to the user as a NULL retval |
| 9502 | return null; |
| 9503 | } catch (Exception e) { |
| 9504 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9505 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9506 | } finally { |
| 9507 | Binder.restoreCallingIdentity(identity); |
| 9508 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9509 | } |
| 9510 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9511 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9512 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9513 | * through the callback. |
| 9514 | * |
| 9515 | * @param callback The callback that will be used to send the result. |
| 9516 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9517 | * the caller is not allowlisted. |
| 9518 | */ |
| 9519 | @Override |
| 9520 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9521 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 9522 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 9523 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 9524 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9525 | throw new SecurityException("Not an authorized caller"); |
| 9526 | } |
| 9527 | final long identity = Binder.clearCallingIdentity(); |
| 9528 | try { |
| 9529 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 9530 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 9531 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9532 | } finally { |
| 9533 | Binder.restoreCallingIdentity(identity); |
| 9534 | } |
| 9535 | } |
| 9536 | |
| 9537 | @VisibleForTesting |
| 9538 | public int validateCallerAndGetCarrierId(String packageName) { |
| 9539 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9540 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 9541 | } |
| 9542 | |
| 9543 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9544 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9545 | * @param subId the subscription ID that this action applies to. |
| 9546 | * @param enabled control enable or disable radio. |
| 9547 | * {@hide} |
| 9548 | */ |
| 9549 | @Override |
| 9550 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9551 | enforceModifyPermission(); |
| 9552 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9553 | |
| 9554 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9555 | if (phone == null) { |
| 9556 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9557 | return; |
| 9558 | } |
| 9559 | try { |
| 9560 | phone.carrierActionSetRadioEnabled(enabled); |
| 9561 | } catch (Exception e) { |
| 9562 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9563 | } finally { |
| 9564 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9565 | } |
| 9566 | } |
| 9567 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9568 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9569 | * Enable or disable Voice over NR (VoNR) |
| 9570 | * @param subId the subscription ID that this action applies to. |
| 9571 | * @param enabled enable or disable VoNR. |
| 9572 | * @return operation result. |
| 9573 | */ |
| 9574 | @Override |
| 9575 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9576 | enforceModifyPermission(); |
| 9577 | final Phone phone = getPhone(subId); |
| 9578 | |
| 9579 | final long identity = Binder.clearCallingIdentity(); |
| 9580 | if (phone == null) { |
| 9581 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9582 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9583 | } |
| 9584 | |
| 9585 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9586 | try { |
| 9587 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9588 | workSource); |
| 9589 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9590 | |
| 9591 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9592 | if (DBG) { |
| 9593 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9594 | } |
| 9595 | SubscriptionManager.setSubscriptionProperty( |
| 9596 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9597 | (enabled ? "1" : "0")); |
| 9598 | } |
| 9599 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9600 | return result; |
| 9601 | } finally { |
| 9602 | Binder.restoreCallingIdentity(identity); |
| 9603 | } |
| 9604 | } |
| 9605 | |
| 9606 | /** |
| 9607 | * Is voice over NR enabled |
| 9608 | * @return true if VoNR is enabled else false |
| 9609 | */ |
| 9610 | @Override |
| 9611 | public boolean isVoNrEnabled(int subId) { |
| 9612 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9613 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9614 | final long identity = Binder.clearCallingIdentity(); |
| 9615 | try { |
| 9616 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9617 | null, subId, workSource); |
| 9618 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9619 | return isEnabled; |
| 9620 | } finally { |
| 9621 | Binder.restoreCallingIdentity(identity); |
| 9622 | } |
| 9623 | } |
| 9624 | |
| 9625 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9626 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9627 | * network status based on which carrier apps could apply actions accordingly, |
| 9628 | * enable/disable default url handler for example. |
| 9629 | * |
| 9630 | * @param subId the subscription ID that this action applies to. |
| 9631 | * @param report control start/stop reporting the default network status. |
| 9632 | * {@hide} |
| 9633 | */ |
| 9634 | @Override |
| 9635 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9636 | enforceModifyPermission(); |
| 9637 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9638 | |
| 9639 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9640 | if (phone == null) { |
| 9641 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9642 | return; |
| 9643 | } |
| 9644 | try { |
| 9645 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9646 | } catch (Exception e) { |
| 9647 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9648 | } finally { |
| 9649 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9650 | } |
| 9651 | } |
| 9652 | |
| 9653 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9654 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9655 | * @param subId the subscription ID that this action applies to. |
| 9656 | * {@hide} |
| 9657 | */ |
| 9658 | @Override |
| 9659 | public void carrierActionResetAll(int subId) { |
| 9660 | enforceModifyPermission(); |
| 9661 | final Phone phone = getPhone(subId); |
| 9662 | if (phone == null) { |
| 9663 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9664 | return; |
| 9665 | } |
| 9666 | try { |
| 9667 | phone.carrierActionResetAll(); |
| 9668 | } catch (Exception e) { |
| 9669 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9670 | } |
| 9671 | } |
| 9672 | |
| 9673 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9674 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9675 | * bug report is being generated. |
| 9676 | */ |
| 9677 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9678 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9679 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9680 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9681 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9682 | + Binder.getCallingPid() |
| 9683 | + ", uid=" + Binder.getCallingUid() |
| 9684 | + "without permission " |
| 9685 | + android.Manifest.permission.DUMP); |
| 9686 | return; |
| 9687 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9688 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9689 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9690 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9691 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9692 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9693 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9694 | @NonNull String[] args) { |
| 9695 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9696 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9697 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9698 | } |
| 9699 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9700 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9701 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9702 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9703 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9704 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9705 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9706 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9707 | */ |
| 9708 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9709 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9710 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9711 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9712 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9713 | try { |
| 9714 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9715 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9716 | } catch (SecurityException se) { |
| 9717 | enforceModifyPermission(); |
| 9718 | } |
| 9719 | } else { |
| 9720 | enforceModifyPermission(); |
| 9721 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9722 | |
| 9723 | final long identity = Binder.clearCallingIdentity(); |
| 9724 | try { |
| 9725 | Phone phone = getPhone(subId); |
| 9726 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9727 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9728 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9729 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9730 | phone.getDataSettingsManager().setDataEnabled( |
| 9731 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9732 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9733 | } |
| 9734 | } finally { |
| 9735 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9736 | } |
| 9737 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9738 | |
| 9739 | /** |
| 9740 | * Get Client request stats |
| 9741 | * @return List of Client Request Stats |
| 9742 | * @hide |
| 9743 | */ |
| 9744 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9745 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9746 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9747 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9748 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9749 | return null; |
| 9750 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9751 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9753 | final long identity = Binder.clearCallingIdentity(); |
| 9754 | try { |
| 9755 | if (phone != null) { |
| 9756 | return phone.getClientRequestStats(); |
| 9757 | } |
| 9758 | |
| 9759 | return null; |
| 9760 | } finally { |
| 9761 | Binder.restoreCallingIdentity(identity); |
| 9762 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9763 | } |
| 9764 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9765 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9766 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9767 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9768 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9769 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9770 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9771 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9772 | // commands that plumb through the RIL as root, like so: |
| 9773 | // $ adb root |
| 9774 | // $ adb shell cmd phone ... |
| 9775 | packageName = "root"; |
| 9776 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9777 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9778 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9779 | |
| 9780 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9781 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9782 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9783 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9784 | * @param state State of SIM (power down, power up, pass through) |
| 9785 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9786 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9787 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9788 | * |
| 9789 | **/ |
| 9790 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9791 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9792 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9793 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9794 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9795 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9797 | final long identity = Binder.clearCallingIdentity(); |
| 9798 | try { |
| 9799 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9800 | phone.setSimPowerState(state, null, workSource); |
| 9801 | } |
| 9802 | } finally { |
| 9803 | Binder.restoreCallingIdentity(identity); |
| 9804 | } |
| 9805 | } |
| 9806 | |
| 9807 | /** |
| 9808 | * Set SIM card power state. |
| 9809 | * |
| 9810 | * @param slotIndex SIM slot id. |
| 9811 | * @param state State of SIM (power down, power up, pass through) |
| 9812 | * @param callback callback to trigger after success or failure |
| 9813 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9814 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9815 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9816 | * |
| 9817 | **/ |
| 9818 | @Override |
| 9819 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9820 | IIntegerConsumer callback) { |
| 9821 | enforceModifyPermission(); |
| 9822 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9823 | |
| 9824 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9825 | |
| 9826 | final long identity = Binder.clearCallingIdentity(); |
| 9827 | try { |
| 9828 | if (phone != null) { |
| 9829 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9830 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9831 | } |
| 9832 | } finally { |
| 9833 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9834 | } |
| 9835 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9836 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9837 | private boolean isUssdApiAllowed(int subId) { |
| 9838 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9839 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9840 | if (configManager == null) { |
| 9841 | return false; |
| 9842 | } |
| 9843 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9844 | if (pb == null) { |
| 9845 | return false; |
| 9846 | } |
| 9847 | return pb.getBoolean( |
| 9848 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9849 | } |
| 9850 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9851 | /** |
| 9852 | * Check if phone is in emergency callback mode |
| 9853 | * @return true if phone is in emergency callback mode |
| 9854 | * @param subId sub id |
| 9855 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9856 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9857 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9858 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9859 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9860 | |
| 9861 | final long identity = Binder.clearCallingIdentity(); |
| 9862 | try { |
| 9863 | if (phone != null) { |
| 9864 | return phone.isInEcm(); |
| 9865 | } else { |
| 9866 | return false; |
| 9867 | } |
| 9868 | } finally { |
| 9869 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9870 | } |
| 9871 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9872 | |
| 9873 | /** |
| 9874 | * Get the current signal strength information for the given subscription. |
| 9875 | * Because this information is not updated when the device is in a low power state |
| 9876 | * it should not be relied-upon to be current. |
| 9877 | * @param subId Subscription index |
| 9878 | * @return the most recent cached signal strength info from the modem |
| 9879 | */ |
| 9880 | @Override |
| 9881 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9882 | final long identity = Binder.clearCallingIdentity(); |
| 9883 | try { |
| 9884 | Phone p = getPhone(subId); |
| 9885 | if (p == null) { |
| 9886 | return null; |
| 9887 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9888 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9889 | return p.getSignalStrength(); |
| 9890 | } finally { |
| 9891 | Binder.restoreCallingIdentity(identity); |
| 9892 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9893 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9894 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9895 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9896 | * Get the current modem radio state for the given slot. |
| 9897 | * @param slotIndex slot index. |
| 9898 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9899 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9900 | * @return the current radio power state from the modem |
| 9901 | */ |
| 9902 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9903 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9904 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9905 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9906 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9907 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9908 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9909 | } |
| 9910 | |
| 9911 | final long identity = Binder.clearCallingIdentity(); |
| 9912 | try { |
| 9913 | return phone.getRadioPowerState(); |
| 9914 | } finally { |
| 9915 | Binder.restoreCallingIdentity(identity); |
| 9916 | } |
| 9917 | } |
| 9918 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9919 | } |
| 9920 | |
| 9921 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9922 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9923 | * |
| 9924 | * <p>Requires one of the following permissions: |
| 9925 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9926 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9927 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9928 | * privileges. |
| 9929 | * |
| 9930 | * @param subId subscription id |
| 9931 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9932 | * {@code false}. |
| 9933 | */ |
| 9934 | @Override |
| 9935 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9936 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9937 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9938 | try { |
| 9939 | mApp.enforceCallingOrSelfPermission( |
| 9940 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9941 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9942 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9943 | mApp.enforceCallingOrSelfPermission( |
| 9944 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9945 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9946 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9947 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9948 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9949 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9950 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9951 | boolean isEnabled = false; |
| 9952 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9953 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9954 | Phone phone = getPhone(subId); |
| 9955 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9956 | } finally { |
| 9957 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9958 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9959 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9960 | } |
| 9961 | |
| 9962 | |
| 9963 | /** |
| 9964 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9965 | * |
| 9966 | * <p> Requires permission: |
| 9967 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9968 | * privileges. |
| 9969 | * |
| 9970 | * @param subId subscription id |
| 9971 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9972 | */ |
| 9973 | @Override |
| 9974 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9976 | mApp, subId, "setDataRoamingEnabled"); |
| 9977 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9978 | final long identity = Binder.clearCallingIdentity(); |
| 9979 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9980 | Phone phone = getPhone(subId); |
| 9981 | if (phone != null) { |
| 9982 | phone.setDataRoamingEnabled(isEnabled); |
| 9983 | } |
| 9984 | } finally { |
| 9985 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9986 | } |
| 9987 | } |
| 9988 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9989 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9990 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9991 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9992 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9993 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9994 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9995 | boolean isAllowed = true; |
| 9996 | final long identity = Binder.clearCallingIdentity(); |
| 9997 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9998 | Phone phone = getPhone(subId); |
| 9999 | if (phone != null) { |
| 10000 | isAllowed = phone.isCspPlmnEnabled(); |
| 10001 | } |
| 10002 | } finally { |
| 10003 | Binder.restoreCallingIdentity(identity); |
| 10004 | } |
| 10005 | return isAllowed; |
| 10006 | } |
| 10007 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10008 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 10009 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 10010 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10011 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10012 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 10013 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 10014 | if (phone == null) { |
| 10015 | return false; |
| 10016 | } |
| 10017 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10018 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 10019 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10020 | } |
| 10021 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 10022 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 10023 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10024 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 10025 | mApp.getSystemService(AppOpsManager.class) |
| 10026 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10027 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10028 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10029 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 10030 | try { |
| 10031 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10032 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 10033 | } catch (SecurityException e) { |
| 10034 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 10035 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 10036 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10037 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10038 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 10039 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 10040 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10041 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10042 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10043 | Binder.getCallingUid())) { |
| 10044 | isIccIdAccessRestricted = true; |
| 10045 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 10046 | final long identity = Binder.clearCallingIdentity(); |
| 10047 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 10048 | UiccController uiccController = UiccController.getInstance(); |
| 10049 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10050 | if (hasReadPermission) { |
| 10051 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 10052 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10053 | |
| 10054 | // Remove private info if the caller doesn't have access |
| 10055 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 10056 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10057 | //setting the value after compatibility check |
| 10058 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10059 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 10060 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10061 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10062 | if (card == null) { |
| 10063 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10064 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10065 | continue; |
| 10066 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10067 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 10068 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10069 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10070 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10071 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10072 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 10073 | for (UiccPortInfo portInfo : portInfos) { |
| 10074 | UiccPort port = uiccController.getUiccPortForSlot( |
| 10075 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 10076 | if (port == null) { |
| 10077 | // assume no access if port is null |
| 10078 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 10079 | continue; |
| 10080 | } |
| 10081 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10082 | uiccPortInfos.add(portInfo); |
| 10083 | } else { |
| 10084 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 10085 | } |
| 10086 | } |
| 10087 | filteredInfos.add(new UiccCardInfo( |
| 10088 | cardInfo.isEuicc(), |
| 10089 | cardInfo.getCardId(), |
| 10090 | null, |
| 10091 | cardInfo.getPhysicalSlotIndex(), |
| 10092 | cardInfo.isRemovable(), |
| 10093 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 10094 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 10095 | } |
| 10096 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 10097 | } finally { |
| 10098 | Binder.restoreCallingIdentity(identity); |
| 10099 | } |
| 10100 | } |
| 10101 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10102 | /** |
| 10103 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 10104 | * generally private and require carrier privileges to view. |
| 10105 | * |
| 10106 | * @hide |
| 10107 | */ |
| 10108 | @NonNull |
| 10109 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 10110 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 10111 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 10112 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 10113 | } |
| 10114 | return new UiccCardInfo( |
| 10115 | cardInfo.isEuicc(), |
| 10116 | cardInfo.getCardId(), |
| 10117 | null, |
| 10118 | cardInfo.getPhysicalSlotIndex(), |
| 10119 | cardInfo.isRemovable(), |
| 10120 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 10121 | portinfo |
| 10122 | ); |
| 10123 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10124 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10125 | /** |
| 10126 | * @hide |
| 10127 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 10128 | * These values are generally private and require carrier privileges to view. |
| 10129 | */ |
| 10130 | @NonNull |
| 10131 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 10132 | return new UiccPortInfo( |
| 10133 | UiccPortInfo.ICCID_REDACTED, |
| 10134 | portInfo.getPortIndex(), |
| 10135 | portInfo.getLogicalSlotIndex(), |
| 10136 | portInfo.isActive() |
| 10137 | ); |
| 10138 | } |
| 10139 | @Override |
| 10140 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10141 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10142 | mApp.getSystemService(AppOpsManager.class) |
| 10143 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10144 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10145 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10146 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10147 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10148 | // we are reading iccId which is PII data. |
| 10149 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10150 | |
| 10151 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10152 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10153 | Binder.getCallingUid())) { |
| 10154 | isLogicalSlotAccessRestricted = true; |
| 10155 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10156 | final long identity = Binder.clearCallingIdentity(); |
| 10157 | try { |
| 10158 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10159 | if (slots == null || slots.length == 0) { |
| 10160 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10161 | return null; |
| 10162 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10163 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10164 | for (int i = 0; i < slots.length; i++) { |
| 10165 | UiccSlot slot = slots[i]; |
| 10166 | if (slot == null) { |
| 10167 | continue; |
| 10168 | } |
| 10169 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10170 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10171 | UiccCard card = slot.getUiccCard(); |
| 10172 | if (card != null) { |
| 10173 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10174 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10175 | cardId = slot.getEid(); |
| 10176 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10177 | // If cardId is null, use iccId of default port as cardId. |
| 10178 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10179 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10180 | } |
| 10181 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10182 | if (cardId != null) { |
| 10183 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10184 | // if cardId is an EID, it's all digits so this is fine |
| 10185 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10186 | } |
| 10187 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10188 | int cardState = 0; |
| 10189 | switch (slot.getCardState()) { |
| 10190 | case CARDSTATE_ABSENT: |
| 10191 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10192 | break; |
| 10193 | case CARDSTATE_PRESENT: |
| 10194 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10195 | break; |
| 10196 | case CARDSTATE_ERROR: |
| 10197 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10198 | break; |
| 10199 | case CARDSTATE_RESTRICTED: |
| 10200 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10201 | break; |
| 10202 | default: |
| 10203 | break; |
| 10204 | |
| 10205 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10206 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10207 | int[] portIndexes = slot.getPortList(); |
| 10208 | for (int portIdx : portIndexes) { |
| 10209 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10210 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10211 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10212 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10213 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10214 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10215 | slot.isEuicc(), |
| 10216 | cardId, |
| 10217 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10218 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10219 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10220 | //setting the value after compatibility check |
| 10221 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10222 | } |
| 10223 | return infos; |
| 10224 | } finally { |
| 10225 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10226 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10227 | } |
| 10228 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10229 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10230 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10231 | boolean hasReadPermission) { |
| 10232 | String iccId = slot.getIccId(portIndex); |
| 10233 | if (hasReadPermission) { // if has read permission |
| 10234 | return iccId; |
| 10235 | } else { |
| 10236 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10237 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10238 | // if no read permission, checking carrier privilege access |
| 10239 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10240 | return iccId; |
| 10241 | } |
| 10242 | } |
| 10243 | } |
| 10244 | // No read permission or carrier privilege access. |
| 10245 | return UiccPortInfo.ICCID_REDACTED; |
| 10246 | } |
| 10247 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10248 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10249 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10250 | public boolean switchSlots(int[] physicalSlots) { |
| 10251 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10252 | |
| 10253 | final long identity = Binder.clearCallingIdentity(); |
| 10254 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10255 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10256 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10257 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10258 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10259 | physicalSlots[i], i)); |
| 10260 | } |
| 10261 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10262 | } finally { |
| 10263 | Binder.restoreCallingIdentity(identity); |
| 10264 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10265 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10266 | |
| 10267 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10268 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10269 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10270 | enforceModifyPermission(); |
| 10271 | |
| 10272 | final long identity = Binder.clearCallingIdentity(); |
| 10273 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10274 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10275 | } finally { |
| 10276 | Binder.restoreCallingIdentity(identity); |
| 10277 | } |
| 10278 | } |
| 10279 | |
| 10280 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10281 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10282 | final long identity = Binder.clearCallingIdentity(); |
| 10283 | try { |
| 10284 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10285 | } finally { |
| 10286 | Binder.restoreCallingIdentity(identity); |
| 10287 | } |
| 10288 | } |
| 10289 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10290 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10291 | * A test API to reload the UICC profile. |
| 10292 | * |
| 10293 | * <p>Requires that the calling app has permission |
| 10294 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10295 | * @hide |
| 10296 | */ |
| 10297 | @Override |
| 10298 | public void refreshUiccProfile(int subId) { |
| 10299 | enforceModifyPermission(); |
| 10300 | |
| 10301 | final long identity = Binder.clearCallingIdentity(); |
| 10302 | try { |
| 10303 | Phone phone = getPhone(subId); |
| 10304 | if (phone == null) { |
| 10305 | return; |
| 10306 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10307 | UiccPort uiccPort = phone.getUiccPort(); |
| 10308 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10309 | return; |
| 10310 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10311 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10312 | if (uiccProfile == null) { |
| 10313 | return; |
| 10314 | } |
| 10315 | uiccProfile.refresh(); |
| 10316 | } finally { |
| 10317 | Binder.restoreCallingIdentity(identity); |
| 10318 | } |
| 10319 | } |
| 10320 | |
| 10321 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10322 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10323 | */ |
| 10324 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10325 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10326 | } |
| 10327 | |
| 10328 | /** |
| 10329 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 10330 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 10331 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 10332 | */ |
| 10333 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 10334 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10335 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 10336 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10337 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 10338 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 10339 | return isDataRoamingEnabled; |
| 10340 | } |
| 10341 | |
| 10342 | /** |
| 10343 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10344 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10345 | */ |
| 10346 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10347 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10348 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10349 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10350 | return list.get(phoneId); |
| 10351 | } |
| 10352 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10353 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10354 | |
| 10355 | @Override |
| 10356 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10357 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10358 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10359 | |
| 10360 | final long identity = Binder.clearCallingIdentity(); |
| 10361 | try { |
| 10362 | final Phone phone = getPhone(subId); |
| 10363 | if (phone == null) { |
| 10364 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10365 | return; |
| 10366 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10367 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10368 | if (cpt != null) { |
| 10369 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10370 | } |
| 10371 | // 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] | 10372 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10373 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10374 | if (carrierPrivilegeRules == null) { |
| 10375 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10376 | } else { |
| 10377 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10378 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10379 | } finally { |
| 10380 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10381 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10382 | } |
| 10383 | |
| 10384 | @Override |
| 10385 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10386 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10387 | |
| 10388 | final long identity = Binder.clearCallingIdentity(); |
| 10389 | try { |
| 10390 | final Phone phone = getPhone(subId); |
| 10391 | if (phone == null) { |
| 10392 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10393 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10394 | } |
| 10395 | return phone.getCarrierIdListVersion(); |
| 10396 | } finally { |
| 10397 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10398 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10399 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10400 | |
| 10401 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10402 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10403 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10404 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10405 | mApp, subId, callingPackage, callingFeatureId, |
| 10406 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10407 | return -1; |
| 10408 | } |
| 10409 | |
| 10410 | final long identity = Binder.clearCallingIdentity(); |
| 10411 | try { |
| 10412 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10413 | } finally { |
| 10414 | Binder.restoreCallingIdentity(identity); |
| 10415 | } |
| 10416 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10417 | |
| 10418 | @Override |
| 10419 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10420 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10421 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10422 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10423 | |
| 10424 | final long identity = Binder.clearCallingIdentity(); |
| 10425 | try { |
| 10426 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10427 | } finally { |
| 10428 | Binder.restoreCallingIdentity(identity); |
| 10429 | } |
| 10430 | } |
| 10431 | |
| 10432 | @Override |
| 10433 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10434 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10435 | mApp, subId, "setCdmaRoamingMode"); |
| 10436 | |
| 10437 | final long identity = Binder.clearCallingIdentity(); |
| 10438 | try { |
| 10439 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10440 | } finally { |
| 10441 | Binder.restoreCallingIdentity(identity); |
| 10442 | } |
| 10443 | } |
| 10444 | |
| 10445 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10446 | public int getCdmaSubscriptionMode(int subId) { |
| 10447 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10448 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10449 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10450 | |
| 10451 | final long identity = Binder.clearCallingIdentity(); |
| 10452 | try { |
| 10453 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10454 | } finally { |
| 10455 | Binder.restoreCallingIdentity(identity); |
| 10456 | } |
| 10457 | } |
| 10458 | |
| 10459 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10460 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10462 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10463 | |
| 10464 | final long identity = Binder.clearCallingIdentity(); |
| 10465 | try { |
| 10466 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10467 | } finally { |
| 10468 | Binder.restoreCallingIdentity(identity); |
| 10469 | } |
| 10470 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10471 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10472 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10473 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10474 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10475 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10476 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10477 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10478 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10479 | } |
| 10480 | final long identity = Binder.clearCallingIdentity(); |
| 10481 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10482 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10483 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10484 | if (phone.getEmergencyNumberTracker() != null |
| 10485 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10486 | emergencyNumberListInternal.put( |
| 10487 | phone.getSubId(), |
| 10488 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10489 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10490 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10491 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10492 | } finally { |
| 10493 | Binder.restoreCallingIdentity(identity); |
| 10494 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10495 | } |
| 10496 | |
| 10497 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10498 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10499 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10500 | if (!exactMatch) { |
| 10501 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10502 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10503 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10504 | } |
| 10505 | final long identity = Binder.clearCallingIdentity(); |
| 10506 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10507 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10508 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10509 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10510 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10511 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10512 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10513 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10514 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10515 | } |
| 10516 | return false; |
| 10517 | } finally { |
| 10518 | Binder.restoreCallingIdentity(identity); |
| 10519 | } |
| 10520 | } |
| 10521 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10522 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10523 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10524 | */ |
| 10525 | @Override |
| 10526 | public void startEmergencyCallbackMode() { |
| 10527 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10528 | "startEmergencyCallbackMode"); |
| 10529 | enforceModifyPermission(); |
| 10530 | final long identity = Binder.clearCallingIdentity(); |
| 10531 | try { |
| 10532 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10533 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10534 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10535 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10536 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10537 | gsmCdmaPhone.obtainMessage( |
| 10538 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10539 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10540 | } |
| 10541 | } |
| 10542 | } finally { |
| 10543 | Binder.restoreCallingIdentity(identity); |
| 10544 | } |
| 10545 | } |
| 10546 | |
| 10547 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10548 | * Update emergency number list for test mode. |
| 10549 | */ |
| 10550 | @Override |
| 10551 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10552 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10553 | "updateEmergencyNumberListTestMode"); |
| 10554 | |
| 10555 | final long identity = Binder.clearCallingIdentity(); |
| 10556 | try { |
| 10557 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10558 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10559 | if (tracker != null) { |
| 10560 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10561 | } |
| 10562 | } |
| 10563 | } finally { |
| 10564 | Binder.restoreCallingIdentity(identity); |
| 10565 | } |
| 10566 | } |
| 10567 | |
| 10568 | /** |
| 10569 | * Get the full emergency number list for test mode. |
| 10570 | */ |
| 10571 | @Override |
| 10572 | public List<String> getEmergencyNumberListTestMode() { |
| 10573 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10574 | "getEmergencyNumberListTestMode"); |
| 10575 | |
| 10576 | final long identity = Binder.clearCallingIdentity(); |
| 10577 | try { |
| 10578 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10579 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10580 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10581 | if (tracker != null) { |
| 10582 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10583 | emergencyNumbers.add(num.getNumber()); |
| 10584 | } |
| 10585 | } |
| 10586 | } |
| 10587 | return new ArrayList<>(emergencyNumbers); |
| 10588 | } finally { |
| 10589 | Binder.restoreCallingIdentity(identity); |
| 10590 | } |
| 10591 | } |
| 10592 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10593 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10594 | public int getEmergencyNumberDbVersion(int subId) { |
| 10595 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10596 | |
| 10597 | final long identity = Binder.clearCallingIdentity(); |
| 10598 | try { |
| 10599 | final Phone phone = getPhone(subId); |
| 10600 | if (phone == null) { |
| 10601 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10602 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10603 | } |
| 10604 | return phone.getEmergencyNumberDbVersion(); |
| 10605 | } finally { |
| 10606 | Binder.restoreCallingIdentity(identity); |
| 10607 | } |
| 10608 | } |
| 10609 | |
| 10610 | @Override |
| 10611 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10612 | enforceModifyPermission(); |
| 10613 | |
| 10614 | final long identity = Binder.clearCallingIdentity(); |
| 10615 | try { |
| 10616 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10617 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10618 | if (tracker != null) { |
| 10619 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10620 | } |
| 10621 | } |
| 10622 | } finally { |
| 10623 | Binder.restoreCallingIdentity(identity); |
| 10624 | } |
| 10625 | } |
| 10626 | |
| 10627 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10628 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10629 | enforceActiveEmergencySessionPermission(); |
| 10630 | |
| 10631 | final long identity = Binder.clearCallingIdentity(); |
| 10632 | try { |
| 10633 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10634 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10635 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10636 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10637 | } |
| 10638 | } |
| 10639 | } finally { |
| 10640 | Binder.restoreCallingIdentity(identity); |
| 10641 | } |
| 10642 | } |
| 10643 | |
| 10644 | @Override |
| 10645 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10646 | enforceActiveEmergencySessionPermission(); |
| 10647 | |
| 10648 | final long identity = Binder.clearCallingIdentity(); |
| 10649 | try { |
| 10650 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10651 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10652 | if (tracker != null) { |
| 10653 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10654 | } |
| 10655 | } |
| 10656 | } finally { |
| 10657 | Binder.restoreCallingIdentity(identity); |
| 10658 | } |
| 10659 | } |
| 10660 | |
| 10661 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10662 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10663 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10664 | Phone phone = getPhone(subId); |
| 10665 | if (phone == null) { |
| 10666 | return null; |
| 10667 | } |
| 10668 | final long identity = Binder.clearCallingIdentity(); |
| 10669 | try { |
| 10670 | UiccProfile profile = UiccController.getInstance() |
| 10671 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10672 | if (profile != null) { |
| 10673 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10674 | } |
| 10675 | } finally { |
| 10676 | Binder.restoreCallingIdentity(identity); |
| 10677 | } |
| 10678 | return null; |
| 10679 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10680 | |
| 10681 | /** |
| 10682 | * Enable or disable a modem stack. |
| 10683 | */ |
| 10684 | @Override |
| 10685 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10686 | enforceModifyPermission(); |
| 10687 | |
| 10688 | final long identity = Binder.clearCallingIdentity(); |
| 10689 | try { |
| 10690 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10691 | if (phone == null) { |
| 10692 | return false; |
| 10693 | } else { |
| 10694 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10695 | } |
| 10696 | } finally { |
| 10697 | Binder.restoreCallingIdentity(identity); |
| 10698 | } |
| 10699 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10700 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10701 | /** |
| 10702 | * Whether a modem stack is enabled or not. |
| 10703 | */ |
| 10704 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10705 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10706 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10707 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10708 | if (phone == null) return false; |
| 10709 | |
| 10710 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10711 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10712 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10713 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10714 | } |
| 10715 | |
| 10716 | final long identity = Binder.clearCallingIdentity(); |
| 10717 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10718 | try { |
| 10719 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10720 | } catch (NoSuchElementException ex) { |
| 10721 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10722 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10723 | } finally { |
| 10724 | Binder.restoreCallingIdentity(identity); |
| 10725 | } |
| 10726 | } |
| 10727 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10728 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10729 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10730 | enforceModifyPermission(); |
| 10731 | |
| 10732 | final long identity = Binder.clearCallingIdentity(); |
| 10733 | try { |
| 10734 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10735 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10736 | .commit(); |
| 10737 | } finally { |
| 10738 | Binder.restoreCallingIdentity(identity); |
| 10739 | } |
| 10740 | } |
| 10741 | |
| 10742 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10743 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10744 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10745 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10746 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10747 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10748 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10749 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10750 | |
| 10751 | final long identity = Binder.clearCallingIdentity(); |
| 10752 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10753 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10754 | } finally { |
| 10755 | Binder.restoreCallingIdentity(identity); |
| 10756 | } |
| 10757 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10758 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10759 | @TelephonyManager.IsMultiSimSupportedResult |
| 10760 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10761 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10762 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10763 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10764 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10765 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10766 | } |
| 10767 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10768 | // supported by the modem, indicate that it is restricted. |
| 10769 | PhoneCapability staticCapability = |
| 10770 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10771 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10772 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10773 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10774 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10775 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10776 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10777 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10778 | } |
| 10779 | // Check if support of multiple SIMs is restricted by carrier |
| 10780 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10781 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10782 | } |
| 10783 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10784 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10785 | } |
| 10786 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10787 | /** |
| 10788 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10789 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10790 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10791 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10792 | * @param numOfSims number of active sims we want to switch to |
| 10793 | */ |
| 10794 | @Override |
| 10795 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10796 | if (numOfSims == 1) { |
| 10797 | enforceModifyPermission(); |
| 10798 | } else { |
| 10799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10800 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10801 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10802 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10803 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10804 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10805 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10806 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10807 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10808 | return; |
| 10809 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10810 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10811 | } finally { |
| 10812 | Binder.restoreCallingIdentity(identity); |
| 10813 | } |
| 10814 | } |
| 10815 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10816 | @Override |
| 10817 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10818 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10819 | Phone phone = getPhone(subId); |
| 10820 | if (phone == null) { |
| 10821 | return false; |
| 10822 | } |
| 10823 | final long identity = Binder.clearCallingIdentity(); |
| 10824 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10825 | UiccPort uiccPort = phone.getUiccPort(); |
| 10826 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10827 | return false; |
| 10828 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10829 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10830 | if (uiccProfile == null) { |
| 10831 | return false; |
| 10832 | } |
| 10833 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10834 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10835 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10836 | } |
| 10837 | return false; |
| 10838 | } finally { |
| 10839 | Binder.restoreCallingIdentity(identity); |
| 10840 | } |
| 10841 | } |
| 10842 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10843 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10844 | * Get whether making changes to modem configurations will trigger reboot. |
| 10845 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10846 | */ |
| 10847 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10848 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10849 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10850 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10851 | mApp, subId, callingPackage, callingFeatureId, |
| 10852 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10853 | return false; |
| 10854 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10855 | final long identity = Binder.clearCallingIdentity(); |
| 10856 | try { |
| 10857 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10858 | } finally { |
| 10859 | Binder.restoreCallingIdentity(identity); |
| 10860 | } |
| 10861 | } |
| 10862 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10863 | private void updateModemStateMetrics() { |
| 10864 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10865 | // TODO: check the state for each modem if the api is ready. |
| 10866 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10867 | } |
| 10868 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10869 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10870 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10871 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10872 | // Verify that the callingPackage belongs to the calling UID |
| 10873 | mApp.getSystemService(AppOpsManager.class) |
| 10874 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10875 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10876 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10877 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10878 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10879 | if (slotInfos != null) { |
| 10880 | for (int i = 0; i < slotInfos.length; i++) { |
| 10881 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10882 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10883 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10884 | portInfo.getLogicalSlotIndex())); |
| 10885 | } |
| 10886 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10887 | } |
| 10888 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10889 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10890 | } finally { |
| 10891 | Binder.restoreCallingIdentity(identity); |
| 10892 | } |
| 10893 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10894 | |
| 10895 | /** |
| 10896 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10897 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10898 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10899 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10900 | @Override |
| 10901 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10902 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10903 | } |
| 10904 | |
| 10905 | /** |
| 10906 | * Get the HAL Version of a specific service |
| 10907 | */ |
| 10908 | @Override |
| 10909 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10910 | Phone phone = getDefaultPhone(); |
| 10911 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10912 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10913 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10914 | return hv.major * 100 + hv.minor; |
| 10915 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10916 | |
| 10917 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10918 | * Get the current calling package name. |
| 10919 | * @return the current calling package name |
| 10920 | */ |
| 10921 | @Override |
| 10922 | public String getCurrentPackageName() { |
| 10923 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10924 | } |
| 10925 | |
| 10926 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10927 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10928 | * corresponding network requests on a subId. |
| 10929 | * |
| 10930 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10931 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10932 | * 2) APN is un-metered for this subscription, or |
| 10933 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10934 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10935 | * |
| 10936 | * @return whether data is allowed for a apn type. |
| 10937 | * |
| 10938 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10939 | */ |
| 10940 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10941 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10942 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10943 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10944 | |
| 10945 | // Now that all security checks passes, perform the operation as ourselves. |
| 10946 | final long identity = Binder.clearCallingIdentity(); |
| 10947 | try { |
| 10948 | Phone phone = getPhone(subId); |
| 10949 | if (phone == null) return false; |
| 10950 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10951 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10952 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10953 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10954 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10955 | phone.getServiceState().getDataRoaming()); |
| 10956 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10957 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10958 | } finally { |
| 10959 | Binder.restoreCallingIdentity(identity); |
| 10960 | } |
| 10961 | } |
| 10962 | |
| 10963 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10964 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10965 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10966 | |
| 10967 | // Now that all security checks passes, perform the operation as ourselves. |
| 10968 | final long identity = Binder.clearCallingIdentity(); |
| 10969 | try { |
| 10970 | Phone phone = getPhone(subId); |
| 10971 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10972 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10973 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10974 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10975 | } finally { |
| 10976 | Binder.restoreCallingIdentity(identity); |
| 10977 | } |
| 10978 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10979 | |
| 10980 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10981 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10982 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10983 | enforceModifyPermission(); |
| 10984 | long token = Binder.clearCallingIdentity(); |
| 10985 | try { |
| 10986 | Phone phone = getPhone(subscriptionId); |
| 10987 | if (phone == null) { |
| 10988 | try { |
| 10989 | if (resultCallback != null) { |
| 10990 | resultCallback.accept(false); |
| 10991 | } |
| 10992 | } catch (RemoteException e) { |
| 10993 | // ignore |
| 10994 | } |
| 10995 | return; |
| 10996 | } |
| 10997 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10998 | Pair.create(specifiers, (x) -> { |
| 10999 | try { |
| 11000 | if (resultCallback != null) { |
| 11001 | resultCallback.accept(x); |
| 11002 | } |
| 11003 | } catch (RemoteException e) { |
| 11004 | // ignore |
| 11005 | } |
| 11006 | }); |
| 11007 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 11008 | } finally { |
| 11009 | Binder.restoreCallingIdentity(token); |
| 11010 | } |
| 11011 | } |
| 11012 | |
| 11013 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11014 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 11015 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 11016 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11017 | mApp, subId, "getSystemSelectionChannels"); |
| 11018 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11019 | final long identity = Binder.clearCallingIdentity(); |
| 11020 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 11021 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 11022 | if (result instanceof IllegalStateException) { |
| 11023 | throw (IllegalStateException) result; |
| 11024 | } |
| 11025 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11026 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 11027 | return specifiers; |
| 11028 | } finally { |
| 11029 | Binder.restoreCallingIdentity(identity); |
| 11030 | } |
| 11031 | } |
| 11032 | |
| 11033 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11034 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11035 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11036 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11037 | } |
| 11038 | |
| 11039 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11040 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11041 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11042 | if (callingPackage == null) { |
| 11043 | callingPackage = getCurrentPackageName(); |
| 11044 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11045 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11046 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11047 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11048 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11049 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11050 | } |
| 11051 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11052 | Intent intent = new Intent(); |
| 11053 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11054 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11055 | // Bring up choose default SMS subscription dialog right now |
| 11056 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11057 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 11058 | mApp.startActivity(intent); |
| 11059 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11060 | |
| 11061 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11062 | public void showSwitchToManagedProfileDialog() { |
| 11063 | enforceModifyPermission(); |
| 11064 | |
| 11065 | Intent intent = new Intent(); |
| 11066 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11067 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11068 | mApp.startActivity(intent); |
| 11069 | } |
| 11070 | |
| 11071 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11072 | public String getMmsUAProfUrl(int subId) { |
| 11073 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11074 | final long identity = Binder.clearCallingIdentity(); |
| 11075 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11076 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11077 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11078 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11079 | return carrierUAProfUrl; |
| 11080 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11081 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11082 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11083 | } finally { |
| 11084 | Binder.restoreCallingIdentity(identity); |
| 11085 | } |
| 11086 | } |
| 11087 | |
| 11088 | @Override |
| 11089 | public String getMmsUserAgent(int subId) { |
| 11090 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11091 | final long identity = Binder.clearCallingIdentity(); |
| 11092 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11093 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11094 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11095 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11096 | return carrierUserAgent; |
| 11097 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11098 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11099 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11100 | } finally { |
| 11101 | Binder.restoreCallingIdentity(identity); |
| 11102 | } |
| 11103 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11104 | |
| 11105 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11106 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11107 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11108 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11109 | final long identity = Binder.clearCallingIdentity(); |
| 11110 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11111 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11112 | if (phone == null) return false; |
| 11113 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11114 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11115 | } finally { |
| 11116 | Binder.restoreCallingIdentity(identity); |
| 11117 | } |
| 11118 | } |
| 11119 | |
| 11120 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11121 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11122 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11123 | enforceModifyPermission(); |
| 11124 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11125 | final long identity = Binder.clearCallingIdentity(); |
| 11126 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11127 | Phone phone = getPhone(subscriptionId); |
| 11128 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11129 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11130 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11131 | } finally { |
| 11132 | Binder.restoreCallingIdentity(identity); |
| 11133 | } |
| 11134 | } |
| 11135 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11136 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11137 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11138 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11139 | * otherwise. |
| 11140 | */ |
| 11141 | @Override |
| 11142 | public void setCepEnabled(boolean isCepEnabled) { |
| 11143 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11144 | |
| 11145 | final long identity = Binder.clearCallingIdentity(); |
| 11146 | try { |
| 11147 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11148 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11149 | Phone defaultPhone = phone.getImsPhone(); |
| 11150 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11151 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11152 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11153 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11154 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11155 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11156 | + imsPhone.getMsisdn()); |
| 11157 | } |
| 11158 | } |
| 11159 | } finally { |
| 11160 | Binder.restoreCallingIdentity(identity); |
| 11161 | } |
| 11162 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11163 | |
| 11164 | /** |
| 11165 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11166 | * |
| 11167 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11168 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11169 | * before being read. |
| 11170 | */ |
| 11171 | @Override |
| 11172 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11173 | isCompressed) { |
| 11174 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11175 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11176 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11177 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11178 | } |
| 11179 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11180 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11181 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11182 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11183 | } |
| 11184 | |
| 11185 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11186 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11187 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11188 | } finally { |
| 11189 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11190 | } |
| 11191 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11192 | |
| 11193 | @Override |
| 11194 | public boolean isIccLockEnabled(int subId) { |
| 11195 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11196 | |
| 11197 | // Now that all security checks passes, perform the operation as ourselves. |
| 11198 | final long identity = Binder.clearCallingIdentity(); |
| 11199 | try { |
| 11200 | Phone phone = getPhone(subId); |
| 11201 | if (phone != null && phone.getIccCard() != null) { |
| 11202 | return phone.getIccCard().getIccLockEnabled(); |
| 11203 | } else { |
| 11204 | return false; |
| 11205 | } |
| 11206 | } finally { |
| 11207 | Binder.restoreCallingIdentity(identity); |
| 11208 | } |
| 11209 | } |
| 11210 | |
| 11211 | /** |
| 11212 | * Set the ICC pin lock enabled or disabled. |
| 11213 | * |
| 11214 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11215 | * three cases: |
| 11216 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11217 | * successfully. |
| 11218 | * - Positive number and zero for remaining password attempts. |
| 11219 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11220 | * |
| 11221 | */ |
| 11222 | @Override |
| 11223 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11224 | enforceModifyPermission(); |
| 11225 | |
| 11226 | Phone phone = getPhone(subId); |
| 11227 | if (phone == null) { |
| 11228 | return 0; |
| 11229 | } |
| 11230 | // Now that all security checks passes, perform the operation as ourselves. |
| 11231 | final long identity = Binder.clearCallingIdentity(); |
| 11232 | try { |
| 11233 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11234 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11235 | return attemptsRemaining; |
| 11236 | |
| 11237 | } catch (Exception e) { |
| 11238 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11239 | } finally { |
| 11240 | Binder.restoreCallingIdentity(identity); |
| 11241 | } |
| 11242 | return 0; |
| 11243 | } |
| 11244 | |
| 11245 | /** |
| 11246 | * Change the ICC password used in ICC pin lock. |
| 11247 | * |
| 11248 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11249 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11250 | * - Positive number and zero for remaining password attempts. |
| 11251 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11252 | * |
| 11253 | */ |
| 11254 | @Override |
| 11255 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11256 | enforceModifyPermission(); |
| 11257 | |
| 11258 | Phone phone = getPhone(subId); |
| 11259 | if (phone == null) { |
| 11260 | return 0; |
| 11261 | } |
| 11262 | // Now that all security checks passes, perform the operation as ourselves. |
| 11263 | final long identity = Binder.clearCallingIdentity(); |
| 11264 | try { |
| 11265 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11266 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11267 | return attemptsRemaining; |
| 11268 | |
| 11269 | } catch (Exception e) { |
| 11270 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11271 | } finally { |
| 11272 | Binder.restoreCallingIdentity(identity); |
| 11273 | } |
| 11274 | return 0; |
| 11275 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11276 | |
| 11277 | /** |
| 11278 | * Request for receiving user activity notification |
| 11279 | */ |
| 11280 | @Override |
| 11281 | public void requestUserActivityNotification() { |
| 11282 | if (!mNotifyUserActivity.get() |
| 11283 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11284 | mNotifyUserActivity.set(true); |
| 11285 | } |
| 11286 | } |
| 11287 | |
| 11288 | /** |
| 11289 | * Called when userActivity is signalled in the power manager. |
| 11290 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11291 | */ |
| 11292 | @Override |
| 11293 | public void userActivity() { |
| 11294 | // *************************************** |
| 11295 | // * Inherited from PhoneWindowManager * |
| 11296 | // *************************************** |
| 11297 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11298 | // WITH ITS LOCKS HELD. |
| 11299 | // |
| 11300 | // This code must be VERY careful about the locks |
| 11301 | // it acquires. |
| 11302 | // In fact, the current code acquires way too many, |
| 11303 | // and probably has lurking deadlocks. |
| 11304 | |
| 11305 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11306 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11307 | } |
| 11308 | |
| 11309 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11310 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11311 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11312 | } |
| 11313 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11314 | |
| 11315 | @Override |
| 11316 | public boolean canConnectTo5GInDsdsMode() { |
| 11317 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11318 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11319 | |
| 11320 | @Override |
| 11321 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11322 | String callingFeatureId) { |
| 11323 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11324 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11325 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11326 | } |
| 11327 | |
| 11328 | Phone phone = getPhone(subId); |
| 11329 | if (phone == null) { |
| 11330 | throw new RuntimeException("phone is not available"); |
| 11331 | } |
| 11332 | // Now that all security checks passes, perform the operation as ourselves. |
| 11333 | final long identity = Binder.clearCallingIdentity(); |
| 11334 | try { |
| 11335 | return phone.getEquivalentHomePlmns(); |
| 11336 | } finally { |
| 11337 | Binder.restoreCallingIdentity(identity); |
| 11338 | } |
| 11339 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11340 | |
| 11341 | @Override |
| 11342 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11343 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 11344 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11345 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11346 | if (radioInterfaceCapabilities == null) { |
| 11347 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11348 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11349 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11350 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11351 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11352 | @Override |
| 11353 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11354 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11355 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11356 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11357 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11358 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11359 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11360 | if (DBG) { |
| 11361 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11362 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11363 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11364 | } |
| 11365 | |
| 11366 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11367 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11368 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11369 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11370 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11371 | if (callback != null) { |
| 11372 | try { |
| 11373 | callback.onAuthenticationFailure( |
| 11374 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11375 | } catch (RemoteException exception) { |
| 11376 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11377 | } |
| 11378 | return; |
| 11379 | } |
| 11380 | } |
| 11381 | |
| 11382 | final long token = Binder.clearCallingIdentity(); |
| 11383 | try { |
| 11384 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11385 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11386 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11387 | } finally { |
| 11388 | Binder.restoreCallingIdentity(token); |
| 11389 | } |
| 11390 | } |
| 11391 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11392 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11393 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11394 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11395 | * requested radio power state will actually be set. See {@link |
| 11396 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11397 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11398 | * @param enable {@code true} if trying to turn radio on. |
| 11399 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11400 | * false}. |
| 11401 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11402 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11403 | boolean isPhoneAvailable = false; |
| 11404 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11405 | Phone phone = PhoneFactory.getPhone(i); |
| 11406 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11407 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11408 | isPhoneAvailable = true; |
| 11409 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11410 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11411 | |
| 11412 | // return true if successfully informed the phone object about the thermal radio power |
| 11413 | // request. |
| 11414 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11415 | } |
| 11416 | |
| 11417 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11418 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11419 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11420 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11421 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11422 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11423 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11424 | } |
| 11425 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11426 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11427 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11428 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11429 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11430 | } |
| 11431 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11432 | setDataEnabledForReason( |
| 11433 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11434 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11435 | if (isDataThrottlingSupported) { |
| 11436 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11437 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11438 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11439 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11440 | } else if (thermalMitigationResult |
| 11441 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11442 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11443 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11444 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11445 | } |
| 11446 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11447 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11448 | |
| 11449 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11450 | } |
| 11451 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11452 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11453 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11454 | for (String pckg : context.getResources() |
| 11455 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11456 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11457 | } |
| 11458 | } |
| 11459 | |
| 11460 | return sThermalMitigationAllowlistedPackages; |
| 11461 | } |
| 11462 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11463 | private boolean isAnyPhoneInEmergencyState() { |
| 11464 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11465 | if (tm.isInEmergencyCall()) { |
| 11466 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11467 | return true; |
| 11468 | } |
| 11469 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11470 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11471 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11472 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11473 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11474 | return true; |
| 11475 | } |
| 11476 | } |
| 11477 | |
| 11478 | return false; |
| 11479 | } |
| 11480 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11481 | /** |
| 11482 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11483 | * @param packageName name of package to be allowlisted |
| 11484 | * @param context |
| 11485 | */ |
| 11486 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11487 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11488 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11489 | } |
| 11490 | |
| 11491 | /** |
| 11492 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11493 | * @param packageName name of package to remove from allowlist |
| 11494 | * @param context |
| 11495 | */ |
| 11496 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11497 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11498 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11499 | } |
| 11500 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11501 | /** |
| 11502 | * Thermal mitigation request to control functionalities at modem. |
| 11503 | * |
| 11504 | * @param subId the id of the subscription. |
| 11505 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11506 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11507 | * |
| 11508 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11509 | */ |
| 11510 | @Override |
| 11511 | @ThermalMitigationResult |
| 11512 | public int sendThermalMitigationRequest( |
| 11513 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11514 | ThermalMitigationRequest thermalMitigationRequest, |
| 11515 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11516 | enforceModifyPermission(); |
| 11517 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11518 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11519 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11520 | .contains(callingPackage)) { |
| 11521 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11522 | + "calling package: " + callingPackage); |
| 11523 | } |
| 11524 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11525 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11526 | final long identity = Binder.clearCallingIdentity(); |
| 11527 | |
| 11528 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11529 | try { |
| 11530 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11531 | switch (thermalMitigationAction) { |
| 11532 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11533 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11534 | handleDataThrottlingRequest(subId, |
| 11535 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11536 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11537 | break; |
| 11538 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11539 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11540 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11541 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11542 | } |
| 11543 | |
| 11544 | // Ensure that radio is on. If not able to power on due to phone being |
| 11545 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11546 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11547 | thermalMitigationResult = |
| 11548 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11549 | break; |
| 11550 | } |
| 11551 | |
| 11552 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11553 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11554 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11555 | break; |
| 11556 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11557 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11558 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11559 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11560 | } |
| 11561 | |
| 11562 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11563 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11564 | Phone phone = getPhone(subId); |
| 11565 | if (phone == null) { |
| 11566 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11567 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11568 | break; |
| 11569 | } |
| 11570 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11571 | TelephonyConnectionService service = |
| 11572 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11573 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11574 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11575 | thermalMitigationResult = |
| 11576 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11577 | break; |
| 11578 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11579 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11580 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11581 | break; |
| 11582 | } |
| 11583 | } else { |
| 11584 | thermalMitigationResult = |
| 11585 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11586 | break; |
| 11587 | } |
| 11588 | |
| 11589 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11590 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11591 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11592 | thermalMitigationResult = |
| 11593 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11594 | break; |
| 11595 | } |
| 11596 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11597 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11598 | break; |
| 11599 | default: |
| 11600 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11601 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11602 | } |
| 11603 | } catch (IllegalArgumentException e) { |
| 11604 | throw e; |
| 11605 | } catch (Exception e) { |
| 11606 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11607 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11608 | } finally { |
| 11609 | Binder.restoreCallingIdentity(identity); |
| 11610 | } |
| 11611 | |
| 11612 | if (DBG) { |
| 11613 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11614 | + thermalMitigationResult); |
| 11615 | } |
| 11616 | |
| 11617 | return thermalMitigationResult; |
| 11618 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11619 | |
| 11620 | /** |
| 11621 | * Set the GbaService Package Name that Telephony will bind to. |
| 11622 | * |
| 11623 | * @param subId The sim that the GbaService is associated with. |
| 11624 | * @param packageName The name of the package to be replaced with. |
| 11625 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11626 | */ |
| 11627 | @Override |
| 11628 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11629 | enforceModifyPermission(); |
| 11630 | |
| 11631 | final long identity = Binder.clearCallingIdentity(); |
| 11632 | try { |
| 11633 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11634 | } finally { |
| 11635 | Binder.restoreCallingIdentity(identity); |
| 11636 | } |
| 11637 | } |
| 11638 | |
| 11639 | /** |
| 11640 | * Return the package name of the currently bound GbaService. |
| 11641 | * |
| 11642 | * @param subId The sim that the GbaService is associated with. |
| 11643 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11644 | */ |
| 11645 | @Override |
| 11646 | public String getBoundGbaService(int subId) { |
| 11647 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11648 | |
| 11649 | final long identity = Binder.clearCallingIdentity(); |
| 11650 | try { |
| 11651 | return getGbaManager(subId).getServicePackage(); |
| 11652 | } finally { |
| 11653 | Binder.restoreCallingIdentity(identity); |
| 11654 | } |
| 11655 | } |
| 11656 | |
| 11657 | /** |
| 11658 | * Set the release time for telephony to unbind GbaService. |
| 11659 | * |
| 11660 | * @param subId The sim that the GbaService is associated with. |
| 11661 | * @param interval The release time to unbind GbaService by millisecond. |
| 11662 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11663 | */ |
| 11664 | @Override |
| 11665 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11666 | enforceModifyPermission(); |
| 11667 | |
| 11668 | final long identity = Binder.clearCallingIdentity(); |
| 11669 | try { |
| 11670 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11671 | } finally { |
| 11672 | Binder.restoreCallingIdentity(identity); |
| 11673 | } |
| 11674 | } |
| 11675 | |
| 11676 | /** |
| 11677 | * Return the release time for telephony to unbind GbaService. |
| 11678 | * |
| 11679 | * @param subId The sim that the GbaService is associated with. |
| 11680 | * @return The release time to unbind GbaService by millisecond. |
| 11681 | */ |
| 11682 | @Override |
| 11683 | public int getGbaReleaseTime(int subId) { |
| 11684 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11685 | |
| 11686 | final long identity = Binder.clearCallingIdentity(); |
| 11687 | try { |
| 11688 | return getGbaManager(subId).getReleaseTime(); |
| 11689 | } finally { |
| 11690 | Binder.restoreCallingIdentity(identity); |
| 11691 | } |
| 11692 | } |
| 11693 | |
| 11694 | private GbaManager getGbaManager(int subId) { |
| 11695 | GbaManager instance = GbaManager.getInstance(subId); |
| 11696 | if (instance == null) { |
| 11697 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11698 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11699 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11700 | } |
| 11701 | return instance; |
| 11702 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11703 | |
| 11704 | /** |
| 11705 | * indicate whether the device and the carrier can support |
| 11706 | * RCS VoLTE single registration. |
| 11707 | */ |
| 11708 | @Override |
| 11709 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11710 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11711 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11712 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11713 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11714 | |
| 11715 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11716 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11717 | } |
| 11718 | |
| 11719 | final long identity = Binder.clearCallingIdentity(); |
| 11720 | try { |
| 11721 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11722 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11723 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11724 | if (isCapable != null) { |
| 11725 | return isCapable; |
| 11726 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11727 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11728 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11729 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11730 | } finally { |
| 11731 | Binder.restoreCallingIdentity(identity); |
| 11732 | } |
| 11733 | } |
| 11734 | |
| 11735 | /** |
| 11736 | * Register RCS provisioning callback. |
| 11737 | */ |
| 11738 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11739 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11740 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11741 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11742 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11743 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11744 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11745 | |
| 11746 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11747 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11748 | } |
| 11749 | if (!isImsAvailableOnDevice()) { |
| 11750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11751 | "IMS not available on device."); |
| 11752 | } |
| 11753 | |
| 11754 | final long identity = Binder.clearCallingIdentity(); |
| 11755 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11756 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11757 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11758 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11759 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11760 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11761 | } finally { |
| 11762 | Binder.restoreCallingIdentity(identity); |
| 11763 | } |
| 11764 | } |
| 11765 | |
| 11766 | /** |
| 11767 | * Unregister RCS provisioning callback. |
| 11768 | */ |
| 11769 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11770 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11771 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11772 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11773 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11774 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11775 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11776 | |
| 11777 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11778 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11779 | } |
| 11780 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11781 | // operation failed silently |
| 11782 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11783 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11784 | } |
| 11785 | |
| 11786 | final long identity = Binder.clearCallingIdentity(); |
| 11787 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11788 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11789 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11790 | } finally { |
| 11791 | Binder.restoreCallingIdentity(identity); |
| 11792 | } |
| 11793 | } |
| 11794 | |
| 11795 | /** |
| 11796 | * trigger RCS reconfiguration. |
| 11797 | */ |
| 11798 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11799 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11800 | "triggerRcsReconfiguration", |
| 11801 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11802 | |
| 11803 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11804 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11805 | } |
| 11806 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11807 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11808 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11809 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11810 | } |
| 11811 | |
| 11812 | final long identity = Binder.clearCallingIdentity(); |
| 11813 | try { |
| 11814 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11815 | } finally { |
| 11816 | Binder.restoreCallingIdentity(identity); |
| 11817 | } |
| 11818 | } |
| 11819 | |
| 11820 | /** |
| 11821 | * Provide the client configuration parameters of the RCS application. |
| 11822 | */ |
| 11823 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11824 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11825 | "setRcsClientConfiguration", |
| 11826 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11827 | |
| 11828 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11829 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11830 | } |
| 11831 | if (!isImsAvailableOnDevice()) { |
| 11832 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11833 | "IMS not available on device."); |
| 11834 | } |
| 11835 | |
| 11836 | final long identity = Binder.clearCallingIdentity(); |
| 11837 | |
| 11838 | try { |
| 11839 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11840 | if (configBinder == null) { |
| 11841 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11842 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11843 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11844 | } else { |
| 11845 | configBinder.setRcsClientConfiguration(rcc); |
| 11846 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11847 | |
| 11848 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11849 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11850 | } catch (RemoteException e) { |
| 11851 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11852 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11853 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11854 | } finally { |
| 11855 | Binder.restoreCallingIdentity(identity); |
| 11856 | } |
| 11857 | } |
| 11858 | |
| 11859 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11860 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11861 | */ |
| 11862 | @Override |
| 11863 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11864 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11865 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11866 | |
| 11867 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11868 | } |
| 11869 | |
| 11870 | /** |
| 11871 | * Gets the test mode for RCS VoLTE single registration. |
| 11872 | */ |
| 11873 | @Override |
| 11874 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11875 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11876 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11877 | |
| 11878 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11879 | } |
| 11880 | |
| 11881 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11882 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11883 | */ |
| 11884 | @Override |
| 11885 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11886 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11887 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11888 | enforceModifyPermission(); |
| 11889 | |
| 11890 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11891 | : Boolean.parseBoolean(enabledStr); |
| 11892 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11893 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11894 | } |
| 11895 | |
| 11896 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11897 | * Sends a device to device communication message. Only usable via shell. |
| 11898 | * @param message message to send. |
| 11899 | * @param value message value. |
| 11900 | */ |
| 11901 | @Override |
| 11902 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11903 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11904 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11905 | enforceModifyPermission(); |
| 11906 | |
| 11907 | final long identity = Binder.clearCallingIdentity(); |
| 11908 | try { |
| 11909 | TelephonyConnectionService service = |
| 11910 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11911 | if (service == null) { |
| 11912 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11913 | return; |
| 11914 | } |
| 11915 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11916 | } finally { |
| 11917 | Binder.restoreCallingIdentity(identity); |
| 11918 | } |
| 11919 | } |
| 11920 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11921 | /** |
| 11922 | * Sets the specified device to device transport active. |
| 11923 | * @param transport The transport to set active. |
| 11924 | */ |
| 11925 | @Override |
| 11926 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11927 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11928 | "setActiveDeviceToDeviceTransport"); |
| 11929 | enforceModifyPermission(); |
| 11930 | |
| 11931 | final long identity = Binder.clearCallingIdentity(); |
| 11932 | try { |
| 11933 | TelephonyConnectionService service = |
| 11934 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11935 | if (service == null) { |
| 11936 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11937 | return; |
| 11938 | } |
| 11939 | service.setActiveDeviceToDeviceTransport(transport); |
| 11940 | } finally { |
| 11941 | Binder.restoreCallingIdentity(identity); |
| 11942 | } |
| 11943 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11944 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11945 | @Override |
| 11946 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11947 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11948 | "setDeviceToDeviceForceEnabled"); |
| 11949 | |
| 11950 | final long identity = Binder.clearCallingIdentity(); |
| 11951 | try { |
| 11952 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11953 | p -> { |
| 11954 | Phone thePhone = p.getImsPhone(); |
| 11955 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11956 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11957 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11958 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11959 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11960 | (ImsPhoneCallTracker) tracker; |
| 11961 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11962 | } |
| 11963 | } |
| 11964 | } |
| 11965 | ); |
| 11966 | } finally { |
| 11967 | Binder.restoreCallingIdentity(identity); |
| 11968 | } |
| 11969 | } |
| 11970 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11971 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11972 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11973 | */ |
| 11974 | @Override |
| 11975 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11976 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11977 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11978 | } |
| 11979 | |
| 11980 | /** |
| 11981 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11982 | */ |
| 11983 | @Override |
| 11984 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11985 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11986 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11987 | enforceModifyPermission(); |
| 11988 | |
| 11989 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11990 | : Boolean.parseBoolean(enabledStr); |
| 11991 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11992 | subId, enabled); |
| 11993 | } |
| 11994 | |
| 11995 | /** |
| 11996 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11997 | */ |
| 11998 | @Override |
| 11999 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12000 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12001 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12002 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12003 | |
| 12004 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12005 | * Overrides the ims feature validation result |
| 12006 | */ |
| 12007 | @Override |
| 12008 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12009 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12010 | "setImsFeatureValidationOverride"); |
| 12011 | |
| 12012 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12013 | : Boolean.parseBoolean(enabledStr); |
| 12014 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12015 | subId, enabled); |
| 12016 | } |
| 12017 | |
| 12018 | /** |
| 12019 | * Gets the ims feature validation override value |
| 12020 | */ |
| 12021 | @Override |
| 12022 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12023 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12024 | "getImsFeatureValidationOverride"); |
| 12025 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12026 | } |
| 12027 | |
| 12028 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12029 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12030 | * their mobile plan. |
| 12031 | */ |
| 12032 | @Override |
| 12033 | public String getMobileProvisioningUrl() { |
| 12034 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12035 | final long identity = Binder.clearCallingIdentity(); |
| 12036 | try { |
| 12037 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12038 | } finally { |
| 12039 | Binder.restoreCallingIdentity(identity); |
| 12040 | } |
| 12041 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12042 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12043 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12044 | * Get the EAB contact from the EAB database. |
| 12045 | */ |
| 12046 | @Override |
| 12047 | public String getContactFromEab(String contact) { |
| 12048 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12049 | enforceModifyPermission(); |
| 12050 | final long identity = Binder.clearCallingIdentity(); |
| 12051 | try { |
| 12052 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12053 | } finally { |
| 12054 | Binder.restoreCallingIdentity(identity); |
| 12055 | } |
| 12056 | } |
| 12057 | |
| 12058 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12059 | * Get the EAB capability from the EAB database. |
| 12060 | */ |
| 12061 | @Override |
| 12062 | public String getCapabilityFromEab(String contact) { |
| 12063 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12064 | enforceModifyPermission(); |
| 12065 | final long identity = Binder.clearCallingIdentity(); |
| 12066 | try { |
| 12067 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12068 | } finally { |
| 12069 | Binder.restoreCallingIdentity(identity); |
| 12070 | } |
| 12071 | } |
| 12072 | |
| 12073 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12074 | * Remove the EAB contacts from the EAB database. |
| 12075 | */ |
| 12076 | @Override |
| 12077 | public int removeContactFromEab(int subId, String contacts) { |
| 12078 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12079 | enforceModifyPermission(); |
| 12080 | final long identity = Binder.clearCallingIdentity(); |
| 12081 | try { |
| 12082 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12083 | } finally { |
| 12084 | Binder.restoreCallingIdentity(identity); |
| 12085 | } |
| 12086 | } |
| 12087 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12088 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12089 | public boolean getDeviceUceEnabled() { |
| 12090 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12091 | final long identity = Binder.clearCallingIdentity(); |
| 12092 | try { |
| 12093 | return mApp.getDeviceUceEnabled(); |
| 12094 | } finally { |
| 12095 | Binder.restoreCallingIdentity(identity); |
| 12096 | } |
| 12097 | } |
| 12098 | |
| 12099 | @Override |
| 12100 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12101 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12102 | final long identity = Binder.clearCallingIdentity(); |
| 12103 | try { |
| 12104 | mApp.setDeviceUceEnabled(isEnabled); |
| 12105 | } finally { |
| 12106 | Binder.restoreCallingIdentity(identity); |
| 12107 | } |
| 12108 | } |
| 12109 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12110 | /** |
| 12111 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12112 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12113 | */ |
| 12114 | // Used for SHELL command only right now. |
| 12115 | @Override |
| 12116 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12117 | List<String> featureTags) { |
| 12118 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12119 | "addUceRegistrationOverrideShell"); |
| 12120 | final long identity = Binder.clearCallingIdentity(); |
| 12121 | try { |
| 12122 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12123 | new ArraySet<>(featureTags)); |
| 12124 | } catch (ImsException e) { |
| 12125 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12126 | } finally { |
| 12127 | Binder.restoreCallingIdentity(identity); |
| 12128 | } |
| 12129 | } |
| 12130 | |
| 12131 | /** |
| 12132 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12133 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12134 | */ |
| 12135 | // Used for SHELL command only right now. |
| 12136 | @Override |
| 12137 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12138 | List<String> featureTags) { |
| 12139 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12140 | "removeUceRegistrationOverrideShell"); |
| 12141 | final long identity = Binder.clearCallingIdentity(); |
| 12142 | try { |
| 12143 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12144 | new ArraySet<>(featureTags)); |
| 12145 | } catch (ImsException e) { |
| 12146 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12147 | } finally { |
| 12148 | Binder.restoreCallingIdentity(identity); |
| 12149 | } |
| 12150 | } |
| 12151 | |
| 12152 | /** |
| 12153 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12154 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12155 | */ |
| 12156 | // Used for SHELL command only right now. |
| 12157 | @Override |
| 12158 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12159 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12160 | "clearUceRegistrationOverrideShell"); |
| 12161 | final long identity = Binder.clearCallingIdentity(); |
| 12162 | try { |
| 12163 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12164 | } catch (ImsException e) { |
| 12165 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12166 | } finally { |
| 12167 | Binder.restoreCallingIdentity(identity); |
| 12168 | } |
| 12169 | } |
| 12170 | |
| 12171 | /** |
| 12172 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12173 | */ |
| 12174 | // Used for SHELL command only right now. |
| 12175 | @Override |
| 12176 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12177 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12178 | "getLatestRcsContactUceCapabilityShell"); |
| 12179 | final long identity = Binder.clearCallingIdentity(); |
| 12180 | try { |
| 12181 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12182 | } catch (ImsException e) { |
| 12183 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12184 | } finally { |
| 12185 | Binder.restoreCallingIdentity(identity); |
| 12186 | } |
| 12187 | } |
| 12188 | |
| 12189 | /** |
| 12190 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12191 | * device does not have an active PUBLISH. |
| 12192 | */ |
| 12193 | // Used for SHELL command only right now. |
| 12194 | @Override |
| 12195 | public String getLastUcePidfXmlShell(int subId) { |
| 12196 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12197 | final long identity = Binder.clearCallingIdentity(); |
| 12198 | try { |
| 12199 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12200 | } catch (ImsException e) { |
| 12201 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12202 | } finally { |
| 12203 | Binder.restoreCallingIdentity(identity); |
| 12204 | } |
| 12205 | } |
| 12206 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12207 | /** |
| 12208 | * Remove UCE requests cannot be sent to the network status. |
| 12209 | */ |
| 12210 | // Used for SHELL command only right now. |
| 12211 | @Override |
| 12212 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12213 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12214 | final long identity = Binder.clearCallingIdentity(); |
| 12215 | try { |
| 12216 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12217 | } catch (ImsException e) { |
| 12218 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12219 | } finally { |
| 12220 | Binder.restoreCallingIdentity(identity); |
| 12221 | } |
| 12222 | } |
| 12223 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12224 | /** |
| 12225 | * Remove UCE requests cannot be sent to the network status. |
| 12226 | */ |
| 12227 | // Used for SHELL command only. |
| 12228 | @Override |
| 12229 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12230 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12231 | final long identity = Binder.clearCallingIdentity(); |
| 12232 | try { |
| 12233 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12234 | } catch (ImsException e) { |
| 12235 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12236 | } finally { |
| 12237 | Binder.restoreCallingIdentity(identity); |
| 12238 | } |
| 12239 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12240 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12241 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12242 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12243 | String callingPackage) { |
| 12244 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12245 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12246 | |
| 12247 | final int callingUid = Binder.getCallingUid(); |
| 12248 | // Verify that tha callingPackage belongs to the calling UID |
| 12249 | mApp.getSystemService(AppOpsManager.class) |
| 12250 | .checkPackage(callingUid, callingPackage); |
| 12251 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12252 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12253 | |
| 12254 | final long identity = Binder.clearCallingIdentity(); |
| 12255 | try { |
| 12256 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12257 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12258 | |
| 12259 | if (result instanceof IllegalStateException) { |
| 12260 | throw (IllegalStateException) result; |
| 12261 | } |
| 12262 | } finally { |
| 12263 | Binder.restoreCallingIdentity(identity); |
| 12264 | } |
| 12265 | } |
| 12266 | |
| 12267 | @Override |
| 12268 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12269 | String callingPackage) { |
| 12270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12271 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12272 | |
| 12273 | final int callingUid = Binder.getCallingUid(); |
| 12274 | // Verify that tha callingPackage belongs to the calling UID |
| 12275 | mApp.getSystemService(AppOpsManager.class) |
| 12276 | .checkPackage(callingUid, callingPackage); |
| 12277 | |
| 12278 | final long identity = Binder.clearCallingIdentity(); |
| 12279 | try { |
| 12280 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12281 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12282 | |
| 12283 | if (result instanceof IllegalStateException) { |
| 12284 | throw (IllegalStateException) result; |
| 12285 | } |
| 12286 | } finally { |
| 12287 | Binder.restoreCallingIdentity(identity); |
| 12288 | } |
| 12289 | } |
| 12290 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12291 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12292 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12293 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 12294 | // phone/system process do not have further restriction on request |
| 12295 | return; |
| 12296 | } |
| 12297 | |
| 12298 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12299 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12300 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12301 | context.enforceCallingOrSelfPermission( |
| 12302 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12303 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12304 | } |
| 12305 | |
| 12306 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12307 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12308 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12309 | || info.isEnabled()) { |
| 12310 | throw new IllegalArgumentException( |
| 12311 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12312 | } |
| 12313 | |
| 12314 | // Thresholds length for each RAN need in range. This has been validated in |
| 12315 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12316 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12317 | final int[] thresholds = info.getThresholds(); |
| 12318 | Objects.requireNonNull(thresholds); |
| 12319 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12320 | || thresholds.length |
| 12321 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12322 | throw new IllegalArgumentException( |
| 12323 | "thresholds length is out of range: " + thresholds.length); |
| 12324 | } |
| 12325 | } |
| 12326 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12327 | |
| 12328 | /** |
| 12329 | * Gets the current phone capability. |
| 12330 | * |
| 12331 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12332 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12333 | * It's used to evaluate possible phone config change, for example from single |
| 12334 | * SIM device to multi-SIM device. |
| 12335 | */ |
| 12336 | @Override |
| 12337 | public PhoneCapability getPhoneCapability() { |
| 12338 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 12339 | final long identity = Binder.clearCallingIdentity(); |
| 12340 | try { |
| 12341 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12342 | } finally { |
| 12343 | Binder.restoreCallingIdentity(identity); |
| 12344 | } |
| 12345 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12346 | |
| 12347 | /** |
| 12348 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12349 | * required to be done shortly after the API is invoked. |
| 12350 | */ |
| 12351 | @Override |
| 12352 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12353 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12354 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12355 | enforceRebootPermission(); |
| 12356 | |
| 12357 | final long identity = Binder.clearCallingIdentity(); |
| 12358 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12359 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12360 | } finally { |
| 12361 | Binder.restoreCallingIdentity(identity); |
| 12362 | } |
| 12363 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12364 | |
| 12365 | /** |
| 12366 | * Request to get the current slicing configuration including URSP rules and |
| 12367 | * NSSAIs (configured, allowed and rejected). |
| 12368 | * |
| 12369 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12370 | */ |
| 12371 | @Override |
| 12372 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12373 | TelephonyPermissions |
| 12374 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12375 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12376 | |
| 12377 | final long identity = Binder.clearCallingIdentity(); |
| 12378 | try { |
| 12379 | Phone phone = getDefaultPhone(); |
| 12380 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12381 | } finally { |
| 12382 | Binder.restoreCallingIdentity(identity); |
| 12383 | } |
| 12384 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12385 | |
| 12386 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12387 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12388 | * |
| 12389 | * @param capability The premium capability to check. |
| 12390 | * @param subId The subId to check the premium capability for. |
| 12391 | * |
| 12392 | * @return Whether the given premium capability is available to purchase. |
| 12393 | */ |
| 12394 | @Override |
| 12395 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12396 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12397 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12398 | log("Premium capability " |
| 12399 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12400 | + " is not available for purchase due to missing permissions."); |
| 12401 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12402 | + "permission READ_BASIC_PHONE_STATE."); |
| 12403 | } |
| 12404 | |
| 12405 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12406 | if (phone == null) { |
| 12407 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12408 | return false; |
| 12409 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12410 | final long identity = Binder.clearCallingIdentity(); |
| 12411 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 12412 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12413 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12414 | } finally { |
| 12415 | Binder.restoreCallingIdentity(identity); |
| 12416 | } |
| 12417 | } |
| 12418 | |
| 12419 | /** |
| 12420 | * Purchase the given premium capability from the carrier. |
| 12421 | * |
| 12422 | * @param capability The premium capability to purchase. |
| 12423 | * @param callback The result of the purchase request. |
| 12424 | * @param subId The subId to purchase the premium capability for. |
| 12425 | */ |
| 12426 | @Override |
| 12427 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12428 | log("purchasePremiumCapability: capability=" |
| 12429 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12430 | + getCurrentPackageName()); |
| 12431 | |
| 12432 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12433 | mApp, "purchasePremiumCapability")) { |
| 12434 | log("purchasePremiumCapability " |
| 12435 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12436 | + " failed due to missing permissions."); |
| 12437 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12438 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12439 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12440 | mApp, "purchasePremiumCapability")) { |
| 12441 | log("purchasePremiumCapability " |
| 12442 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12443 | + " failed due to missing permissions."); |
| 12444 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12445 | } |
| 12446 | |
| 12447 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12448 | if (phone == null) { |
| 12449 | try { |
| 12450 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12451 | callback.accept(result); |
| 12452 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12453 | } catch (RemoteException e) { |
| 12454 | String logStr = "Purchase premium capability " |
| 12455 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12456 | + " failed due to RemoteException handling null phone: " + e; |
| 12457 | if (DBG) log(logStr); |
| 12458 | AnomalyReporter.reportAnomaly( |
| 12459 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12460 | } |
| 12461 | return; |
| 12462 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12463 | |
| 12464 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12465 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12466 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12467 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12468 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12469 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12470 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12471 | |
| 12472 | boolean isVisible = false; |
| 12473 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12474 | if (am != null) { |
| 12475 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12476 | if (processes != null) { |
| 12477 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12478 | log("purchasePremiumCapability: process " + process.processName |
| 12479 | + "has importance " + process.importance); |
| 12480 | if (process.processName.equals(callingProcess) && process.importance |
| 12481 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12482 | isVisible = true; |
| 12483 | break; |
| 12484 | } |
| 12485 | } |
| 12486 | } |
| 12487 | } |
| 12488 | |
| 12489 | if (!isVisible) { |
| 12490 | try { |
| 12491 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12492 | callback.accept(result); |
| 12493 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12494 | } catch (RemoteException e) { |
| 12495 | String logStr = "Purchase premium capability " |
| 12496 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12497 | + " failed due to RemoteException handling background application: " + e; |
| 12498 | if (DBG) log(logStr); |
| 12499 | AnomalyReporter.reportAnomaly( |
| 12500 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12501 | } |
| 12502 | return; |
| 12503 | } |
| 12504 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12505 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12506 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12507 | } |
| 12508 | |
| 12509 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12510 | * Register an IMS connection state callback |
| 12511 | */ |
| 12512 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12513 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12514 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12515 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12516 | // ImsMmTelManager |
| 12517 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12518 | TelephonyPermissions |
| 12519 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12520 | mApp, subId, "registerImsStateCallback"); |
| 12521 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12522 | // ImsRcsManager or SipDelegateManager |
| 12523 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12524 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12525 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12526 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12527 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12528 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12529 | } |
| 12530 | |
| 12531 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12532 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12533 | "IMS not available on device."); |
| 12534 | } |
| 12535 | |
| 12536 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12537 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12538 | } |
| 12539 | |
| 12540 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12541 | if (controller == null) { |
| 12542 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12543 | "IMS not available on device."); |
| 12544 | } |
| 12545 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12546 | if (callingPackage == null) { |
| 12547 | callingPackage = getCurrentPackageName(); |
| 12548 | } |
| 12549 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12550 | final long token = Binder.clearCallingIdentity(); |
| 12551 | try { |
| 12552 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12553 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12554 | } catch (ImsException e) { |
| 12555 | throw new ServiceSpecificException(e.getCode()); |
| 12556 | } finally { |
| 12557 | Binder.restoreCallingIdentity(token); |
| 12558 | } |
| 12559 | } |
| 12560 | |
| 12561 | /** |
| 12562 | * Unregister an IMS connection state callback |
| 12563 | */ |
| 12564 | @Override |
| 12565 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12566 | final long token = Binder.clearCallingIdentity(); |
| 12567 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12568 | if (controller == null) { |
| 12569 | return; |
| 12570 | } |
| 12571 | try { |
| 12572 | controller.unregisterImsStateCallback(cb); |
| 12573 | } finally { |
| 12574 | Binder.restoreCallingIdentity(token); |
| 12575 | } |
| 12576 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12577 | |
| 12578 | /** |
| 12579 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12580 | * |
| 12581 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 12582 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 12583 | * SecurityException. |
| 12584 | * If there is current registered network this value will be same as the registered cell |
| 12585 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12586 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12587 | * it will be cleared and null will be returned. |
| 12588 | * |
| 12589 | */ |
| 12590 | @Override |
| 12591 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12592 | String callingFeatureId) { |
| 12593 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12594 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12595 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12596 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12597 | .setCallingPackage(callingPackage) |
| 12598 | .setCallingFeatureId(callingFeatureId) |
| 12599 | .setCallingPid(Binder.getCallingPid()) |
| 12600 | .setCallingUid(Binder.getCallingUid()) |
| 12601 | .setMethod("getLastKnownCellIdentity") |
| 12602 | .setLogAsInfo(true) |
| 12603 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12604 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12605 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12606 | .build()); |
| 12607 | |
| 12608 | boolean hasFinePermission = |
| 12609 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12610 | if (!hasFinePermission |
| 12611 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12612 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12613 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12614 | } |
| 12615 | |
| 12616 | final long identity = Binder.clearCallingIdentity(); |
| 12617 | try { |
| 12618 | Phone phone = getPhone(subId); |
| 12619 | if (phone == null) return null; |
| 12620 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 12621 | if (sst == null) return null; |
| 12622 | return sst.getLastKnownCellIdentity(); |
| 12623 | } finally { |
| 12624 | Binder.restoreCallingIdentity(identity); |
| 12625 | } |
| 12626 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12627 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12628 | /** |
| 12629 | * Sets the modem service class Name that Telephony will bind to. |
| 12630 | * |
| 12631 | * @param serviceName The class name of the modem service. |
| 12632 | * @return true if the operation is succeed, otherwise false. |
| 12633 | */ |
| 12634 | public boolean setModemService(String serviceName) { |
| 12635 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12636 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12638 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12639 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12640 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12641 | } |
| 12642 | |
| 12643 | /** |
| 12644 | * Return the class name of the currently bounded modem service. |
| 12645 | * |
| 12646 | * @return the class name of the modem service. |
| 12647 | */ |
| 12648 | public String getModemService() { |
| 12649 | String result; |
| 12650 | Log.d(LOG_TAG, "getModemService"); |
| 12651 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12652 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12653 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12654 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12655 | "getModemService"); |
| 12656 | result = mPhoneConfigurationManager.getModemService(); |
| 12657 | Log.d(LOG_TAG, "result = " + result); |
| 12658 | return result; |
| 12659 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12660 | |
| 12661 | @Override |
| 12662 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12663 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12664 | mApp.enforceCallingOrSelfPermission( |
| 12665 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12666 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12667 | |
| 12668 | final long identity = Binder.clearCallingIdentity(); |
| 12669 | try { |
| 12670 | Phone phone = getPhone(subId); |
| 12671 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12672 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12673 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12674 | phone.setVoiceServiceStateOverride(hasService); |
| 12675 | } finally { |
| 12676 | Binder.restoreCallingIdentity(identity); |
| 12677 | } |
| 12678 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12679 | |
| 12680 | /** |
| 12681 | * set removable eSIM as default eUICC. |
| 12682 | * |
| 12683 | * @hide |
| 12684 | */ |
| 12685 | @Override |
| 12686 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12687 | enforceModifyPermission(); |
| 12688 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12689 | |
| 12690 | final long identity = Binder.clearCallingIdentity(); |
| 12691 | try { |
| 12692 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12693 | } finally { |
| 12694 | Binder.restoreCallingIdentity(identity); |
| 12695 | } |
| 12696 | } |
| 12697 | |
| 12698 | /** |
| 12699 | * Returns whether the removable eSIM is default eUICC or not. |
| 12700 | * |
| 12701 | * @hide |
| 12702 | */ |
| 12703 | @Override |
| 12704 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12705 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12706 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12707 | |
| 12708 | final long identity = Binder.clearCallingIdentity(); |
| 12709 | try { |
| 12710 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12711 | } finally { |
| 12712 | Binder.restoreCallingIdentity(identity); |
| 12713 | } |
| 12714 | } |
| 12715 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12716 | /** |
| 12717 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12718 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12719 | * application currently configured for this user. |
| 12720 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12721 | * {@code null} if the functionality is not supported. |
| 12722 | * @hide |
| 12723 | */ |
| 12724 | @Override |
| 12725 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12726 | boolean updateIfNeeded) { |
| 12727 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12728 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12729 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12730 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12731 | UserHandle userHandle = null; |
| 12732 | final long identity = Binder.clearCallingIdentity(); |
| 12733 | try { |
| 12734 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12735 | } finally { |
| 12736 | Binder.restoreCallingIdentity(identity); |
| 12737 | } |
| 12738 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12739 | updateIfNeeded, userHandle); |
| 12740 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12741 | |
| 12742 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12743 | * Set whether the device is able to connect with null ciphering or integrity |
| 12744 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12745 | * and all new subscriptions after this. |
| 12746 | * |
| 12747 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12748 | * @hide |
| 12749 | */ |
| 12750 | @Override |
| 12751 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12752 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12753 | enforceModifyPermission(); |
| 12754 | checkForNullCipherAndIntegritySupport(); |
| 12755 | |
| 12756 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12757 | // for listening to these preference changes and applying them immediately. |
| 12758 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12759 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12760 | editor.apply(); |
| 12761 | |
| 12762 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12763 | phone.handleNullCipherEnabledChange(); |
| 12764 | } |
| 12765 | } |
| 12766 | |
| 12767 | |
| 12768 | /** |
| 12769 | * Get whether the device is able to connect with null ciphering or integrity |
| 12770 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12771 | * the state of the radio. |
| 12772 | * |
| 12773 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12774 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12775 | * version for this feature. |
| 12776 | * @hide |
| 12777 | */ |
| 12778 | @Override |
| 12779 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12780 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12781 | enforceReadPermission(); |
| 12782 | checkForNullCipherAndIntegritySupport(); |
| 12783 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12784 | } |
| 12785 | |
| 12786 | private void checkForNullCipherAndIntegritySupport() { |
| 12787 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12788 | throw new UnsupportedOperationException( |
| 12789 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12790 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12791 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12792 | throw new UnsupportedOperationException( |
| 12793 | "Null cipher and integrity operations unsupported by modem"); |
| 12794 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12795 | } |
| 12796 | |
| 12797 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12798 | * Get the SIM state for the slot index. |
| 12799 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12800 | * |
| 12801 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12802 | */ |
| 12803 | @Override |
| 12804 | @SimState |
| 12805 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12806 | IccCardConstants.State simState; |
| 12807 | if (slotIndex < 0) { |
| 12808 | simState = IccCardConstants.State.UNKNOWN; |
| 12809 | } else { |
| 12810 | Phone phone = null; |
| 12811 | try { |
| 12812 | phone = PhoneFactory.getPhone(slotIndex); |
| 12813 | } catch (IllegalStateException e) { |
| 12814 | // ignore |
| 12815 | } |
| 12816 | if (phone == null) { |
| 12817 | simState = IccCardConstants.State.UNKNOWN; |
| 12818 | } else { |
| 12819 | IccCard icc = phone.getIccCard(); |
| 12820 | if (icc == null) { |
| 12821 | simState = IccCardConstants.State.UNKNOWN; |
| 12822 | } else { |
| 12823 | simState = icc.getState(); |
| 12824 | } |
| 12825 | } |
| 12826 | } |
| 12827 | return simState.ordinal(); |
| 12828 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12829 | |
| 12830 | /** |
| 12831 | * Get current cell broadcast ranges. |
| 12832 | */ |
| 12833 | @Override |
| 12834 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12835 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12836 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12837 | "getCellBroadcastIdRanges"); |
| 12838 | final long identity = Binder.clearCallingIdentity(); |
| 12839 | try { |
| 12840 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12841 | } finally { |
| 12842 | Binder.restoreCallingIdentity(identity); |
| 12843 | } |
| 12844 | } |
| 12845 | |
| 12846 | /** |
| 12847 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12848 | * |
| 12849 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12850 | */ |
| 12851 | @Override |
| 12852 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12853 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12854 | @Nullable IIntegerConsumer callback) { |
| 12855 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12856 | "setCellBroadcastIdRanges"); |
| 12857 | final long identity = Binder.clearCallingIdentity(); |
| 12858 | try { |
| 12859 | Phone phone = getPhoneFromSubId(subId); |
| 12860 | if (DBG) { |
| 12861 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12862 | } |
| 12863 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12864 | if (callback != null) { |
| 12865 | try { |
| 12866 | callback.accept(result); |
| 12867 | } catch (RemoteException e) { |
| 12868 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12869 | } |
| 12870 | } |
| 12871 | }); |
| 12872 | } finally { |
| 12873 | Binder.restoreCallingIdentity(identity); |
| 12874 | } |
| 12875 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12876 | |
| 12877 | /** |
| 12878 | * Returns whether the device supports the domain selection service. |
| 12879 | * |
| 12880 | * @return {@code true} if the device supports the domain selection service. |
| 12881 | */ |
| 12882 | @Override |
| 12883 | public boolean isDomainSelectionSupported() { |
| 12884 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12885 | "isDomainSelectionSupported"); |
| 12886 | |
| 12887 | final long identity = Binder.clearCallingIdentity(); |
| 12888 | try { |
| 12889 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12890 | } finally { |
| 12891 | Binder.restoreCallingIdentity(identity); |
| 12892 | } |
| 12893 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12894 | |
| 12895 | /** |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12896 | * Request to enable or disable the satellite modem. If the satellite modem is enabled, this |
| 12897 | * will also disable the cellular modem, and if the satellite modem is disabled, this will also |
| 12898 | * re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12899 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12900 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12901 | * @param enable {@code true} to enable the satellite modem and {@code false} to disable. |
| 12902 | * @param callback The callback to get the error code of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12903 | * |
| 12904 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12905 | */ |
| 12906 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12907 | public void requestSatelliteEnabled( |
| 12908 | int subId, boolean enable, @NonNull IIntegerConsumer callback) { |
| 12909 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12910 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12911 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12912 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12913 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12914 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12915 | |
| 12916 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12917 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12918 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 12919 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12920 | } |
| 12921 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12922 | Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteEnabled"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12923 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12924 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12925 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12926 | } |
| 12927 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12928 | Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result); |
| 12929 | sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12930 | } |
| 12931 | |
| 12932 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12933 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12934 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12935 | * @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] | 12936 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12937 | * 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] | 12938 | * |
| 12939 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12940 | */ |
| 12941 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12942 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12943 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12944 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12945 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 12946 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12947 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12948 | |
| 12949 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12950 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12951 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 12952 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12953 | } |
| 12954 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12955 | Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12956 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12957 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 12958 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12959 | } |
| 12960 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12961 | sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12962 | } |
| 12963 | |
| 12964 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12965 | * Request to enable or disable the satellite service demo mode. |
| 12966 | * |
| 12967 | * @param subId The subId of the subscription to set the satellite demo mode enabled for. |
| 12968 | * @param enable {@code true} to enable the satellite demo mode and {@code false} to disable. |
| 12969 | * @param callback The callback to get the error code of the request. |
| 12970 | * |
| 12971 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12972 | */ |
| 12973 | @Override |
| 12974 | public void requestSatelliteDemoModeEnabled( |
| 12975 | int subId, boolean enable, @NonNull IIntegerConsumer callback) { |
| 12976 | enforceSatelliteCommunicationPermission("requestSatelliteDemoModeEnabled"); |
| 12977 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 12978 | if (!isSatelliteSupported()) { |
| 12979 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 12980 | return; |
| 12981 | } |
| 12982 | |
| 12983 | final int validSubId = getValidSatelliteSubId(subId); |
| 12984 | if (!isSatelliteProvisioned(validSubId)) { |
| 12985 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 12986 | return; |
| 12987 | } |
| 12988 | |
| 12989 | Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteDemoModeEnabled"); |
| 12990 | if (phone == null) { |
| 12991 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 12992 | return; |
| 12993 | } |
| 12994 | |
| 12995 | if (mIsSatelliteServiceSupported) { |
| 12996 | result.accept(mSatelliteServiceController.requestSatelliteDemoModeEnabled(enable)); |
| 12997 | } else { |
| 12998 | result.accept(SatelliteManager.SATELLITE_SERVICE_ERROR); |
| 12999 | } |
| 13000 | } |
| 13001 | |
| 13002 | /** |
| 13003 | * Request to get whether the satellite service demo mode is enabled. |
| 13004 | * |
| 13005 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13006 | * is enabled for. |
| 13007 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13008 | * if the request is successful or an error code if the request failed. |
| 13009 | * |
| 13010 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13011 | */ |
| 13012 | @Override |
| 13013 | public void requestIsSatelliteDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13014 | enforceSatelliteCommunicationPermission("requestIsSatelliteDemoModeEnabled"); |
| 13015 | if (!isSatelliteSupported()) { |
| 13016 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 13017 | return; |
| 13018 | } |
| 13019 | |
| 13020 | final int validSubId = getValidSatelliteSubId(subId); |
| 13021 | if (!isSatelliteProvisioned(validSubId)) { |
| 13022 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 13023 | return; |
| 13024 | } |
| 13025 | |
| 13026 | Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteDemoModeEnabled"); |
| 13027 | if (phone == null) { |
| 13028 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 13029 | return; |
| 13030 | } |
| 13031 | |
| 13032 | if (mIsSatelliteServiceSupported) { |
| 13033 | final Bundle bundle = new Bundle(); |
| 13034 | int error = mSatelliteServiceController.requestIsSatelliteDemoModeEnabled( |
| 13035 | new Consumer<Boolean>() { |
| 13036 | @Override |
| 13037 | public void accept(Boolean enabled) { |
| 13038 | bundle.putBoolean(SatelliteManager.KEY_DEMO_MODE_ENABLED, enabled); |
| 13039 | } |
| 13040 | }); |
| 13041 | result.send(error, bundle); |
| 13042 | } else { |
| 13043 | result.send(SatelliteManager.SATELLITE_SERVICE_ERROR, null); |
| 13044 | } |
| 13045 | } |
| 13046 | |
| 13047 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13048 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13049 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13050 | * @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] | 13051 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13052 | * 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] | 13053 | */ |
| 13054 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13055 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13056 | synchronized (mIsSatelliteSupportedLock) { |
| 13057 | if (mIsSatelliteSupported != null) { |
| 13058 | /* We have already successfully queried the satellite modem. */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13059 | Bundle bundle = new Bundle(); |
| 13060 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported); |
| 13061 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle); |
| 13062 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13063 | } |
| 13064 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13065 | |
| 13066 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13067 | Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13068 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13069 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 13070 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13071 | } |
| 13072 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13073 | sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13074 | } |
| 13075 | |
| 13076 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13077 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13078 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13079 | * @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] | 13080 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13081 | * 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] | 13082 | * |
| 13083 | * @throws SecurityException if the caller doesn't have required permission. |
| 13084 | */ |
| 13085 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13086 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13087 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13088 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13089 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 13090 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13091 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13092 | |
| 13093 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13094 | Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities"); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13095 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13096 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 13097 | return; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13098 | } |
| 13099 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13100 | sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13101 | } |
| 13102 | |
| 13103 | /** |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13104 | * Start receiving satellite position updates. |
| 13105 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13106 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13107 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13108 | * @param subId The subId of the subscription to start satellite position updates for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13109 | * @param errorCallback The callback to get the error code of the request. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13110 | * @param callback The callback to notify of changes in satellite position. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13111 | * |
| 13112 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13113 | */ |
| 13114 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13115 | public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13116 | @NonNull ISatellitePositionUpdateCallback callback) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 13117 | enforceSatelliteCommunicationPermission("startSatellitePositionUpdates"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13118 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13119 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13120 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 13121 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13122 | } |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 13123 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13124 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13125 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13126 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 13127 | return; |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 13128 | } |
| 13129 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13130 | Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates"); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13131 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13132 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 13133 | return; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13134 | } |
| 13135 | |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13136 | SatellitePositionUpdateHandler handler = mSatellitePositionUpdateHandlers.get(validSubId); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13137 | if (handler != null) { |
| 13138 | handler.addListener(callback); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13139 | return; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13140 | } else { |
| 13141 | handler = new SatellitePositionUpdateHandler(Looper.getMainLooper()); |
| 13142 | handler.addListener(callback); |
| 13143 | mSatellitePositionUpdateHandlers.put(validSubId, handler); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13144 | if (mIsSatelliteServiceSupported) { |
| 13145 | mSatelliteServiceController.registerForSatellitePositionInfoChanged(handler, |
| 13146 | SatellitePositionUpdateHandler.EVENT_POSITION_INFO_CHANGED, null); |
| 13147 | mSatelliteServiceController.registerForDatagramTransferStateChanged(handler, |
| 13148 | SatellitePositionUpdateHandler.EVENT_DATAGRAM_TRANSFER_STATE_CHANGED, null); |
| 13149 | } else { |
| 13150 | phone.registerForSatellitePositionInfoChanged(handler, |
| 13151 | SatellitePositionUpdateHandler.EVENT_POSITION_INFO_CHANGED, null); |
| 13152 | // TODO: registerForDatagramTransferStateChanged through SatelliteController |
| 13153 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13154 | } |
| 13155 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13156 | sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, |
| 13157 | new SatellitePositionUpdateArgument(result, callback, validSubId), phone, null); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13158 | } |
| 13159 | |
| 13160 | /** |
| 13161 | * Stop receiving satellite position updates. |
| 13162 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13163 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13164 | * @param subId The subId of the subscription to stop satellite position updates for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13165 | * @param errorCallback The callback to get the error code of the request. |
| 13166 | * @param callback The callback that was passed to {@link |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13167 | * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)} |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13168 | * |
| 13169 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13170 | */ |
| 13171 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13172 | public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13173 | @NonNull ISatellitePositionUpdateCallback callback) { |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 13174 | enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13175 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13176 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13177 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 13178 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13179 | } |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 13180 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13181 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13182 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13183 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 13184 | return; |
Sarah Chin | f75afa7 | 2023-02-01 01:32:19 -0800 | [diff] [blame] | 13185 | } |
| 13186 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13187 | Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates"); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13188 | SatellitePositionUpdateHandler handler = mSatellitePositionUpdateHandlers.get(validSubId); |
| 13189 | if (handler != null) { |
| 13190 | handler.removeListener(callback); |
| 13191 | |
| 13192 | if (handler.hasListeners()) { |
| 13193 | /** |
| 13194 | * TODO (b/269194948): If the calling apps crash, the handler will always have some |
| 13195 | * listener. That is, we will not request modem to stop position update and |
| 13196 | * cleaning our resources. We need to monitor the calling apps and clean up the |
| 13197 | * resources when the apps die. We need to this for other satellite callbacks |
| 13198 | * as well. |
| 13199 | */ |
| 13200 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 13201 | return; |
| 13202 | } |
| 13203 | |
| 13204 | mSatellitePositionUpdateHandlers.remove(validSubId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13205 | if (mIsSatelliteServiceSupported) { |
| 13206 | mSatelliteServiceController.unregisterForSatellitePositionInfoChanged(handler); |
| 13207 | mSatelliteServiceController.unregisterForDatagramTransferStateChanged(handler); |
| 13208 | } else { |
| 13209 | if (phone == null) { |
| 13210 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 13211 | return; |
| 13212 | } |
| 13213 | phone.unregisterForSatellitePositionInfoChanged(handler); |
| 13214 | // TODO: unregisterForDatagramTransferStateChanged through SatelliteController |
| 13215 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13216 | } |
| 13217 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13218 | /** |
| 13219 | * Even if handler is null - which means there are not any listeners, the command to stop |
| 13220 | * satellite position updates sent to the modem might have failed. The callers might want to |
| 13221 | * retry sending the command. Thus, we always need to send this command to the modem. |
| 13222 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13223 | sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13224 | } |
| 13225 | |
| 13226 | /** |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13227 | * Request to get the maximum number of bytes per datagram that can be sent to satellite. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13228 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13229 | * @param subId The subId of the subscription to get the maximum number of characters for. |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13230 | * @param result The result receiver that returns the maximum number of bytes per datagram |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13231 | * message on satellite if the request is successful or an error code |
| 13232 | * if the request failed. |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13233 | * |
| 13234 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13235 | */ |
| 13236 | @Override |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13237 | public void requestMaxSizePerSendingDatagram(int subId, |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13238 | @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13239 | enforceSatelliteCommunicationPermission("requestMaxSizePerSendingDatagram"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13240 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13241 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 13242 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13243 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13244 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13245 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13246 | if (!isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13247 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 13248 | return; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13249 | } |
| 13250 | |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13251 | Phone phone = getPhoneOrDefault(validSubId, "requestMaxSizePerSendingDatagram"); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13252 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13253 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 13254 | return; |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13255 | } |
| 13256 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13257 | sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13258 | } |
| 13259 | |
| 13260 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13261 | * Register the subscription with a satellite provider. |
| 13262 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13263 | * |
| 13264 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13265 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13266 | * gateway. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13267 | * @param callback The callback to get the error code of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13268 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13269 | * @return The signal transport used by the caller to cancel the provision request, |
| 13270 | * or {@code null} if the request failed. |
| 13271 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13272 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13273 | */ |
| 13274 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13275 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
| 13276 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13277 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13278 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13279 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13280 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13281 | return null; |
| 13282 | } |
| 13283 | |
| 13284 | final int validSubId = getValidSatelliteSubId(subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13285 | Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService"); |
| 13286 | if (phone == null) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13287 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13288 | return null; |
| 13289 | } |
| 13290 | |
| 13291 | if (mSatelliteProvisionCallbacks.containsKey(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13292 | result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13293 | return null; |
| 13294 | } |
| 13295 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13296 | if (isSatelliteProvisioned(validSubId)) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13297 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13298 | return null; |
| 13299 | } |
| 13300 | |
| 13301 | sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE, |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13302 | new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13303 | |
| 13304 | ICancellationSignal cancelTransport = CancellationSignal.createTransport(); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13305 | CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> { |
| 13306 | sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE, |
| 13307 | new ProvisionSatelliteServiceArgument(token, null, validSubId), |
| 13308 | phone, null); |
| 13309 | }); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13310 | return cancelTransport; |
| 13311 | } |
| 13312 | |
| 13313 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13314 | * Unregister the device/subscription with the satellite provider. |
| 13315 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13316 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13317 | * should report as deprovisioned. |
| 13318 | * |
| 13319 | * @param subId The subId of the subscription to be deprovisioned. |
| 13320 | * @param token The token of the device/subscription to be deprovisioned. |
| 13321 | * @param callback The callback to get the error code of the request. |
| 13322 | * |
| 13323 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13324 | */ |
| 13325 | @Override |
| 13326 | public void deprovisionSatelliteService(int subId, |
| 13327 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13328 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
| 13329 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 13330 | if (!isSatelliteSupported()) { |
| 13331 | result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED); |
| 13332 | return; |
| 13333 | } |
| 13334 | |
| 13335 | final int validSubId = getValidSatelliteSubId(subId); |
| 13336 | if (!isSatelliteProvisioned(validSubId)) { |
| 13337 | result.accept(SatelliteManager.SATELLITE_ERROR_NONE); |
| 13338 | return; |
| 13339 | } |
| 13340 | |
| 13341 | Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService"); |
| 13342 | if (phone == null) { |
| 13343 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 13344 | return; |
| 13345 | } |
| 13346 | |
| 13347 | sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE, |
| 13348 | new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null); |
| 13349 | } |
| 13350 | |
| 13351 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13352 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13353 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13354 | * @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] | 13355 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13356 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13357 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 13358 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13359 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13360 | */ |
| 13361 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13362 | @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13363 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13364 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13365 | return registerForSatelliteProvisionStateChangedInternal(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13366 | } |
| 13367 | |
| 13368 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13369 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13370 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13371 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13372 | * @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] | 13373 | * @param callback The callback that was passed to |
| 13374 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13375 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13376 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13377 | */ |
| 13378 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13379 | public void unregisterForSatelliteProvisionStateChanged( |
| 13380 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13381 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
| 13382 | |
| 13383 | final int validSubId = getValidSatelliteSubId(subId); |
| 13384 | SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler = |
| 13385 | mSatelliteProvisionStateChangedHandlers.get(validSubId); |
| 13386 | if (satelliteProvisionStateChangedHandler != null) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13387 | satelliteProvisionStateChangedHandler.removeListener(callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13388 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13389 | } |
| 13390 | |
| 13391 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13392 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13393 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13394 | * @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] | 13395 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13396 | * satellite provider if the request is successful or an error code if the |
| 13397 | * request failed. |
| 13398 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13399 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13400 | */ |
| 13401 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13402 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13403 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13404 | if (!isSatelliteSupported()) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13405 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 13406 | return; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13407 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13408 | |
| 13409 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13410 | Bundle bundle = new Bundle(); |
| 13411 | bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED, |
| 13412 | isSatelliteProvisioned(validSubId)); |
| 13413 | result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13414 | } |
| 13415 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13416 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13417 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13418 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13419 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13420 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13421 | * |
| 13422 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 13423 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13424 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13425 | */ |
| 13426 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13427 | @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13428 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13429 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13430 | |
| 13431 | final int validSubId = getValidSatelliteSubId(subId); |
| 13432 | Phone phone = getPhoneOrDefault( |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13433 | validSubId, "registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13434 | if (phone == null) { |
| 13435 | return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE; |
| 13436 | } |
| 13437 | |
| 13438 | SatelliteStateListenerHandler satelliteStateListenerHandler = |
| 13439 | mSatelliteStateListenerHandlers.get(validSubId); |
| 13440 | if (satelliteStateListenerHandler == null) { |
| 13441 | satelliteStateListenerHandler = new SatelliteStateListenerHandler( |
| 13442 | Looper.getMainLooper(), validSubId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13443 | if (mIsSatelliteServiceSupported) { |
| 13444 | mSatelliteServiceController.registerForSatelliteModemStateChanged( |
| 13445 | satelliteStateListenerHandler, |
| 13446 | SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null); |
| 13447 | mSatelliteServiceController.registerForPendingDatagramCount( |
| 13448 | satelliteStateListenerHandler, |
| 13449 | SatelliteStateListenerHandler.EVENT_PENDING_DATAGRAM_COUNT, null); |
| 13450 | } else { |
| 13451 | phone.registerForSatelliteModemStateChanged(satelliteStateListenerHandler, |
| 13452 | SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null); |
| 13453 | phone.registerForPendingDatagramCount(satelliteStateListenerHandler, |
| 13454 | SatelliteStateListenerHandler.EVENT_PENDING_DATAGRAM_COUNT, null); |
| 13455 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13456 | } |
| 13457 | |
| 13458 | satelliteStateListenerHandler.addListener(callback); |
| 13459 | mSatelliteStateListenerHandlers.put(validSubId, satelliteStateListenerHandler); |
| 13460 | return SatelliteManager.SATELLITE_ERROR_NONE; |
| 13461 | } |
| 13462 | |
| 13463 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13464 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13465 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13466 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13467 | * @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] | 13468 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13469 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13470 | * |
| 13471 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13472 | */ |
| 13473 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13474 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13475 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13476 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13477 | |
| 13478 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13479 | SatelliteStateListenerHandler handler = mSatelliteStateListenerHandlers.get(validSubId); |
| 13480 | if (handler != null) { |
| 13481 | handler.removeListener(callback); |
| 13482 | if (!handler.hasListeners()) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13483 | mSatelliteStateListenerHandlers.remove(validSubId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13484 | if (mIsSatelliteServiceSupported) { |
| 13485 | mSatelliteServiceController.unregisterForSatelliteModemStateChanged(handler); |
| 13486 | mSatelliteServiceController.unregisterForPendingDatagramCount(handler); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13487 | } else { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13488 | Phone phone = getPhoneOrDefault( |
| 13489 | validSubId, "unregisterForSatelliteModemStateChanged"); |
| 13490 | if (phone == null) { |
| 13491 | loge("unregisterForSatelliteModemStateChanged: phone is null"); |
| 13492 | } else { |
| 13493 | phone.unregisterForSatelliteModemStateChanged(handler); |
| 13494 | phone.unregisterForPendingDatagramCount(handler); |
| 13495 | } |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13496 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13497 | } |
| 13498 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13499 | } |
| 13500 | |
| 13501 | /** |
| 13502 | * Register to receive incoming datagrams over satellite. |
| 13503 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13504 | * @param subId The subId of the subscription to register for incoming satellite datagrams. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13505 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13506 | * SOS_SMS or LOCATION_SHARING. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13507 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13508 | * |
| 13509 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 13510 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13511 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13512 | */ |
| 13513 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13514 | @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId, |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13515 | @SatelliteManager.DatagramType int datagramType, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13516 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13517 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13518 | if (!isSatelliteSupported()) { |
| 13519 | return SatelliteManager.SATELLITE_NOT_SUPPORTED; |
| 13520 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13521 | |
| 13522 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13523 | Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteDatagram"); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13524 | if (phone == null) { |
| 13525 | return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE; |
| 13526 | } |
| 13527 | |
| 13528 | SatelliteDatagramListenerHandler satelliteDatagramListenerHandler = |
| 13529 | mSatelliteDatagramListenerHandlers.get(validSubId); |
| 13530 | if (satelliteDatagramListenerHandler == null) { |
| 13531 | satelliteDatagramListenerHandler = new SatelliteDatagramListenerHandler( |
| 13532 | Looper.getMainLooper(), validSubId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13533 | if (mIsSatelliteServiceSupported) { |
| 13534 | mSatelliteServiceController.registerForSatelliteDatagramsReceived( |
| 13535 | satelliteDatagramListenerHandler, |
| 13536 | SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null); |
| 13537 | } else { |
| 13538 | phone.registerForSatelliteDatagramsReceived(satelliteDatagramListenerHandler, |
| 13539 | SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null); |
| 13540 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13541 | } |
| 13542 | |
| 13543 | satelliteDatagramListenerHandler.addListener(callback); |
| 13544 | mSatelliteDatagramListenerHandlers.put(validSubId, satelliteDatagramListenerHandler); |
| 13545 | return SatelliteManager.SATELLITE_ERROR_NONE; |
| 13546 | } |
| 13547 | |
| 13548 | /** |
| 13549 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13550 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13551 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13552 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13553 | * @param callback The callback that was passed to |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13554 | * {@link #registerForSatelliteDatagram(int, int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13555 | * |
| 13556 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13557 | */ |
| 13558 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13559 | public void unregisterForSatelliteDatagram(int subId, |
| 13560 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13561 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
| 13562 | |
| 13563 | final int validSubId = getValidSatelliteSubId(subId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13564 | SatelliteDatagramListenerHandler handler = |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13565 | mSatelliteDatagramListenerHandlers.get(validSubId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13566 | if (handler != null) { |
| 13567 | handler.removeListener(callback); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13568 | |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13569 | if (!handler.hasListeners()) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13570 | mSatelliteDatagramListenerHandlers.remove(validSubId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13571 | if (mIsSatelliteServiceSupported) { |
| 13572 | mSatelliteServiceController.unregisterForSatelliteDatagramsReceived(handler); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13573 | } else { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13574 | Phone phone = getPhoneOrDefault(validSubId, "unregisterForSatelliteDatagram"); |
| 13575 | if (phone == null) { |
| 13576 | loge("unregisterForSatelliteDatagram: phone is null"); |
| 13577 | } else { |
| 13578 | phone.unregisterForSatelliteDatagramsReceived(handler); |
| 13579 | } |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13580 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13581 | } |
| 13582 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13583 | } |
| 13584 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13585 | /** |
| 13586 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13587 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13588 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13589 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13590 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, |
| 13591 | * ISatelliteDatagramReceiverAck)} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13592 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13593 | * @param subId The subId of the subscription used for receiving datagrams. |
| 13594 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13595 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13596 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13597 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13598 | @Override |
| 13599 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13600 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13601 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13602 | |
| 13603 | final int validSubId = getValidSatelliteSubId(subId); |
| 13604 | if (!isSatelliteProvisioned(validSubId)) { |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13605 | result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED); |
| 13606 | return; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13607 | } |
| 13608 | |
| 13609 | Phone phone = getPhoneOrDefault(validSubId, "pollPendingSatelliteDatagrams"); |
| 13610 | if (phone == null) { |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13611 | result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE); |
| 13612 | return; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13613 | } |
| 13614 | |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13615 | sendRequestAsync(CMD_POLL_PENDING_SATELLITE_DATAGRAMS, result, phone, null); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13616 | } |
| 13617 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13618 | /** |
| 13619 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13620 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13621 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13622 | * input to this method. Datagram received here will be passed down to modem without any |
| 13623 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13624 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13625 | * @param subId The subId of the subscription to send satellite datagrams for. |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13626 | * @param datagramId An id that uniquely identifies datagram requested to be sent. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13627 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13628 | * SOS_SMS or LOCATION_SHARING. |
| 13629 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13630 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame^] | 13631 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13632 | * full screen mode. |
| 13633 | * @param result The result receiver that returns datagramId if datagram is sent successfully |
| 13634 | * or {@link SatelliteManager.SatelliteError} of the request if it is failed. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13635 | * |
| 13636 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13637 | */ |
| 13638 | @Override |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13639 | public void sendSatelliteDatagram(int subId, long datagramId, |
| 13640 | @SatelliteManager.DatagramType int datagramType, SatelliteDatagram datagram, |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame^] | 13641 | boolean needFullScreenPointingUI, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13642 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13643 | |
| 13644 | final int validSubId = getValidSatelliteSubId(subId); |
| 13645 | if (!isSatelliteProvisioned(validSubId)) { |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13646 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13647 | return; |
| 13648 | } |
| 13649 | |
| 13650 | Phone phone = getPhoneOrDefault(validSubId, "sendSatelliteDatagram"); |
| 13651 | if (phone == null) { |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13652 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13653 | return; |
| 13654 | } |
| 13655 | |
| 13656 | // check if we need to start PointingUI. |
| 13657 | |
| 13658 | sendRequestAsync(CMD_SEND_SATELLITE_DATAGRAM, |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame^] | 13659 | new SendSatelliteDatagramArgument(datagramId, datagramType, datagram, |
| 13660 | needFullScreenPointingUI, result), phone, null); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13661 | } |
| 13662 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13663 | /** |
| 13664 | * Request to get whether satellite communication is allowed for the current location. |
| 13665 | * |
| 13666 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13667 | * allowed for the current location for. |
| 13668 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13669 | * for the current location if the request is successful or an error code |
| 13670 | * if the request failed. |
| 13671 | * |
| 13672 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13673 | */ |
| 13674 | @Override |
| 13675 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 13676 | @NonNull ResultReceiver result) { |
| 13677 | enforceSatelliteCommunicationPermission( |
| 13678 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
| 13679 | if (!isSatelliteSupported()) { |
| 13680 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 13681 | return; |
| 13682 | } |
| 13683 | |
| 13684 | final int validSubId = getValidSatelliteSubId(subId); |
| 13685 | if (!isSatelliteProvisioned(validSubId)) { |
| 13686 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 13687 | return; |
| 13688 | } |
| 13689 | |
| 13690 | Phone phone = getPhoneOrDefault(validSubId, |
| 13691 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
| 13692 | if (phone == null) { |
| 13693 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 13694 | return; |
| 13695 | } |
| 13696 | |
| 13697 | sendRequest(CMD_IS_SATELLITE_COMMUNICATION_ALLOWED, result, subId); |
| 13698 | } |
| 13699 | |
| 13700 | /** |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13701 | * Request to get the time after which the satellite will be visible |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13702 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13703 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13704 | * @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] | 13705 | * be visible if the request is successful or an error code if the request failed. |
| 13706 | * |
| 13707 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13708 | */ |
| 13709 | @Override |
| 13710 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13711 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
| 13712 | if (!isSatelliteSupported()) { |
| 13713 | result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null); |
| 13714 | return; |
| 13715 | } |
| 13716 | |
| 13717 | final int validSubId = getValidSatelliteSubId(subId); |
| 13718 | if (!isSatelliteProvisioned(validSubId)) { |
| 13719 | result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null); |
| 13720 | return; |
| 13721 | } |
| 13722 | |
| 13723 | Phone phone = getPhoneOrDefault(validSubId, "requestTimeForNextSatelliteVisibility"); |
| 13724 | if (phone == null) { |
| 13725 | result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null); |
| 13726 | return; |
| 13727 | } |
| 13728 | |
| 13729 | sendRequestAsync(CMD_GET_TIME_SATELLITE_NEXT_VISIBLE, result, phone, null); |
| 13730 | } |
| 13731 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13732 | private void handleEventProvisionSatelliteServiceDone( |
| 13733 | @NonNull ProvisionSatelliteServiceArgument arg, |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13734 | @SatelliteManager.SatelliteError int result) { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13735 | log("handleEventProvisionSatelliteServiceDone: result=" |
| 13736 | + result + ", subId=" + arg.subId); |
| 13737 | |
| 13738 | Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13739 | if (callback == null) { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13740 | loge("handleEventProvisionSatelliteServiceDone: callback is null for subId=" |
| 13741 | + arg.subId); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13742 | return; |
| 13743 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13744 | callback.accept(result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13745 | |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13746 | if (result == SatelliteManager.SATELLITE_ERROR_NONE) { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13747 | setSatelliteProvisioned(arg.subId, true); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13748 | } |
| 13749 | |
| 13750 | /** |
| 13751 | * We need to update satellite provision status in SubscriptionController |
| 13752 | * or SatelliteController. |
| 13753 | * TODO (b/267826133) we need to do this for all subscriptions on the device. |
| 13754 | */ |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13755 | registerForSatelliteProvisionStateChangedInternal(arg.subId, null); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13756 | } |
| 13757 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13758 | private void handleEventDeprovisionSatelliteServiceDone( |
| 13759 | @NonNull ProvisionSatelliteServiceArgument arg, |
| 13760 | @SatelliteManager.SatelliteError int result) { |
| 13761 | if (arg == null) { |
| 13762 | loge("handleEventDeprovisionSatelliteServiceDone: arg is null"); |
| 13763 | return; |
| 13764 | } |
| 13765 | log("handleEventDeprovisionSatelliteServiceDone: result=" |
| 13766 | + result + ", subId=" + arg.subId); |
| 13767 | |
| 13768 | if (arg.callback != null) { |
| 13769 | arg.callback.accept(result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13770 | } |
| 13771 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13772 | if (result == SatelliteManager.SATELLITE_ERROR_NONE) { |
| 13773 | setSatelliteProvisioned(arg.subId, false); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13774 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13775 | } |
| 13776 | |
| 13777 | private Phone getPhoneOrDefault(int subId, String caller) { |
| 13778 | Phone phone = getPhone(subId); |
| 13779 | if (phone == null) { |
| 13780 | loge(caller + " called with invalid subId: " + subId |
| 13781 | + ". Retrying with default phone."); |
| 13782 | phone = getDefaultPhone(); |
| 13783 | if (phone == null) { |
| 13784 | loge(caller + " failed with no phone object."); |
| 13785 | } |
| 13786 | } |
| 13787 | return phone; |
| 13788 | } |
| 13789 | |
| 13790 | /** |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13791 | * Check if satellite is provisioned for a subscription or the device. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13792 | * |
| 13793 | * Note: this is the version without permission check for telephony internal use only. The |
| 13794 | * caller need to take care of the permission check. |
| 13795 | */ |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13796 | private boolean isSatelliteProvisioned(int subId) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13797 | if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 13798 | if (mSubscriptionController == null) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13799 | loge("isSatelliteProvisioned mSubscriptionController is null"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13800 | return false; |
| 13801 | } |
| 13802 | |
| 13803 | String strResult = mSubscriptionController.getSubscriptionProperty( |
| 13804 | subId, SubscriptionManager.SATELLITE_ENABLED); |
| 13805 | if (strResult != null) { |
| 13806 | int intResult = Integer.parseInt(strResult); |
| 13807 | return (intResult == 1) ? true : false; |
| 13808 | } |
| 13809 | } else { |
| 13810 | //TODO (b/267826133): check via SatelliteController |
| 13811 | } |
| 13812 | return false; |
| 13813 | } |
| 13814 | |
| 13815 | /** |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13816 | * Set satellite provisioned for a subscription or the device. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13817 | * |
| 13818 | * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by |
| 13819 | * {@link SubscriptionController} when setting satellite enabled for an active subscription. |
| 13820 | * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced. |
| 13821 | */ |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13822 | private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13823 | if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 13824 | if (mSubscriptionController == null) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13825 | loge("setSatelliteProvisioned mSubscriptionController is null"); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13826 | return; |
| 13827 | } |
| 13828 | mSubscriptionController.setSubscriptionProperty( |
| 13829 | subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0"); |
| 13830 | } else { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13831 | //TODO (b/267826133): set via SatelliteController |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13832 | } |
| 13833 | } |
| 13834 | |
| 13835 | private int getValidSatelliteSubId(int subId) { |
| 13836 | if (mSubscriptionController == null) { |
| 13837 | loge("getValidSatelliteSubId mSubscriptionController is null. " |
| 13838 | + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId); |
| 13839 | return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
| 13840 | } |
| 13841 | final long identity = Binder.clearCallingIdentity(); |
| 13842 | try { |
| 13843 | Context context = getDefaultPhone().getContext(); |
| 13844 | if (mSubscriptionController.isActiveSubId( |
| 13845 | subId, context.getOpPackageName(), context.getAttributionTag())) { |
| 13846 | return subId; |
| 13847 | } |
| 13848 | } finally { |
| 13849 | Binder.restoreCallingIdentity(identity); |
| 13850 | } |
| 13851 | if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId); |
| 13852 | return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
| 13853 | } |
| 13854 | |
| 13855 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13856 | * If we have not successfully queried the satellite modem for its satellite service support, |
| 13857 | * we will retry the query one more time. Otherwise, we will return the queried result. |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13858 | */ |
| 13859 | private boolean isSatelliteSupported() { |
| 13860 | synchronized (mIsSatelliteSupportedLock) { |
| 13861 | if (mIsSatelliteSupported != null) { |
| 13862 | /* We have already successfully queried the satellite modem. */ |
| 13863 | return mIsSatelliteSupported; |
| 13864 | } |
| 13865 | } |
| 13866 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13867 | * We have not successfully checked whether the modem supports satellite service. |
| 13868 | * Thus, we need to retry it now. |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13869 | */ |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13870 | requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
| 13871 | mSatelliteSupportedReceiver); |
| 13872 | return false; |
| 13873 | } |
| 13874 | |
| 13875 | /** |
| 13876 | * Get the {@link SatelliteManager.SatelliteError} from the provided result. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13877 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13878 | * @param ar AsyncResult used to determine the error code. |
| 13879 | * @param caller The satellite request. |
| 13880 | * @param checkResult Whether to check if the result exists. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13881 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13882 | * @return The {@link SatelliteManager.SatelliteError} error code from the request. |
| 13883 | */ |
| 13884 | @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar, |
| 13885 | @NonNull String caller, boolean checkResult) { |
| 13886 | int errorCode; |
| 13887 | if (ar.exception == null) { |
| 13888 | errorCode = SatelliteManager.SATELLITE_ERROR_NONE; |
| 13889 | if (checkResult && ar.result == null) { |
| 13890 | loge(caller + ": result is null"); |
| 13891 | errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE; |
| 13892 | } |
| 13893 | } else { |
| 13894 | errorCode = SatelliteManager.SATELLITE_ERROR; |
| 13895 | if (ar.exception instanceof CommandException) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 13896 | CommandException.Error error = ((CommandException) ar.exception).getCommandError(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13897 | errorCode = RILUtils.convertToSatelliteError(error); |
| 13898 | loge(caller + " CommandException: " + ar.exception); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 13899 | } else if (ar.exception instanceof SatelliteManager.SatelliteException) { |
| 13900 | errorCode = ((SatelliteManager.SatelliteException) ar.exception).getErrorCode(); |
| 13901 | loge(caller + " SatelliteException: " + ar.exception); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13902 | } else { |
| 13903 | loge(caller + " unknown exception: " + ar.exception); |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13904 | } |
| 13905 | } |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13906 | log(caller + " error: " + errorCode); |
| 13907 | return errorCode; |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13908 | } |
| 13909 | |
| 13910 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13911 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13912 | * |
| 13913 | * @param subId The subId of the subscription associated with the satellite service. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13914 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13915 | * |
| 13916 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13917 | */ |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13918 | @SatelliteManager.SatelliteError private int registerForSatelliteProvisionStateChangedInternal( |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13919 | int subId, @Nullable ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13920 | if (!isSatelliteSupported()) { |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13921 | return SatelliteManager.SATELLITE_NOT_SUPPORTED; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13922 | } |
| 13923 | |
| 13924 | final int validSubId = getValidSatelliteSubId(subId); |
| 13925 | Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged"); |
| 13926 | if (phone == null) { |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13927 | return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13928 | } |
| 13929 | |
| 13930 | SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler = |
| 13931 | mSatelliteProvisionStateChangedHandlers.get(validSubId); |
| 13932 | if (satelliteProvisionStateChangedHandler == null) { |
| 13933 | satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler( |
| 13934 | Looper.getMainLooper(), validSubId); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13935 | if (mIsSatelliteServiceSupported) { |
| 13936 | mSatelliteServiceController.registerForSatelliteProvisionStateChanged( |
| 13937 | satelliteProvisionStateChangedHandler, |
| 13938 | SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null); |
| 13939 | } else { |
| 13940 | phone.registerForSatelliteProvisionStateChanged( |
| 13941 | satelliteProvisionStateChangedHandler, |
| 13942 | SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null); |
| 13943 | } |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13944 | } |
| 13945 | |
| 13946 | if (callback != null) { |
| 13947 | satelliteProvisionStateChangedHandler.addListener(callback); |
| 13948 | } |
| 13949 | mSatelliteProvisionStateChangedHandlers.put( |
| 13950 | validSubId, satelliteProvisionStateChangedHandler); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13951 | return SatelliteManager.SATELLITE_ERROR_NONE; |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13952 | } |
| 13953 | |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13954 | private void handleStartSatellitePositionUpdatesDone(@NonNull AsyncResult ar) { |
| 13955 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 13956 | SatellitePositionUpdateArgument arg = (SatellitePositionUpdateArgument) request.argument; |
| 13957 | int errorCode = getSatelliteError( |
| 13958 | ar, "handleStartSatellitePositionUpdatesDone", false); |
| 13959 | arg.errorCallback.accept(errorCode); |
| 13960 | |
| 13961 | if (errorCode != SatelliteManager.SATELLITE_ERROR_NONE) { |
| 13962 | /** |
| 13963 | * We need to remove the callback from our listener list since the caller might not call |
| 13964 | * {@link #stopSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)} |
| 13965 | * to unregister the callback in case of failure. |
| 13966 | */ |
| 13967 | SatellitePositionUpdateHandler handler = |
| 13968 | mSatellitePositionUpdateHandlers.get(arg.subId); |
| 13969 | if (handler != null) { |
| 13970 | handler.removeListener(arg.callback); |
| 13971 | |
| 13972 | if (!handler.hasListeners()) { |
| 13973 | mSatellitePositionUpdateHandlers.remove(arg.subId); |
| 13974 | |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13975 | if (mIsSatelliteServiceSupported) { |
| 13976 | mSatelliteServiceController.unregisterForSatellitePositionInfoChanged( |
| 13977 | handler); |
| 13978 | mSatelliteServiceController.unregisterForDatagramTransferStateChanged( |
| 13979 | handler); |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13980 | } else { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13981 | Phone phone = getPhoneFromRequest(request); |
| 13982 | if (phone == null) { |
| 13983 | loge("handleStartSatellitePositionUpdatesDone: phone is null"); |
| 13984 | } else { |
| 13985 | phone.unregisterForSatellitePositionInfoChanged(handler); |
| 13986 | // TODO: unregisterForDatagramTransferStateChanged through |
| 13987 | // SatelliteController |
| 13988 | } |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13989 | } |
| 13990 | } |
| 13991 | } |
| 13992 | } |
| 13993 | } |
| 13994 | |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13995 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13996 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 13997 | * |
| 13998 | * <p>This method behaves in one of the following ways: |
| 13999 | * <ul> |
| 14000 | * <li>return true : if the calling package has the appop permission {@link |
| 14001 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14002 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14003 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14004 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14005 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14006 | * </ul> |
| 14007 | */ |
| 14008 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14009 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14010 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14011 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14012 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14013 | return true; |
| 14014 | } |
| 14015 | } |
| 14016 | return false; |
| 14017 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14018 | |
| 14019 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14020 | * @return The subscription manager service instance. |
| 14021 | */ |
| 14022 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14023 | return SubscriptionManagerService.getInstance(); |
| 14024 | } |
| 14025 | |
| 14026 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14027 | * Class binds the consumer[callback] and carrierId. |
| 14028 | */ |
| 14029 | private static class CallerCallbackInfo { |
| 14030 | private final Consumer<Integer> mConsumer; |
| 14031 | private final int mCarrierId; |
| 14032 | |
| 14033 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 14034 | mConsumer = consumer; |
| 14035 | mCarrierId = carrierId; |
| 14036 | } |
| 14037 | |
| 14038 | public Consumer<Integer> getConsumer() { |
| 14039 | return mConsumer; |
| 14040 | } |
| 14041 | |
| 14042 | public int getCarrierId() { |
| 14043 | return mCarrierId; |
| 14044 | } |
| 14045 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14046 | } |