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; |
| 54 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 56 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 57 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.os.Looper; |
| 59 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 60 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 61 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 62 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 63 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 64 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 65 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 66 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 67 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 68 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 69 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 70 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 71 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 72 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 73 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 74 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 75 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 76 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 77 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 78 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 79 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 80 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 81 | import android.telephony.AccessNetworkConstants; |
| 82 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 83 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 84 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 85 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 86 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 87 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 88 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 89 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 90 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 91 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 92 | import android.telephony.CellIdentityCdma; |
| 93 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 94 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 95 | import android.telephony.CellInfoGsm; |
| 96 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 97 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 98 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 99 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 100 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 101 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 102 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 103 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 104 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 105 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 106 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 107 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 108 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 109 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 111 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 112 | import android.telephony.SignalStrengthUpdateRequest; |
| 113 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 114 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 115 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 116 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 117 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 118 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 119 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 120 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 121 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 122 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 123 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 124 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 125 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 126 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 127 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 128 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 129 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 130 | import android.telephony.gba.GbaAuthRequest; |
| 131 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 132 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 133 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 134 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 135 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 136 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 137 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 144 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 145 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 146 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 147 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 148 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 149 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 150 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 151 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 152 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 153 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 154 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 157 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 158 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 160 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 161 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 162 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 163 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 164 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 165 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 180 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.IIntegerConsumer; |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 182 | import com.android.internal.telephony.ILongConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 198 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 201 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 205 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 206 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 208 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 213 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 214 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 215 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 216 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 217 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 218 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.uicc.IccIoResult; |
| 221 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 222 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 224 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 225 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 227 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 229 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 230 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 231 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 232 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 233 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 234 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 235 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 236 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 237 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 238 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 239 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 240 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 241 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 242 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 243 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 244 | import com.android.services.telephony.TelecomAccountRegistry; |
| 245 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 246 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 247 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 248 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 249 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 250 | import java.io.IOException; |
| 251 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 252 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 254 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 255 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 256 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 257 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 258 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 259 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 260 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 261 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 262 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 263 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 264 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 265 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 266 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 267 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 268 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 | |
| 270 | /** |
| 271 | * Implementation of the ITelephony interface. |
| 272 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 273 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 275 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 276 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 277 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 278 | |
| 279 | // Message codes used with mMainThreadHandler |
| 280 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 281 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 282 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 283 | private static final int CMD_OPEN_CHANNEL = 9; |
| 284 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 285 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 286 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 287 | private static final int CMD_NV_READ_ITEM = 13; |
| 288 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 289 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 290 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 291 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 292 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 293 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 294 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 295 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 296 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 297 | private static final int CMD_SEND_ENVELOPE = 25; |
| 298 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 299 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 300 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 301 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 302 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 303 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 304 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 305 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 306 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 307 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 308 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 309 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 310 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 311 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 312 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 313 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 314 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 315 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 316 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 317 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 318 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 319 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 320 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 321 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 322 | private static final int CMD_SWITCH_SLOTS = 50; |
| 323 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 324 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 325 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 326 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 327 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 328 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 329 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 330 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 331 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 332 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 333 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 334 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 335 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 336 | private static final int CMD_MODEM_REBOOT = 64; |
| 337 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 338 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 339 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 340 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 341 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 342 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 343 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 344 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 345 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 346 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 347 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 348 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 349 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 350 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 351 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 352 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 353 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 354 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 355 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 356 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 357 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 358 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 359 | private static final int CMD_GET_CALL_WAITING = 87; |
| 360 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 361 | private static final int CMD_SET_CALL_WAITING = 89; |
| 362 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 363 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 364 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 365 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 366 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 367 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 368 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 369 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 370 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 371 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 372 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 373 | private static final int CMD_SET_SIM_POWER = 101; |
| 374 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 375 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 376 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 377 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 378 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 379 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 380 | 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] | 381 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 382 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 383 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 384 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 385 | private static final int CMD_ENABLE_VONR = 113; |
| 386 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 387 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 388 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 389 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 390 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 391 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 392 | // Parameters of select command. |
| 393 | private static final int SELECT_COMMAND = 0xA4; |
| 394 | private static final int SELECT_P1 = 0x04; |
| 395 | private static final int SELECT_P2 = 0; |
| 396 | private static final int SELECT_P3 = 0x10; |
| 397 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 398 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 399 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 400 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 401 | /** The singleton instance. */ |
| 402 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 403 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 404 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 405 | private final PhoneGlobals mApp; |
| 406 | private final CallManager mCM; |
| 407 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 408 | |
| 409 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 410 | private final UserManager mUserManager; |
| 411 | private final AppOpsManager mAppOps; |
| 412 | private final MainThreadHandler mMainThreadHandler; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 413 | private final SubscriptionController mSubscriptionController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 414 | private final SharedPreferences mTelephonySharedPreferences; |
| 415 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 416 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 418 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 419 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 420 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 421 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 422 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 423 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 424 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 425 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 426 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 427 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 428 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 429 | // String to store multi SIM allowed |
| 430 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 431 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 432 | // The AID of ISD-R. |
| 433 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 434 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 435 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 436 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 437 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 438 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 439 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 440 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 441 | 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] | 442 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 443 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 444 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 445 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 446 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 447 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 448 | */ |
| 449 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 450 | "reset_network_erase_modem_config_enabled"; |
| 451 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 452 | 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] | 453 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 454 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 455 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 456 | /** |
| 457 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 458 | * one ICCID active at the same time. |
| 459 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 460 | * |
| 461 | * @hide |
| 462 | */ |
| 463 | @ChangeId |
| 464 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 465 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 466 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 467 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 468 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 469 | * operation fails. |
| 470 | */ |
| 471 | @ChangeId |
| 472 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 473 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 474 | |
| 475 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 476 | * A request object to use for transmitting data to an ICC. |
| 477 | */ |
| 478 | private static final class IccAPDUArgument { |
| 479 | public int channel, cla, command, p1, p2, p3; |
| 480 | public String data; |
| 481 | |
| 482 | public IccAPDUArgument(int channel, int cla, int command, |
| 483 | int p1, int p2, int p3, String data) { |
| 484 | this.channel = channel; |
| 485 | this.cla = cla; |
| 486 | this.command = command; |
| 487 | this.p1 = p1; |
| 488 | this.p2 = p2; |
| 489 | this.p3 = p3; |
| 490 | this.data = data; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 495 | * A request object to use for transmitting data to an ICC. |
| 496 | */ |
| 497 | private static final class ManualNetworkSelectionArgument { |
| 498 | public OperatorInfo operatorInfo; |
| 499 | public boolean persistSelection; |
| 500 | |
| 501 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 502 | this.operatorInfo = operatorInfo; |
| 503 | this.persistSelection = persistSelection; |
| 504 | } |
| 505 | } |
| 506 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 507 | private static final class PurchasePremiumCapabilityArgument { |
| 508 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 509 | public @NonNull IIntegerConsumer callback; |
| 510 | |
| 511 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 512 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 513 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 514 | this.callback = callback; |
| 515 | } |
| 516 | } |
| 517 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 518 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 519 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 520 | * request after sending. The main thread will notify the request when it is complete. |
| 521 | */ |
| 522 | private static final class MainThreadRequest { |
| 523 | /** The argument to use for the request */ |
| 524 | public Object argument; |
| 525 | /** The result of the request that is run on the main thread */ |
| 526 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 527 | // The subscriber id that this request applies to. Defaults to |
| 528 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 529 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 530 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 531 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 532 | public Phone phone; |
| 533 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 534 | public WorkSource workSource; |
| 535 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 536 | public MainThreadRequest(Object argument) { |
| 537 | this.argument = argument; |
| 538 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 539 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 540 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 541 | this.argument = argument; |
| 542 | if (phone != null) { |
| 543 | this.phone = phone; |
| 544 | } |
| 545 | this.workSource = workSource; |
| 546 | } |
| 547 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 548 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 549 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 550 | if (subId != null) { |
| 551 | this.subId = subId; |
| 552 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 553 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 554 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 557 | private static final class IncomingThirdPartyCallArgs { |
| 558 | public final ComponentName component; |
| 559 | public final String callId; |
| 560 | public final String callerDisplayName; |
| 561 | |
| 562 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 563 | String callerDisplayName) { |
| 564 | this.component = component; |
| 565 | this.callId = callId; |
| 566 | this.callerDisplayName = callerDisplayName; |
| 567 | } |
| 568 | } |
| 569 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 570 | /** |
| 571 | * A handler that processes messages on the main thread in the phone process. Since many |
| 572 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 573 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 574 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 575 | * on, which will be notified when the operation completes and will contain the result of the |
| 576 | * request. |
| 577 | * |
| 578 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 579 | * note that request.result must be set to something non-null for the calling thread to |
| 580 | * unblock. |
| 581 | */ |
| 582 | private final class MainThreadHandler extends Handler { |
| 583 | @Override |
| 584 | public void handleMessage(Message msg) { |
| 585 | MainThreadRequest request; |
| 586 | Message onCompleted; |
| 587 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 588 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 589 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 590 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 591 | |
| 592 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | case CMD_HANDLE_USSD_REQUEST: { |
| 594 | request = (MainThreadRequest) msg.obj; |
| 595 | final Phone phone = getPhoneFromRequest(request); |
| 596 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 597 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 598 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 599 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 600 | if (!isUssdApiAllowed(request.subId)) { |
| 601 | // Carrier does not support use of this API, return failure. |
| 602 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 603 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 604 | Bundle returnData = new Bundle(); |
| 605 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 606 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 607 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 608 | request.result = true; |
| 609 | notifyRequester(request); |
| 610 | return; |
| 611 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 612 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 613 | try { |
| 614 | request.result = phone != null |
| 615 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 616 | } catch (CallStateException cse) { |
| 617 | request.result = false; |
| 618 | } |
| 619 | // Wake up the requesting thread |
| 620 | notifyRequester(request); |
| 621 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 624 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 625 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 626 | final Phone phone = getPhoneFromRequest(request); |
| 627 | request.result = phone != null ? |
| 628 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 629 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 630 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 631 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 632 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 633 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 634 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 635 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 638 | uiccPort = getUiccPortFromRequest(request); |
| 639 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 640 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 641 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 642 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 643 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 645 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 646 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 647 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 648 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 649 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 650 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | break; |
| 652 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 653 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | ar = (AsyncResult) msg.obj; |
| 655 | request = (MainThreadRequest) ar.userObj; |
| 656 | if (ar.exception == null && ar.result != null) { |
| 657 | request.result = ar.result; |
| 658 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 659 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | if (ar.result == null) { |
| 661 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 664 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | } else { |
| 666 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 667 | } |
| 668 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 669 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | break; |
| 671 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 673 | request = (MainThreadRequest) msg.obj; |
| 674 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 675 | uiccPort = getUiccPortFromRequest(request); |
| 676 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 677 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 678 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 679 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | } else { |
| 681 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 683 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 684 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 685 | iccArgument.p2, |
| 686 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 687 | } |
| 688 | break; |
| 689 | |
| 690 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 691 | ar = (AsyncResult) msg.obj; |
| 692 | request = (MainThreadRequest) ar.userObj; |
| 693 | if (ar.exception == null && ar.result != null) { |
| 694 | request.result = ar.result; |
| 695 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 696 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 697 | if (ar.result == null) { |
| 698 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 699 | } else if (ar.exception instanceof CommandException) { |
| 700 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 701 | ar.exception); |
| 702 | } else { |
| 703 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 704 | } |
| 705 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 706 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | break; |
| 708 | |
| 709 | case CMD_EXCHANGE_SIM_IO: |
| 710 | request = (MainThreadRequest) msg.obj; |
| 711 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 712 | uiccPort = getUiccPortFromRequest(request); |
| 713 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 714 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 715 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 717 | } else { |
| 718 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 719 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 720 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 721 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 722 | iccArgument.data, onCompleted); |
| 723 | } |
| 724 | break; |
| 725 | |
| 726 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 727 | ar = (AsyncResult) msg.obj; |
| 728 | request = (MainThreadRequest) ar.userObj; |
| 729 | if (ar.exception == null && ar.result != null) { |
| 730 | request.result = ar.result; |
| 731 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 732 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 733 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 734 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 735 | break; |
| 736 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 737 | case CMD_SEND_ENVELOPE: |
| 738 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 739 | uiccPort = getUiccPortFromRequest(request); |
| 740 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 741 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 742 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 744 | } else { |
| 745 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 746 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 747 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case EVENT_SEND_ENVELOPE_DONE: |
| 751 | ar = (AsyncResult) msg.obj; |
| 752 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 753 | if (ar.exception == null && ar.result != null) { |
| 754 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 755 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 756 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 757 | if (ar.result == null) { |
| 758 | loge("sendEnvelopeWithStatus: Empty response"); |
| 759 | } else if (ar.exception instanceof CommandException) { |
| 760 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 761 | ar.exception); |
| 762 | } else { |
| 763 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 764 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 765 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 767 | break; |
| 768 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 769 | case CMD_OPEN_CHANNEL: |
| 770 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 771 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 772 | IccLogicalChannelRequest openChannelRequest = |
| 773 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 774 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 775 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 776 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 777 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 778 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 779 | } else { |
| 780 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 781 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 782 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 783 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 784 | break; |
| 785 | |
| 786 | case EVENT_OPEN_CHANNEL_DONE: |
| 787 | ar = (AsyncResult) msg.obj; |
| 788 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 789 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 790 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 791 | int[] result = (int[]) ar.result; |
| 792 | int channelId = result[0]; |
| 793 | byte[] selectResponse = null; |
| 794 | if (result.length > 1) { |
| 795 | selectResponse = new byte[result.length - 1]; |
| 796 | for (int i = 1; i < result.length; ++i) { |
| 797 | selectResponse[i - 1] = (byte) result[i]; |
| 798 | } |
| 799 | } |
| 800 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 801 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 802 | |
| 803 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 804 | if (uiccPort == null) { |
| 805 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 806 | } else { |
| 807 | IccLogicalChannelRequest channelRequest = |
| 808 | (IccLogicalChannelRequest) request.argument; |
| 809 | channelRequest.channel = channelId; |
| 810 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 811 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 812 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 813 | if (ar.result == null) { |
| 814 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 815 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 816 | if (ar.exception != null) { |
| 817 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 818 | } |
| 819 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 820 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 821 | if (ar.exception instanceof CommandException) { |
| 822 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 823 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 824 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 825 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 826 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 827 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 831 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 832 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 833 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 834 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 835 | break; |
| 836 | |
| 837 | case CMD_CLOSE_CHANNEL: |
| 838 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 839 | uiccPort = getUiccPortFromRequest(request); |
| 840 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 841 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 842 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 843 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 844 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 845 | } else { |
| 846 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 847 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 848 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 852 | ar = (AsyncResult) msg.obj; |
| 853 | request = (MainThreadRequest) ar.userObj; |
| 854 | if (ar.exception == null) { |
| 855 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 856 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 857 | if (uiccPort == null) { |
| 858 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 859 | } else { |
| 860 | final int channelId = (Integer) request.argument; |
| 861 | uiccPort.onLogicalChannelClosed(channelId); |
| 862 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 863 | } else { |
| 864 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 865 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 866 | if (ar.exception instanceof CommandException) { |
| 867 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 868 | CommandException.Error error = |
| 869 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 870 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 871 | // should only throw exceptions from the binder threads. |
| 872 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 873 | "iccCloseLogicalChannel: invalid argument "); |
| 874 | } |
| 875 | } else { |
| 876 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 877 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 878 | request.result = (exception != null) ? exception : |
| 879 | new IllegalStateException( |
| 880 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 881 | } |
| 882 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 883 | break; |
| 884 | |
| 885 | case CMD_NV_READ_ITEM: |
| 886 | request = (MainThreadRequest) msg.obj; |
| 887 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 888 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 889 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 890 | break; |
| 891 | |
| 892 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 893 | ar = (AsyncResult) msg.obj; |
| 894 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 895 | if (ar.exception == null && ar.result != null) { |
| 896 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 897 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 898 | request.result = ""; |
| 899 | if (ar.result == null) { |
| 900 | loge("nvReadItem: Empty response"); |
| 901 | } else if (ar.exception instanceof CommandException) { |
| 902 | loge("nvReadItem: CommandException: " + |
| 903 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 904 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 905 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 906 | } |
| 907 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 908 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 909 | break; |
| 910 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 911 | case CMD_NV_WRITE_ITEM: |
| 912 | request = (MainThreadRequest) msg.obj; |
| 913 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 914 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 915 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 916 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case EVENT_NV_WRITE_ITEM_DONE: |
| 920 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 921 | break; |
| 922 | |
| 923 | case CMD_NV_WRITE_CDMA_PRL: |
| 924 | request = (MainThreadRequest) msg.obj; |
| 925 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 926 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 927 | break; |
| 928 | |
| 929 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 930 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 931 | break; |
| 932 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 933 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 934 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 935 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 936 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 937 | break; |
| 938 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 939 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 940 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 941 | break; |
| 942 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 943 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 944 | request = (MainThreadRequest) msg.obj; |
| 945 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 946 | request); |
| 947 | Phone phone = getPhoneFromRequest(request); |
| 948 | if (phone != null) { |
| 949 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 950 | } else { |
| 951 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 952 | request.result = false; |
| 953 | notifyRequester(request); |
| 954 | } |
| 955 | break; |
| 956 | } |
| 957 | |
| 958 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 959 | ar = (AsyncResult) msg.obj; |
| 960 | request = (MainThreadRequest) ar.userObj; |
| 961 | if (ar.exception == null && ar.result != null) { |
| 962 | request.result = ar.result; |
| 963 | } else { |
| 964 | // request.result must be set to something non-null |
| 965 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 966 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 967 | request.result = ar.result; |
| 968 | } else { |
| 969 | request.result = false; |
| 970 | } |
| 971 | if (ar.result == null) { |
| 972 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 973 | } else if (ar.exception instanceof CommandException) { |
| 974 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 975 | + ar.exception); |
| 976 | } else { |
| 977 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 978 | } |
| 979 | } |
| 980 | notifyRequester(request); |
| 981 | break; |
| 982 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 983 | case CMD_IS_VONR_ENABLED: { |
| 984 | request = (MainThreadRequest) msg.obj; |
| 985 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 986 | request); |
| 987 | Phone phone = getPhoneFromRequest(request); |
| 988 | if (phone != null) { |
| 989 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 990 | } else { |
| 991 | loge("isVoNrEnabled: No phone object"); |
| 992 | request.result = false; |
| 993 | notifyRequester(request); |
| 994 | } |
| 995 | break; |
| 996 | } |
| 997 | |
| 998 | case EVENT_IS_VONR_ENABLED_DONE: |
| 999 | ar = (AsyncResult) msg.obj; |
| 1000 | request = (MainThreadRequest) ar.userObj; |
| 1001 | if (ar.exception == null && ar.result != null) { |
| 1002 | request.result = ar.result; |
| 1003 | } else { |
| 1004 | // request.result must be set to something non-null |
| 1005 | // for the calling thread to unblock |
| 1006 | if (ar.result != null) { |
| 1007 | request.result = ar.result; |
| 1008 | } else { |
| 1009 | request.result = false; |
| 1010 | } |
| 1011 | if (ar.result == null) { |
| 1012 | loge("isVoNrEnabled: Empty response"); |
| 1013 | } else if (ar.exception instanceof CommandException) { |
| 1014 | loge("isVoNrEnabled: CommandException: " |
| 1015 | + ar.exception); |
| 1016 | } else { |
| 1017 | loge("isVoNrEnabled: Unknown exception"); |
| 1018 | } |
| 1019 | } |
| 1020 | notifyRequester(request); |
| 1021 | break; |
| 1022 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1023 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1024 | request = (MainThreadRequest) msg.obj; |
| 1025 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1026 | Phone phone = getPhoneFromRequest(request); |
| 1027 | if (phone != null) { |
| 1028 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1029 | request.workSource); |
| 1030 | } else { |
| 1031 | loge("enableNrDualConnectivity: No phone object"); |
| 1032 | request.result = |
| 1033 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1034 | notifyRequester(request); |
| 1035 | } |
| 1036 | break; |
| 1037 | } |
| 1038 | |
| 1039 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1040 | ar = (AsyncResult) msg.obj; |
| 1041 | request = (MainThreadRequest) ar.userObj; |
| 1042 | if (ar.exception == null) { |
| 1043 | request.result = |
| 1044 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1045 | } else { |
| 1046 | request.result = |
| 1047 | TelephonyManager |
| 1048 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1049 | if (ar.exception instanceof CommandException) { |
| 1050 | CommandException.Error error = |
| 1051 | ((CommandException) (ar.exception)).getCommandError(); |
| 1052 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1053 | request.result = |
| 1054 | TelephonyManager |
| 1055 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1056 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1057 | request.result = |
| 1058 | TelephonyManager |
| 1059 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1060 | } |
| 1061 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1062 | + ar.exception); |
| 1063 | } else { |
| 1064 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1065 | } |
| 1066 | } |
| 1067 | notifyRequester(request); |
| 1068 | break; |
| 1069 | } |
| 1070 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1071 | case CMD_ENABLE_VONR: { |
| 1072 | request = (MainThreadRequest) msg.obj; |
| 1073 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1074 | Phone phone = getPhoneFromRequest(request); |
| 1075 | if (phone != null) { |
| 1076 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1077 | request.workSource); |
| 1078 | } else { |
| 1079 | loge("setVoNrEnabled: No phone object"); |
| 1080 | request.result = |
| 1081 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1082 | notifyRequester(request); |
| 1083 | } |
| 1084 | break; |
| 1085 | } |
| 1086 | |
| 1087 | case EVENT_ENABLE_VONR_DONE: { |
| 1088 | ar = (AsyncResult) msg.obj; |
| 1089 | request = (MainThreadRequest) ar.userObj; |
| 1090 | if (ar.exception == null) { |
| 1091 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1092 | } else { |
| 1093 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1094 | if (ar.exception instanceof CommandException) { |
| 1095 | CommandException.Error error = |
| 1096 | ((CommandException) (ar.exception)).getCommandError(); |
| 1097 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1098 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1099 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1100 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1101 | } else { |
| 1102 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1103 | } |
| 1104 | loge("setVoNrEnabled" + ": CommandException: " |
| 1105 | + ar.exception); |
| 1106 | } else { |
| 1107 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1108 | } |
| 1109 | } |
| 1110 | notifyRequester(request); |
| 1111 | break; |
| 1112 | } |
| 1113 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1114 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1115 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1116 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1117 | request); |
| 1118 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1119 | break; |
| 1120 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1121 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1122 | ar = (AsyncResult) msg.obj; |
| 1123 | request = (MainThreadRequest) ar.userObj; |
| 1124 | if (ar.exception == null && ar.result != null) { |
| 1125 | request.result = ar.result; // Integer |
| 1126 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1127 | // request.result must be set to something non-null |
| 1128 | // for the calling thread to unblock |
| 1129 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1130 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1131 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1132 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1133 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1134 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1135 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1136 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1137 | } |
| 1138 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1139 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1140 | break; |
| 1141 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1142 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1143 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1144 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1145 | request); |
| 1146 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1147 | (Pair<Integer, Long>) request.argument; |
| 1148 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1149 | reasonWithNetworkTypes.first, |
| 1150 | reasonWithNetworkTypes.second, |
| 1151 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1152 | break; |
| 1153 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1154 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1155 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1156 | break; |
| 1157 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1158 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1159 | request = (MainThreadRequest)msg.obj; |
| 1160 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1161 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1162 | break; |
| 1163 | |
| 1164 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1165 | ar = (AsyncResult)msg.obj; |
| 1166 | request = (MainThreadRequest)ar.userObj; |
| 1167 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1168 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1169 | break; |
| 1170 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1171 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1172 | request = (MainThreadRequest) msg.obj; |
| 1173 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1174 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1175 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1176 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1177 | break; |
| 1178 | |
| 1179 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1180 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1181 | break; |
| 1182 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1183 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1184 | request = (MainThreadRequest) msg.obj; |
| 1185 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1186 | request); |
| 1187 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1188 | break; |
| 1189 | |
| 1190 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1191 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1192 | break; |
| 1193 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1194 | case CMD_PERFORM_NETWORK_SCAN: |
| 1195 | request = (MainThreadRequest) msg.obj; |
| 1196 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1197 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1198 | break; |
| 1199 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1200 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | request = (MainThreadRequest) msg.obj; |
| 1202 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1203 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1204 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1205 | request.argument; |
| 1206 | int callForwardingReason = args.first; |
| 1207 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1208 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | } |
| 1210 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | ar = (AsyncResult) msg.obj; |
| 1212 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1214 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1215 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1217 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1219 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1220 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1221 | // any service for voice call. |
| 1222 | if ((callForwardInfo.serviceClass |
| 1223 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1224 | callForwardingInfo = new CallForwardingInfo( |
| 1225 | callForwardInfo.status |
| 1226 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | callForwardInfo.reason, |
| 1228 | callForwardInfo.number, |
| 1229 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | break; |
| 1231 | } |
| 1232 | } |
| 1233 | // Didn't find a call forward info for voice call. |
| 1234 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1235 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1236 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1238 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | } else { |
| 1240 | if (ar.result == null) { |
| 1241 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1242 | } |
| 1243 | if (ar.exception != null) { |
| 1244 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1245 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1246 | int errorCode = TelephonyManager |
| 1247 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | if (ar.exception instanceof CommandException) { |
| 1249 | CommandException.Error error = |
| 1250 | ((CommandException) (ar.exception)).getCommandError(); |
| 1251 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1252 | errorCode = TelephonyManager |
| 1253 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1255 | errorCode = TelephonyManager |
| 1256 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | } |
| 1258 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1259 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1262 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1265 | request = (MainThreadRequest) msg.obj; |
| 1266 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1267 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1270 | request.argument).first; |
| 1271 | request.phone.setCallForwardingOption( |
| 1272 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1273 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | callForwardingInfoToSet.getReason(), |
| 1276 | callForwardingInfoToSet.getNumber(), |
| 1277 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1278 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1279 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | ar = (AsyncResult) msg.obj; |
| 1283 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | Consumer<Integer> callback = |
| 1285 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1286 | request.argument).second; |
| 1287 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1288 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1289 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1290 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1291 | if (ar.exception instanceof CommandException) { |
| 1292 | CommandException.Error error = |
| 1293 | ((CommandException) (ar.exception)).getCommandError(); |
| 1294 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1295 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1296 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1297 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1298 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1299 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | callback.accept(errorCode); |
| 1303 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1304 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | request = (MainThreadRequest) msg.obj; |
| 1311 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1312 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1313 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | ar = (AsyncResult) msg.obj; |
| 1318 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1319 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1320 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1322 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | // Service Class is a bit mask per 3gpp 27.007. |
| 1324 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1325 | if (callForwardResults.length > 1 |
| 1326 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1327 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1328 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1329 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1330 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1332 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | } |
| 1334 | } else { |
| 1335 | if (ar.result == null) { |
| 1336 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1337 | } |
| 1338 | if (ar.exception != null) { |
| 1339 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1340 | } |
| 1341 | if (ar.exception instanceof CommandException) { |
| 1342 | CommandException.Error error = |
| 1343 | ((CommandException) (ar.exception)).getCommandError(); |
| 1344 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1345 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1347 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1348 | callWaitingStatus = |
| 1349 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1353 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1354 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1355 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1357 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1358 | request = (MainThreadRequest) msg.obj; |
| 1359 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1360 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1361 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1362 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1363 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1365 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1366 | ar = (AsyncResult) msg.obj; |
| 1367 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1368 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1369 | Consumer<Integer> callback = |
| 1370 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1371 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1372 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1373 | if (ar.exception instanceof CommandException) { |
| 1374 | CommandException.Error error = |
| 1375 | ((CommandException) (ar.exception)).getCommandError(); |
| 1376 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1377 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1378 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1379 | callback.accept( |
| 1380 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1381 | } else { |
| 1382 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1383 | } |
| 1384 | } else { |
| 1385 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1386 | } |
| 1387 | } else { |
| 1388 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1389 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1390 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1391 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1392 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1393 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1394 | ar = (AsyncResult) msg.obj; |
| 1395 | request = (MainThreadRequest) ar.userObj; |
| 1396 | CellNetworkScanResult cellScanResult; |
| 1397 | if (ar.exception == null && ar.result != null) { |
| 1398 | cellScanResult = new CellNetworkScanResult( |
| 1399 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1400 | (List<OperatorInfo>) ar.result); |
| 1401 | } else { |
| 1402 | if (ar.result == null) { |
| 1403 | loge("getCellNetworkScanResults: Empty response"); |
| 1404 | } |
| 1405 | if (ar.exception != null) { |
| 1406 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1407 | } |
| 1408 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1409 | if (ar.exception instanceof CommandException) { |
| 1410 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1411 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1412 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1413 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1414 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1415 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1416 | } |
| 1417 | } |
| 1418 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1419 | } |
| 1420 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1421 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1422 | break; |
| 1423 | |
| 1424 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1425 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1426 | ManualNetworkSelectionArgument selArg = |
| 1427 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1428 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1429 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1430 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1431 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1432 | break; |
| 1433 | |
| 1434 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1435 | ar = (AsyncResult) msg.obj; |
| 1436 | request = (MainThreadRequest) ar.userObj; |
| 1437 | if (ar.exception == null) { |
| 1438 | request.result = true; |
| 1439 | } else { |
| 1440 | request.result = false; |
| 1441 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1442 | } |
| 1443 | notifyRequester(request); |
| 1444 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1448 | request = (MainThreadRequest) msg.obj; |
| 1449 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1450 | if (defaultPhone != null) { |
| 1451 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1452 | } else { |
| 1453 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1454 | Bundle bundle = new Bundle(); |
| 1455 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1456 | new ModemActivityInfo(0, 0, 0, |
| 1457 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1458 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1459 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1460 | break; |
| 1461 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1462 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1463 | ar = (AsyncResult) msg.obj; |
| 1464 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1465 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1466 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1467 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1468 | if (mLastModemActivityInfo == null) { |
| 1469 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1470 | mLastModemActivitySpecificInfo[0] = |
| 1471 | new ActivityStatsTechSpecificInfo( |
| 1472 | 0, |
| 1473 | 0, |
| 1474 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1475 | 0); |
| 1476 | mLastModemActivityInfo = |
| 1477 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1478 | } |
| 1479 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1480 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1481 | // Update the last modem activity info and the result of the request. |
| 1482 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1483 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1484 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1485 | } else { |
| 1486 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1487 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1488 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1489 | // We don't want to return mLastModemActivityInfo which is updated |
| 1490 | // inside mergeModemActivityInfo() |
| 1491 | ret = new ModemActivityInfo( |
| 1492 | mLastModemActivityInfo.getTimestampMillis(), |
| 1493 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1494 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1495 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1496 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1497 | } else { |
| 1498 | if (ar.result == null) { |
| 1499 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1500 | error = TelephonyManager.ModemActivityInfoException |
| 1501 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1502 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1503 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1504 | error = TelephonyManager.ModemActivityInfoException |
| 1505 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1506 | } else { |
| 1507 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1508 | error = TelephonyManager.ModemActivityInfoException |
| 1509 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1510 | } |
| 1511 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1512 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1513 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1514 | bundle.putParcelable( |
| 1515 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1516 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1517 | } else { |
| 1518 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1519 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1520 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1521 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1522 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1523 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1524 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1525 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1526 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1527 | CarrierRestrictionRules argument = |
| 1528 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1529 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1530 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1531 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1532 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1533 | |
| 1534 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1535 | ar = (AsyncResult) msg.obj; |
| 1536 | request = (MainThreadRequest) ar.userObj; |
| 1537 | if (ar.exception == null && ar.result != null) { |
| 1538 | request.result = ar.result; |
| 1539 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1540 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1541 | if (ar.exception instanceof CommandException) { |
| 1542 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1543 | CommandException.Error error = |
| 1544 | ((CommandException) (ar.exception)).getCommandError(); |
| 1545 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1546 | request.result = |
| 1547 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1548 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1549 | } else { |
| 1550 | loge("setAllowedCarriers: Unknown exception"); |
| 1551 | } |
| 1552 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1553 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1554 | break; |
| 1555 | |
| 1556 | case CMD_GET_ALLOWED_CARRIERS: |
| 1557 | request = (MainThreadRequest) msg.obj; |
| 1558 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1559 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1560 | break; |
| 1561 | |
| 1562 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1563 | ar = (AsyncResult) msg.obj; |
| 1564 | request = (MainThreadRequest) ar.userObj; |
| 1565 | if (ar.exception == null && ar.result != null) { |
| 1566 | request.result = ar.result; |
| 1567 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1568 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1569 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1570 | if (ar.result == null) { |
| 1571 | loge("getAllowedCarriers: Empty response"); |
| 1572 | } else if (ar.exception instanceof CommandException) { |
| 1573 | loge("getAllowedCarriers: CommandException: " + |
| 1574 | ar.exception); |
| 1575 | } else { |
| 1576 | loge("getAllowedCarriers: Unknown exception"); |
| 1577 | } |
| 1578 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1579 | if (request.argument != null) { |
| 1580 | // This is for the implementation of carrierRestrictionStatus. |
| 1581 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1582 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1583 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1584 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1585 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1586 | CarrierRestrictionRules carrierRestrictionRules = |
| 1587 | (CarrierRestrictionRules) ar.result; |
| 1588 | int carrierId = -1; |
| 1589 | try { |
| 1590 | CarrierIdentifier carrierIdentifier = |
| 1591 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1592 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1593 | carrierIdentifier); |
| 1594 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1595 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1596 | } |
| 1597 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1598 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1599 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1600 | lockStatus = TelephonyManager |
| 1601 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1602 | } |
| 1603 | } else { |
| 1604 | Rlog.e(LOG_TAG, |
| 1605 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1606 | } |
| 1607 | callback.accept(lockStatus); |
| 1608 | } else { |
| 1609 | // This is for the implementation of getAllowedCarriers. |
| 1610 | notifyRequester(request); |
| 1611 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1612 | break; |
| 1613 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1614 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1615 | ar = (AsyncResult) msg.obj; |
| 1616 | request = (MainThreadRequest) ar.userObj; |
| 1617 | if (ar.exception == null && ar.result != null) { |
| 1618 | request.result = ar.result; |
| 1619 | } else { |
| 1620 | request.result = new IllegalArgumentException( |
| 1621 | "Failed to retrieve Forbidden Plmns"); |
| 1622 | if (ar.result == null) { |
| 1623 | loge("getForbiddenPlmns: Empty response"); |
| 1624 | } else { |
| 1625 | loge("getForbiddenPlmns: Unknown exception"); |
| 1626 | } |
| 1627 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1628 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1629 | break; |
| 1630 | |
| 1631 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1632 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1633 | uiccPort = getUiccPortFromRequest(request); |
| 1634 | if (uiccPort == null) { |
| 1635 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1636 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1637 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1638 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1639 | break; |
| 1640 | } |
| 1641 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1642 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1643 | if (uiccApp == null) { |
| 1644 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1645 | + appType); |
| 1646 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1647 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1648 | break; |
| 1649 | } else { |
| 1650 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1651 | + " specified type -- " + appType); |
| 1652 | } |
| 1653 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1654 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1655 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1656 | break; |
| 1657 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1658 | case CMD_SWITCH_SLOTS: |
| 1659 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1660 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1661 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1662 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1663 | break; |
| 1664 | |
| 1665 | case EVENT_SWITCH_SLOTS_DONE: |
| 1666 | ar = (AsyncResult) msg.obj; |
| 1667 | request = (MainThreadRequest) ar.userObj; |
| 1668 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1669 | notifyRequester(request); |
| 1670 | break; |
| 1671 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1672 | request = (MainThreadRequest) msg.obj; |
| 1673 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1674 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1675 | break; |
| 1676 | |
| 1677 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1678 | ar = (AsyncResult) msg.obj; |
| 1679 | request = (MainThreadRequest) ar.userObj; |
| 1680 | if (ar.exception != null) { |
| 1681 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1682 | } else { |
| 1683 | int mode = ((int[]) ar.result)[0]; |
| 1684 | if (mode == 0) { |
| 1685 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1686 | } else { |
| 1687 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1688 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1689 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1690 | notifyRequester(request); |
| 1691 | break; |
| 1692 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1693 | request = (MainThreadRequest) msg.obj; |
| 1694 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1695 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1696 | break; |
| 1697 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1698 | ar = (AsyncResult) msg.obj; |
| 1699 | request = (MainThreadRequest) ar.userObj; |
| 1700 | if (ar.exception != null) { |
| 1701 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1702 | } else { |
| 1703 | request.result = ((int[]) ar.result)[0]; |
| 1704 | } |
| 1705 | notifyRequester(request); |
| 1706 | break; |
| 1707 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1708 | request = (MainThreadRequest) msg.obj; |
| 1709 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1710 | int mode = (int) request.argument; |
| 1711 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1712 | break; |
| 1713 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1714 | ar = (AsyncResult) msg.obj; |
| 1715 | request = (MainThreadRequest) ar.userObj; |
| 1716 | request.result = ar.exception == null; |
| 1717 | notifyRequester(request); |
| 1718 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1719 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1720 | request = (MainThreadRequest) msg.obj; |
| 1721 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1722 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1723 | break; |
| 1724 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1725 | ar = (AsyncResult) msg.obj; |
| 1726 | request = (MainThreadRequest) ar.userObj; |
| 1727 | if (ar.exception != null) { |
| 1728 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1729 | } else { |
| 1730 | request.result = ((int[]) ar.result)[0]; |
| 1731 | } |
| 1732 | notifyRequester(request); |
| 1733 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1734 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1735 | request = (MainThreadRequest) msg.obj; |
| 1736 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1737 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1738 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1739 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1740 | break; |
| 1741 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1742 | ar = (AsyncResult) msg.obj; |
| 1743 | request = (MainThreadRequest) ar.userObj; |
| 1744 | request.result = ar.exception == null; |
| 1745 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1746 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | case CMD_GET_ALL_CELL_INFO: |
| 1748 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1749 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1750 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1751 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1752 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1753 | ar = (AsyncResult) msg.obj; |
| 1754 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1755 | // If a timeout occurs, the response will be null |
| 1756 | request.result = (ar.exception == null && ar.result != null) |
| 1757 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1758 | synchronized (request) { |
| 1759 | request.notifyAll(); |
| 1760 | } |
| 1761 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1762 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1763 | request = (MainThreadRequest) msg.obj; |
| 1764 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1765 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1766 | break; |
| 1767 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1768 | ar = (AsyncResult) msg.obj; |
| 1769 | request = (MainThreadRequest) ar.userObj; |
| 1770 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1771 | try { |
| 1772 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1773 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1774 | cb.onError( |
| 1775 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1776 | ar.exception.getClass().getName(), |
| 1777 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1778 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1779 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1780 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1781 | } else { |
| 1782 | // use the result as returned |
| 1783 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1784 | } |
| 1785 | } catch (RemoteException re) { |
| 1786 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1787 | } |
| 1788 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1789 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1790 | request = (MainThreadRequest) msg.obj; |
| 1791 | WorkSource ws = (WorkSource) request.argument; |
| 1792 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1793 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1794 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1795 | } |
| 1796 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1797 | ar = (AsyncResult) msg.obj; |
| 1798 | request = (MainThreadRequest) ar.userObj; |
| 1799 | if (ar.exception == null) { |
| 1800 | request.result = ar.result; |
| 1801 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1802 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1803 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1804 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | synchronized (request) { |
| 1808 | request.notifyAll(); |
| 1809 | } |
| 1810 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1811 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1812 | case CMD_MODEM_REBOOT: |
| 1813 | request = (MainThreadRequest) msg.obj; |
| 1814 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1815 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1816 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1817 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1818 | handleNullReturnEvent(msg, "rebootModem"); |
| 1819 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1820 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1821 | request = (MainThreadRequest) msg.obj; |
| 1822 | boolean enable = (boolean) request.argument; |
| 1823 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1824 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1825 | PhoneConfigurationManager.getInstance() |
| 1826 | .enablePhone(request.phone, enable, onCompleted); |
| 1827 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1828 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1829 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1830 | ar = (AsyncResult) msg.obj; |
| 1831 | request = (MainThreadRequest) ar.userObj; |
| 1832 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1833 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1834 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1835 | if ((boolean) request.result) { |
| 1836 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1837 | updateModemStateMetrics(); |
| 1838 | } else { |
| 1839 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1840 | + ar.exception); |
| 1841 | } |
| 1842 | notifyRequester(request); |
| 1843 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1844 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1845 | case CMD_GET_MODEM_STATUS: |
| 1846 | request = (MainThreadRequest) msg.obj; |
| 1847 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1848 | PhoneConfigurationManager.getInstance() |
| 1849 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1850 | break; |
| 1851 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1852 | ar = (AsyncResult) msg.obj; |
| 1853 | request = (MainThreadRequest) ar.userObj; |
| 1854 | int id = request.phone.getPhoneId(); |
| 1855 | if (ar.exception == null && ar.result != null) { |
| 1856 | request.result = ar.result; |
| 1857 | //update the cache as modem status has changed |
| 1858 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1859 | (boolean) request.result); |
| 1860 | } else { |
| 1861 | // Return true if modem status cannot be retrieved. For most cases, |
| 1862 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1863 | // and disable modem are not supported. Modem is always on. |
| 1864 | // TODO: this should be fixed in R to support a third |
| 1865 | // status UNKNOWN b/131631629 |
| 1866 | request.result = true; |
| 1867 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1868 | + ar.exception); |
| 1869 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1870 | notifyRequester(request); |
| 1871 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1872 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1873 | request = (MainThreadRequest) msg.obj; |
| 1874 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1875 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1876 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1877 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1878 | break; |
| 1879 | } |
| 1880 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1881 | ar = (AsyncResult) msg.obj; |
| 1882 | request = (MainThreadRequest) ar.userObj; |
| 1883 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1884 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1885 | args.second.accept(ar.exception == null); |
| 1886 | notifyRequester(request); |
| 1887 | break; |
| 1888 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1889 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1890 | request = (MainThreadRequest) msg.obj; |
| 1891 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1892 | Phone phone = getPhoneFromRequest(request); |
| 1893 | if (phone != null) { |
| 1894 | phone.getSystemSelectionChannels(onCompleted); |
| 1895 | } else { |
| 1896 | loge("getSystemSelectionChannels: No phone object"); |
| 1897 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1898 | notifyRequester(request); |
| 1899 | } |
| 1900 | break; |
| 1901 | } |
| 1902 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1903 | ar = (AsyncResult) msg.obj; |
| 1904 | request = (MainThreadRequest) ar.userObj; |
| 1905 | if (ar.exception == null && ar.result != null) { |
| 1906 | request.result = ar.result; |
| 1907 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1908 | request.result = new IllegalStateException( |
| 1909 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1910 | if (ar.result == null) { |
| 1911 | loge("getSystemSelectionChannels: Empty response"); |
| 1912 | } else { |
| 1913 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1914 | } |
| 1915 | } |
| 1916 | notifyRequester(request); |
| 1917 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1918 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1919 | ar = (AsyncResult) msg.obj; |
| 1920 | request = (MainThreadRequest) ar.userObj; |
| 1921 | if (ar.exception == null && ar.result != null) { |
| 1922 | request.result = ar.result; |
| 1923 | } else { |
| 1924 | request.result = -1; |
| 1925 | loge("Failed to set Forbidden Plmns"); |
| 1926 | if (ar.result == null) { |
| 1927 | loge("setForbidenPlmns: Empty response"); |
| 1928 | } else if (ar.exception != null) { |
| 1929 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1930 | request.result = -1; |
| 1931 | } else { |
| 1932 | loge("setForbiddenPlmns: Unknown exception"); |
| 1933 | } |
| 1934 | } |
| 1935 | notifyRequester(request); |
| 1936 | break; |
| 1937 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1938 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1939 | uiccPort = getUiccPortFromRequest(request); |
| 1940 | if (uiccPort == null) { |
| 1941 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1942 | request.result = -1; |
| 1943 | notifyRequester(request); |
| 1944 | break; |
| 1945 | } |
| 1946 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1947 | (Pair<Integer, List<String>>) request.argument; |
| 1948 | appType = setFplmnsArgs.first; |
| 1949 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1950 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1951 | if (uiccApp == null) { |
| 1952 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1953 | request.result = -1; |
| 1954 | loge("Failed to get UICC App"); |
| 1955 | notifyRequester(request); |
| 1956 | } else { |
| 1957 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1958 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1959 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1960 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1961 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1962 | case CMD_ERASE_MODEM_CONFIG: |
| 1963 | request = (MainThreadRequest) msg.obj; |
| 1964 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1965 | defaultPhone.eraseModemConfig(onCompleted); |
| 1966 | break; |
| 1967 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1968 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1969 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1970 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1971 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1972 | request = (MainThreadRequest) msg.obj; |
| 1973 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1974 | notifyRequester(request); |
| 1975 | break; |
| 1976 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1977 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1978 | request = (MainThreadRequest) msg.obj; |
| 1979 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1980 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1981 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1982 | changed.first, changed.second, onCompleted); |
| 1983 | break; |
| 1984 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1985 | ar = (AsyncResult) msg.obj; |
| 1986 | request = (MainThreadRequest) ar.userObj; |
| 1987 | if (ar.exception == null) { |
| 1988 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1989 | // If the operation is successful, update the PIN storage |
| 1990 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1991 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1992 | UiccController.getInstance().getPinStorage() |
| 1993 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1994 | } else { |
| 1995 | request.result = msg.arg1; |
| 1996 | } |
| 1997 | notifyRequester(request); |
| 1998 | break; |
| 1999 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2000 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2001 | request = (MainThreadRequest) msg.obj; |
| 2002 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2003 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2004 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2005 | enabled.first, enabled.second, onCompleted); |
| 2006 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2007 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2008 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2009 | ar = (AsyncResult) msg.obj; |
| 2010 | request = (MainThreadRequest) ar.userObj; |
| 2011 | if (ar.exception == null) { |
| 2012 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2013 | // If the operation is successful, update the PIN storage |
| 2014 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2015 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2016 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2017 | UiccController.getInstance().getPinStorage() |
| 2018 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2019 | } else { |
| 2020 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2021 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2022 | } else { |
| 2023 | request.result = msg.arg1; |
| 2024 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2025 | |
| 2026 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2027 | notifyRequester(request); |
| 2028 | break; |
| 2029 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2030 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2031 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2032 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2033 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2034 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2035 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2036 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2037 | |
| 2038 | case CMD_SET_DATA_THROTTLING: { |
| 2039 | request = (MainThreadRequest) msg.obj; |
| 2040 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2041 | DataThrottlingRequest dataThrottlingRequest = |
| 2042 | (DataThrottlingRequest) request.argument; |
| 2043 | Phone phone = getPhoneFromRequest(request); |
| 2044 | if (phone != null) { |
| 2045 | phone.setDataThrottling(onCompleted, |
| 2046 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2047 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2048 | } else { |
| 2049 | loge("setDataThrottling: No phone object"); |
| 2050 | request.result = |
| 2051 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2052 | notifyRequester(request); |
| 2053 | } |
| 2054 | |
| 2055 | break; |
| 2056 | } |
| 2057 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2058 | ar = (AsyncResult) msg.obj; |
| 2059 | request = (MainThreadRequest) ar.userObj; |
| 2060 | |
| 2061 | if (ar.exception == null) { |
| 2062 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2063 | } else if (ar.exception instanceof CommandException) { |
| 2064 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2065 | CommandException.Error error = |
| 2066 | ((CommandException) (ar.exception)).getCommandError(); |
| 2067 | |
| 2068 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2069 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2070 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2071 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2072 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2073 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2074 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2075 | } else { |
| 2076 | request.result = |
| 2077 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2078 | } |
| 2079 | } else { |
| 2080 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2081 | } |
| 2082 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2083 | notifyRequester(request); |
| 2084 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2085 | |
| 2086 | case CMD_SET_SIM_POWER: { |
| 2087 | request = (MainThreadRequest) msg.obj; |
| 2088 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2089 | request = (MainThreadRequest) msg.obj; |
| 2090 | int stateToSet = |
| 2091 | ((Pair<Integer, IIntegerConsumer>) |
| 2092 | request.argument).first; |
| 2093 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2094 | break; |
| 2095 | } |
| 2096 | case EVENT_SET_SIM_POWER_DONE: { |
| 2097 | ar = (AsyncResult) msg.obj; |
| 2098 | request = (MainThreadRequest) ar.userObj; |
| 2099 | IIntegerConsumer callback = |
| 2100 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2101 | if (ar.exception != null) { |
| 2102 | loge("setSimPower exception: " + ar.exception); |
| 2103 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2104 | .RESULT_ERROR_UNKNOWN; |
| 2105 | if (ar.exception instanceof CommandException) { |
| 2106 | CommandException.Error error = |
| 2107 | ((CommandException) (ar.exception)).getCommandError(); |
| 2108 | if (error == CommandException.Error.SIM_ERR) { |
| 2109 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2110 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2111 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2112 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2113 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2114 | } else { |
| 2115 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2116 | } |
| 2117 | } |
| 2118 | try { |
| 2119 | callback.accept(errorCode); |
| 2120 | } catch (RemoteException e) { |
| 2121 | // Ignore if the remote process is no longer available to call back. |
| 2122 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2123 | } |
| 2124 | } else { |
| 2125 | try { |
| 2126 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2127 | } catch (RemoteException e) { |
| 2128 | // Ignore if the remote process is no longer available to call back. |
| 2129 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2130 | } |
| 2131 | } |
| 2132 | break; |
| 2133 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2134 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2135 | request = (MainThreadRequest) msg.obj; |
| 2136 | |
| 2137 | final Phone phone = getPhoneFromRequest(request); |
| 2138 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2139 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2140 | notifyRequester(request); |
| 2141 | break; |
| 2142 | } |
| 2143 | |
| 2144 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2145 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2146 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2147 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2148 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2149 | request.subId, pair.first /*callingUid*/, |
| 2150 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2151 | break; |
| 2152 | } |
| 2153 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2154 | ar = (AsyncResult) msg.obj; |
| 2155 | request = (MainThreadRequest) ar.userObj; |
| 2156 | // request.result will be the exception of ar if present, true otherwise. |
| 2157 | // Be cautious not to leave result null which will wait() forever |
| 2158 | request.result = ar.exception != null ? ar.exception : true; |
| 2159 | notifyRequester(request); |
| 2160 | break; |
| 2161 | } |
| 2162 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2163 | request = (MainThreadRequest) msg.obj; |
| 2164 | |
| 2165 | Phone phone = getPhoneFromRequest(request); |
| 2166 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2167 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2168 | notifyRequester(request); |
| 2169 | break; |
| 2170 | } |
| 2171 | |
| 2172 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2173 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2174 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2175 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2176 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2177 | request.subId, pair.first /*callingUid*/, |
| 2178 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2179 | break; |
| 2180 | } |
| 2181 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2182 | ar = (AsyncResult) msg.obj; |
| 2183 | request = (MainThreadRequest) ar.userObj; |
| 2184 | request.result = ar.exception != null ? ar.exception : true; |
| 2185 | notifyRequester(request); |
| 2186 | break; |
| 2187 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2188 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2189 | case CMD_GET_SLICING_CONFIG: { |
| 2190 | request = (MainThreadRequest) msg.obj; |
| 2191 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2192 | request.phone.getSlicingConfig(onCompleted); |
| 2193 | break; |
| 2194 | } |
| 2195 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2196 | ar = (AsyncResult) msg.obj; |
| 2197 | request = (MainThreadRequest) ar.userObj; |
| 2198 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2199 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2200 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2201 | Bundle bundle = new Bundle(); |
| 2202 | int resultCode = 0; |
| 2203 | if (ar.exception != null) { |
| 2204 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2205 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2206 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2207 | } else if (ar.result == null) { |
| 2208 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2209 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2210 | } else { |
| 2211 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2212 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2213 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2217 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2218 | } |
| 2219 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2220 | result.send(resultCode, bundle); |
| 2221 | notifyRequester(request); |
| 2222 | break; |
| 2223 | } |
| 2224 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2225 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2226 | request = (MainThreadRequest) msg.obj; |
| 2227 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2228 | PurchasePremiumCapabilityArgument arg = |
| 2229 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2230 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2231 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2232 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2233 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2234 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2235 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2236 | ar = (AsyncResult) msg.obj; |
| 2237 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2238 | PurchasePremiumCapabilityArgument arg = |
| 2239 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2240 | try { |
| 2241 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2242 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2243 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2244 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2245 | + ", result= " |
| 2246 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2247 | } catch (RemoteException e) { |
| 2248 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2249 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2250 | + " failed: " + e; |
| 2251 | if (DBG) log(logStr); |
| 2252 | AnomalyReporter.reportAnomaly( |
| 2253 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2254 | } |
| 2255 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2256 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2257 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2258 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2259 | request = (MainThreadRequest) msg.obj; |
| 2260 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2261 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2262 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2263 | notifyRequester(request); |
| 2264 | break; |
| 2265 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | default: |
| 2267 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2268 | break; |
| 2269 | } |
| 2270 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2271 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2272 | private void notifyRequester(MainThreadRequest request) { |
| 2273 | synchronized (request) { |
| 2274 | request.notifyAll(); |
| 2275 | } |
| 2276 | } |
| 2277 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2278 | private void handleNullReturnEvent(Message msg, String command) { |
| 2279 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2280 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2281 | if (ar.exception == null) { |
| 2282 | request.result = true; |
| 2283 | } else { |
| 2284 | request.result = false; |
| 2285 | if (ar.exception instanceof CommandException) { |
| 2286 | loge(command + ": CommandException: " + ar.exception); |
| 2287 | } else { |
| 2288 | loge(command + ": Unknown exception"); |
| 2289 | } |
| 2290 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2291 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2292 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | /** |
| 2296 | * Posts the specified command to be executed on the main thread, |
| 2297 | * waits for the request to complete, and returns the result. |
| 2298 | * @see #sendRequestAsync |
| 2299 | */ |
| 2300 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2301 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2302 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | /** |
| 2306 | * Posts the specified command to be executed on the main thread, |
| 2307 | * waits for the request to complete, and returns the result. |
| 2308 | * @see #sendRequestAsync |
| 2309 | */ |
| 2310 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2311 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2312 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * Posts the specified command to be executed on the main thread, |
| 2317 | * waits for the request to complete, and returns the result. |
| 2318 | * @see #sendRequestAsync |
| 2319 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2320 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2321 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2322 | } |
| 2323 | |
| 2324 | /** |
| 2325 | * Posts the specified command to be executed on the main thread, |
| 2326 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2327 | * if not timeout or null otherwise. |
| 2328 | * @see #sendRequestAsync |
| 2329 | */ |
| 2330 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2331 | long timeoutInMs) { |
| 2332 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | /** |
| 2336 | * Posts the specified command to be executed on the main thread, |
| 2337 | * waits for the request to complete, and returns the result. |
| 2338 | * @see #sendRequestAsync |
| 2339 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2340 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2341 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | /** |
| 2345 | * Posts the specified command to be executed on the main thread, |
| 2346 | * waits for the request to complete, and returns the result. |
| 2347 | * @see #sendRequestAsync |
| 2348 | */ |
| 2349 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2350 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2351 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2355 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2356 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2357 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2358 | * @see #sendRequestAsync |
| 2359 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2360 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2361 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2362 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2363 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2364 | } |
| 2365 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2366 | MainThreadRequest request = null; |
| 2367 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2368 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2369 | } else if (phone != null) { |
| 2370 | request = new MainThreadRequest(argument, phone, workSource); |
| 2371 | } else { |
| 2372 | request = new MainThreadRequest(argument, subId, workSource); |
| 2373 | } |
| 2374 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2376 | msg.sendToTarget(); |
| 2377 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2378 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2379 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2380 | if (timeoutInMs >= 0) { |
| 2381 | // Wait for at least timeoutInMs before returning null request result |
| 2382 | long now = SystemClock.elapsedRealtime(); |
| 2383 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2384 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2385 | try { |
| 2386 | request.wait(deadline - now); |
| 2387 | } catch (InterruptedException e) { |
| 2388 | // Do nothing, go back and check if request is completed or timeout |
| 2389 | } finally { |
| 2390 | now = SystemClock.elapsedRealtime(); |
| 2391 | } |
| 2392 | } |
| 2393 | } else { |
| 2394 | // Wait for the request to complete |
| 2395 | while (request.result == null) { |
| 2396 | try { |
| 2397 | request.wait(); |
| 2398 | } catch (InterruptedException e) { |
| 2399 | // Do nothing, go back and wait until the request is complete |
| 2400 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2404 | if (request.result == null) { |
| 2405 | Log.wtf(LOG_TAG, |
| 2406 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | return request.result; |
| 2409 | } |
| 2410 | |
| 2411 | /** |
| 2412 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2413 | * Posts the specified command to be executed on the main thread, and |
| 2414 | * returns immediately. |
| 2415 | * @see #sendRequest |
| 2416 | */ |
| 2417 | private void sendRequestAsync(int command) { |
| 2418 | mMainThreadHandler.sendEmptyMessage(command); |
| 2419 | } |
| 2420 | |
| 2421 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2422 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2423 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2424 | */ |
| 2425 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2426 | sendRequestAsync(command, argument, null, null); |
| 2427 | } |
| 2428 | |
| 2429 | /** |
| 2430 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2431 | * @see {@link #sendRequest(int,Object)} |
| 2432 | */ |
| 2433 | private void sendRequestAsync( |
| 2434 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2435 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2436 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2437 | msg.sendToTarget(); |
| 2438 | } |
| 2439 | |
| 2440 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2442 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2443 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2444 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2445 | synchronized (PhoneInterfaceManager.class) { |
| 2446 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2447 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | } else { |
| 2449 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2450 | } |
| 2451 | return sInstance; |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2456 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2459 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2460 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2461 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2463 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2464 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2465 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2466 | } else { |
| 2467 | mSubscriptionController = null; |
| 2468 | } |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2469 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2470 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2471 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2472 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2473 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2474 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2476 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2479 | @VisibleForTesting |
| 2480 | public SharedPreferences getSharedPreferences() { |
| 2481 | return mTelephonySharedPreferences; |
| 2482 | } |
| 2483 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2484 | /** |
| 2485 | * Get the default phone for this device. |
| 2486 | */ |
| 2487 | @VisibleForTesting |
| 2488 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2489 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2490 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2491 | } |
| 2492 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | private void publish() { |
| 2494 | if (DBG) log("publish: " + this); |
| 2495 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2496 | TelephonyFrameworkInitializer |
| 2497 | .getTelephonyServiceManager() |
| 2498 | .getTelephonyServiceRegisterer() |
| 2499 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2502 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2503 | if (request.phone != null) { |
| 2504 | return request.phone; |
| 2505 | } else { |
| 2506 | return getPhoneFromSubId(request.subId); |
| 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | private Phone getPhoneFromSubId(int subId) { |
| 2511 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2512 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2513 | } |
| 2514 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2515 | /** |
| 2516 | * Get phone object associated with a subscription. |
| 2517 | * Return default phone if phone object associated with subscription is null |
| 2518 | * @param subId - subscriptionId |
| 2519 | * @return phone object associated with a subscription or default phone if null. |
| 2520 | */ |
| 2521 | private Phone getPhoneFromSubIdOrDefault(int subId) { |
| 2522 | Phone phone = getPhoneFromSubId(subId); |
| 2523 | if (phone == null) { |
| 2524 | phone = getDefaultPhone(); |
| 2525 | } |
| 2526 | return phone; |
| 2527 | } |
| 2528 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2529 | @Nullable |
| 2530 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2531 | Phone phone = getPhoneFromRequest(request); |
| 2532 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2533 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2534 | } |
| 2535 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2536 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2537 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2538 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2539 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2540 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2541 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2542 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2543 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2544 | } |
| 2545 | |
| 2546 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2547 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2548 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2551 | private boolean isImsAvailableOnDevice() { |
| 2552 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2553 | if (pm == null) { |
| 2554 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2555 | // so do not throw error and allow. |
| 2556 | return true; |
| 2557 | } |
| 2558 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2559 | } |
| 2560 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2561 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2562 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2563 | } |
| 2564 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2565 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2566 | if (DBG) log("dial: " + number); |
| 2567 | // No permission check needed here: This is just a wrapper around the |
| 2568 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2569 | // the UI before it does anything. |
| 2570 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2571 | final long identity = Binder.clearCallingIdentity(); |
| 2572 | try { |
| 2573 | String url = createTelUrl(number); |
| 2574 | if (url == null) { |
| 2575 | return; |
| 2576 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2577 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2578 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2579 | PhoneConstants.State state = mCM.getState(subId); |
| 2580 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2581 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2582 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2583 | mApp.startActivity(intent); |
| 2584 | } |
| 2585 | } finally { |
| 2586 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2591 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2594 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2595 | if (DBG) log("call: " + number); |
| 2596 | |
| 2597 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2598 | // need to do a permission check since we're calling startActivity() |
| 2599 | // from the context of the phone app. |
| 2600 | enforceCallPermission(); |
| 2601 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2602 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2603 | != AppOpsManager.MODE_ALLOWED) { |
| 2604 | return; |
| 2605 | } |
| 2606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | final long identity = Binder.clearCallingIdentity(); |
| 2608 | try { |
| 2609 | String url = createTelUrl(number); |
| 2610 | if (url == null) { |
| 2611 | return; |
| 2612 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2613 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | boolean isValid = false; |
| 2615 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2616 | if (slist != null) { |
| 2617 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2618 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2619 | isValid = true; |
| 2620 | break; |
| 2621 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2622 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2623 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2624 | if (!isValid) { |
| 2625 | return; |
| 2626 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2627 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2628 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2629 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2630 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2631 | mApp.startActivity(intent); |
| 2632 | } finally { |
| 2633 | Binder.restoreCallingIdentity(identity); |
| 2634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2635 | } |
| 2636 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2637 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2638 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2639 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2640 | } |
| 2641 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2642 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2643 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2644 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2645 | } |
| 2646 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2647 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2648 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2649 | |
| 2650 | final long identity = Binder.clearCallingIdentity(); |
| 2651 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2652 | Phone phone = getPhone(subId); |
| 2653 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | checkSimPin.start(); |
| 2655 | return checkSimPin.unlockSim(null, pin); |
| 2656 | } finally { |
| 2657 | Binder.restoreCallingIdentity(identity); |
| 2658 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2661 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2662 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | |
| 2664 | final long identity = Binder.clearCallingIdentity(); |
| 2665 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2666 | Phone phone = getPhone(subId); |
| 2667 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | checkSimPuk.start(); |
| 2669 | return checkSimPuk.unlockSim(puk, pin); |
| 2670 | } finally { |
| 2671 | Binder.restoreCallingIdentity(identity); |
| 2672 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2676 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2677 | * a synchronous one. |
| 2678 | */ |
| 2679 | private static class UnlockSim extends Thread { |
| 2680 | |
| 2681 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2682 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2683 | |
| 2684 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2685 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2686 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | |
| 2688 | // For replies from SimCard interface |
| 2689 | private Handler mHandler; |
| 2690 | |
| 2691 | // For async handler to identify request type |
| 2692 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2693 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2694 | UnlockSim(int phoneId, IccCard simCard) { |
| 2695 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2696 | mSimCard = simCard; |
| 2697 | } |
| 2698 | |
| 2699 | @Override |
| 2700 | public void run() { |
| 2701 | Looper.prepare(); |
| 2702 | synchronized (UnlockSim.this) { |
| 2703 | mHandler = new Handler() { |
| 2704 | @Override |
| 2705 | public void handleMessage(Message msg) { |
| 2706 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2707 | switch (msg.what) { |
| 2708 | case SUPPLY_PIN_COMPLETE: |
| 2709 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2710 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2711 | mRetryCount = msg.arg1; |
| 2712 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2713 | CommandException.Error error = null; |
| 2714 | if (ar.exception instanceof CommandException) { |
| 2715 | error = ((CommandException) (ar.exception)) |
| 2716 | .getCommandError(); |
| 2717 | } |
| 2718 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2719 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2720 | } else if (error == CommandException.Error.ABORTED) { |
| 2721 | /* When UiccCardApp dispose, handle message and return |
| 2722 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2723 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2724 | } else { |
| 2725 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2726 | } |
| 2727 | } else { |
| 2728 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2729 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2730 | mDone = true; |
| 2731 | UnlockSim.this.notifyAll(); |
| 2732 | } |
| 2733 | break; |
| 2734 | } |
| 2735 | } |
| 2736 | }; |
| 2737 | UnlockSim.this.notifyAll(); |
| 2738 | } |
| 2739 | Looper.loop(); |
| 2740 | } |
| 2741 | |
| 2742 | /* |
| 2743 | * Use PIN or PUK to unlock SIM card |
| 2744 | * |
| 2745 | * If PUK is null, unlock SIM card with PIN |
| 2746 | * |
| 2747 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2748 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2749 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2750 | |
| 2751 | while (mHandler == null) { |
| 2752 | try { |
| 2753 | wait(); |
| 2754 | } catch (InterruptedException e) { |
| 2755 | Thread.currentThread().interrupt(); |
| 2756 | } |
| 2757 | } |
| 2758 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2759 | |
| 2760 | if (puk == null) { |
| 2761 | mSimCard.supplyPin(pin, callback); |
| 2762 | } else { |
| 2763 | mSimCard.supplyPuk(puk, pin, callback); |
| 2764 | } |
| 2765 | |
| 2766 | while (!mDone) { |
| 2767 | try { |
| 2768 | Log.d(LOG_TAG, "wait for done"); |
| 2769 | wait(); |
| 2770 | } catch (InterruptedException e) { |
| 2771 | // Restore the interrupted status |
| 2772 | Thread.currentThread().interrupt(); |
| 2773 | } |
| 2774 | } |
| 2775 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2776 | int[] resultArray = new int[2]; |
| 2777 | resultArray[0] = mResult; |
| 2778 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2779 | |
| 2780 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2781 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2784 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2785 | } |
| 2786 | } |
| 2787 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2788 | /** |
| 2789 | * This method has been removed due to privacy and stability concerns. |
| 2790 | */ |
| 2791 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2793 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2794 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2797 | @Override |
| 2798 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2799 | mApp.getSystemService(AppOpsManager.class) |
| 2800 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2801 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2802 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2803 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2804 | // Callers targeting S have no business invoking this method. |
| 2805 | return; |
| 2806 | } |
| 2807 | |
| 2808 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2809 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2810 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2811 | .setCallingPackage(callingPackage) |
| 2812 | .setCallingFeatureId(null) |
| 2813 | .setCallingPid(Binder.getCallingPid()) |
| 2814 | .setCallingUid(Binder.getCallingUid()) |
| 2815 | .setMethod("updateServiceLocation") |
| 2816 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2817 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2818 | .build()); |
| 2819 | // Apps that lack location permission have no business calling this method; |
| 2820 | // however, because no permission was declared in the public API, denials must |
| 2821 | // all be "soft". |
| 2822 | switch (locationResult) { |
| 2823 | case DENIED_HARD: /* fall through */ |
| 2824 | case DENIED_SOFT: |
| 2825 | return; |
| 2826 | } |
| 2827 | |
| 2828 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2831 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2832 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2833 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2834 | } |
| 2835 | } finally { |
| 2836 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2840 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2841 | @Override |
| 2842 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2843 | return isRadioOnWithFeature(callingPackage, null); |
| 2844 | } |
| 2845 | |
| 2846 | |
| 2847 | @Override |
| 2848 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2849 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2850 | callingFeatureId); |
| 2851 | } |
| 2852 | |
| 2853 | @Deprecated |
| 2854 | @Override |
| 2855 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2856 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2857 | } |
| 2858 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2859 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2860 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2861 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2862 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2863 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2864 | return false; |
| 2865 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2866 | |
| 2867 | final long identity = Binder.clearCallingIdentity(); |
| 2868 | try { |
| 2869 | return isRadioOnForSubscriber(subId); |
| 2870 | } finally { |
| 2871 | Binder.restoreCallingIdentity(identity); |
| 2872 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | final long identity = Binder.clearCallingIdentity(); |
| 2877 | try { |
| 2878 | final Phone phone = getPhone(subId); |
| 2879 | if (phone != null) { |
| 2880 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2881 | } else { |
| 2882 | return false; |
| 2883 | } |
| 2884 | } finally { |
| 2885 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2886 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2890 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2891 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2892 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2893 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2894 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2895 | |
| 2896 | final long identity = Binder.clearCallingIdentity(); |
| 2897 | try { |
| 2898 | final Phone phone = getPhone(subId); |
| 2899 | if (phone != null) { |
| 2900 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2901 | } |
| 2902 | } finally { |
| 2903 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2904 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2908 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2911 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2912 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2913 | |
| 2914 | final long identity = Binder.clearCallingIdentity(); |
| 2915 | try { |
| 2916 | final Phone phone = getPhone(subId); |
| 2917 | if (phone == null) { |
| 2918 | return false; |
| 2919 | } |
| 2920 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2921 | toggleRadioOnOffForSubscriber(subId); |
| 2922 | } |
| 2923 | return true; |
| 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2926 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2927 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2928 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2929 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2930 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2931 | /* |
| 2932 | * If any of the Radios are available, it will need to be |
| 2933 | * shutdown. So return true if any Radio is available. |
| 2934 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2935 | final long identity = Binder.clearCallingIdentity(); |
| 2936 | try { |
| 2937 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2938 | Phone phone = PhoneFactory.getPhone(i); |
| 2939 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2940 | } |
| 2941 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2942 | return false; |
| 2943 | } finally { |
| 2944 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2945 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2948 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2949 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2950 | enforceModifyPermission(); |
| 2951 | |
| 2952 | final long identity = Binder.clearCallingIdentity(); |
| 2953 | try { |
| 2954 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2955 | logv("Shutting down Phone " + i); |
| 2956 | shutdownRadioUsingPhoneId(i); |
| 2957 | } |
| 2958 | } finally { |
| 2959 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2964 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2965 | if (phone != null && phone.isRadioAvailable()) { |
| 2966 | phone.shutdownRadio(); |
| 2967 | } |
| 2968 | } |
| 2969 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2970 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2971 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2972 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2973 | if (!turnOn) { |
| 2974 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 2975 | } |
| 2976 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2977 | final long identity = Binder.clearCallingIdentity(); |
| 2978 | try { |
| 2979 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2980 | if (defaultPhone != null) { |
| 2981 | defaultPhone.setRadioPower(turnOn); |
| 2982 | return true; |
| 2983 | } else { |
| 2984 | loge("There's no default phone."); |
| 2985 | return false; |
| 2986 | } |
| 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2989 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2992 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2993 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2994 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2995 | if (!turnOn) { |
| 2996 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 2997 | + ",callingPackage=" + getCurrentPackageName()); |
| 2998 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2999 | final long identity = Binder.clearCallingIdentity(); |
| 3000 | try { |
| 3001 | final Phone phone = getPhone(subId); |
| 3002 | if (phone != null) { |
| 3003 | phone.setRadioPower(turnOn); |
| 3004 | return true; |
| 3005 | } else { |
| 3006 | return false; |
| 3007 | } |
| 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3010 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3013 | /** |
| 3014 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3015 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3016 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3017 | * powering it off, and these radio off votes will be cleared. |
| 3018 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3019 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3020 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3021 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3022 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3023 | * check its vote. |
| 3024 | * |
| 3025 | * @param subId The subscription ID. |
| 3026 | * @param reason The reason for powering off radio. |
| 3027 | * @return true on success and false on failure. |
| 3028 | */ |
| 3029 | public boolean requestRadioPowerOffForReason(int subId, |
| 3030 | @TelephonyManager.RadioPowerReason int reason) { |
| 3031 | enforceModifyPermission(); |
| 3032 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3033 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3034 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3035 | final long identity = Binder.clearCallingIdentity(); |
| 3036 | try { |
| 3037 | final Phone phone = getPhone(subId); |
| 3038 | if (phone != null) { |
| 3039 | phone.setRadioPowerForReason(false, reason); |
| 3040 | return true; |
| 3041 | } else { |
| 3042 | return false; |
| 3043 | } |
| 3044 | } finally { |
| 3045 | Binder.restoreCallingIdentity(identity); |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | /** |
| 3050 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3051 | * {@link requestRadioPowerOffForReason}. |
| 3052 | * |
| 3053 | * @param subId The subscription ID. |
| 3054 | * @param reason The reason for powering off radio. |
| 3055 | * @return true on success and false on failure. |
| 3056 | */ |
| 3057 | public boolean clearRadioPowerOffForReason(int subId, |
| 3058 | @TelephonyManager.RadioPowerReason int reason) { |
| 3059 | enforceModifyPermission(); |
| 3060 | |
| 3061 | final long identity = Binder.clearCallingIdentity(); |
| 3062 | try { |
| 3063 | final Phone phone = getPhone(subId); |
| 3064 | if (phone != null) { |
| 3065 | phone.setRadioPowerForReason(true, reason); |
| 3066 | return true; |
| 3067 | } else { |
| 3068 | return false; |
| 3069 | } |
| 3070 | } finally { |
| 3071 | Binder.restoreCallingIdentity(identity); |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | /** |
| 3076 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3077 | * |
| 3078 | * @param subId The subscription ID. |
| 3079 | * @param callingPackage The package making the call. |
| 3080 | * @param callingFeatureId The feature in the package. |
| 3081 | * @return List of reasons for powering off radio. |
| 3082 | */ |
| 3083 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3084 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3085 | |
| 3086 | final long identity = Binder.clearCallingIdentity(); |
| 3087 | List result = new ArrayList(); |
| 3088 | try { |
| 3089 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3090 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3091 | return result; |
| 3092 | } |
| 3093 | |
| 3094 | final Phone phone = getPhone(subId); |
| 3095 | if (phone != null) { |
| 3096 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3097 | } |
| 3098 | } finally { |
| 3099 | Binder.restoreCallingIdentity(identity); |
| 3100 | } |
| 3101 | return result; |
| 3102 | } |
| 3103 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3104 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3105 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3106 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3107 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3108 | |
| 3109 | final long identity = Binder.clearCallingIdentity(); |
| 3110 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3111 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3112 | final Phone phone = getPhone(subId); |
| 3113 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3114 | phone.getDataSettingsManager().setDataEnabled( |
| 3115 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3116 | return true; |
| 3117 | } else { |
| 3118 | return false; |
| 3119 | } |
| 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3122 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3123 | } |
| 3124 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3125 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3126 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3127 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3128 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3129 | |
| 3130 | final long identity = Binder.clearCallingIdentity(); |
| 3131 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3132 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3133 | final Phone phone = getPhone(subId); |
| 3134 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3135 | phone.getDataSettingsManager().setDataEnabled( |
| 3136 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3137 | return true; |
| 3138 | } else { |
| 3139 | return false; |
| 3140 | } |
| 3141 | } finally { |
| 3142 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3143 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3146 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3147 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3148 | final long identity = Binder.clearCallingIdentity(); |
| 3149 | try { |
| 3150 | final Phone phone = getPhone(subId); |
| 3151 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3152 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3153 | } else { |
| 3154 | return false; |
| 3155 | } |
| 3156 | } finally { |
| 3157 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3158 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3162 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3165 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3166 | enforceCallPermission(); |
| 3167 | |
| 3168 | final long identity = Binder.clearCallingIdentity(); |
| 3169 | try { |
| 3170 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3171 | return; |
| 3172 | } |
| 3173 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3174 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3175 | } finally { |
| 3176 | Binder.restoreCallingIdentity(identity); |
| 3177 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3178 | }; |
| 3179 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3180 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3181 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3182 | |
| 3183 | final long identity = Binder.clearCallingIdentity(); |
| 3184 | try { |
| 3185 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3186 | return false; |
| 3187 | } |
| 3188 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3189 | } finally { |
| 3190 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3191 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3194 | /** |
| 3195 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3196 | * tag on getCallState Binder call. |
| 3197 | */ |
| 3198 | @Deprecated |
| 3199 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3200 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3201 | if (CompatChanges.isChangeEnabled( |
| 3202 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3203 | Binder.getCallingUid())) { |
| 3204 | // Do not allow this API to be called on API version 31+, it should only be |
| 3205 | // called on old apps using this Binder call directly. |
| 3206 | throw new SecurityException("This method can only be used for applications " |
| 3207 | + "targeting API version 30 or less."); |
| 3208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3209 | final long identity = Binder.clearCallingIdentity(); |
| 3210 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3211 | Phone phone = getPhone(getDefaultSubscription()); |
| 3212 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3213 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(identity); |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | @Override |
| 3220 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3221 | if (CompatChanges.isChangeEnabled( |
| 3222 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3223 | Binder.getCallingUid())) { |
| 3224 | // Check READ_PHONE_STATE for API version 31+ |
| 3225 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3226 | featureId, "getCallStateForSubscription")) { |
| 3227 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3228 | + "targeting API level 31+."); |
| 3229 | } |
| 3230 | } |
| 3231 | final long identity = Binder.clearCallingIdentity(); |
| 3232 | try { |
| 3233 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3234 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3235 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3236 | } finally { |
| 3237 | Binder.restoreCallingIdentity(identity); |
| 3238 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3241 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3242 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3243 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | @Override |
| 3247 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | final long identity = Binder.clearCallingIdentity(); |
| 3249 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3250 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3252 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3253 | } else { |
| 3254 | return PhoneConstantConversions.convertDataState( |
| 3255 | PhoneConstants.DataState.DISCONNECTED); |
| 3256 | } |
| 3257 | } finally { |
| 3258 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3259 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3262 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3263 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3264 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3268 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3269 | final long identity = Binder.clearCallingIdentity(); |
| 3270 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3271 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3273 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | } else { |
| 3275 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3276 | } |
| 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3283 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3284 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3285 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3286 | |
| 3287 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3288 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3289 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3290 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3291 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3292 | .setCallingPid(Binder.getCallingPid()) |
| 3293 | .setCallingUid(Binder.getCallingUid()) |
| 3294 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3295 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3296 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3297 | .build()); |
| 3298 | switch (locationResult) { |
| 3299 | case DENIED_HARD: |
| 3300 | throw new SecurityException("Not allowed to access cell location"); |
| 3301 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3302 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3303 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3306 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3307 | final long identity = Binder.clearCallingIdentity(); |
| 3308 | try { |
| 3309 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3310 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3311 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3312 | } finally { |
| 3313 | Binder.restoreCallingIdentity(identity); |
| 3314 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3317 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3318 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3319 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3320 | // registered cell info, so return a NULL country instead. |
| 3321 | final long identity = Binder.clearCallingIdentity(); |
| 3322 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3323 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3324 | // Get default phone in this case. |
| 3325 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3326 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3327 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3328 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3329 | if (phone == null) return ""; |
| 3330 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3331 | if (sst == null) return ""; |
| 3332 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3333 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3334 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(identity); |
| 3337 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3338 | } |
| 3339 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3340 | /** |
| 3341 | * This method was removed due to potential issues caused by performing partial |
| 3342 | * updates of service state, and lack of a credible use case. |
| 3343 | * |
| 3344 | * This has the ability to break the telephony implementation by disabling notification of |
| 3345 | * changes in device connectivity. DO NOT USE THIS! |
| 3346 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3347 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3348 | public void enableLocationUpdates() { |
| 3349 | mApp.enforceCallingOrSelfPermission( |
| 3350 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3351 | } |
| 3352 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3353 | /** |
| 3354 | * This method was removed due to potential issues caused by performing partial |
| 3355 | * updates of service state, and lack of a credible use case. |
| 3356 | * |
| 3357 | * This has the ability to break the telephony implementation by disabling notification of |
| 3358 | * changes in device connectivity. DO NOT USE THIS! |
| 3359 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3360 | @Override |
| 3361 | public void disableLocationUpdates() { |
| 3362 | mApp.enforceCallingOrSelfPermission( |
| 3363 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | @Override |
| 3367 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3368 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3369 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3370 | try { |
| 3371 | mApp.getSystemService(AppOpsManager.class) |
| 3372 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3373 | } catch (SecurityException e) { |
| 3374 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3375 | throw e; |
| 3376 | } |
| 3377 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3378 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3379 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3380 | throw new SecurityException( |
| 3381 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3382 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3383 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3384 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3385 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3386 | return null; |
| 3387 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3388 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3389 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3390 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3391 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3392 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3393 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3394 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3395 | for (CellInfo ci : info) { |
| 3396 | if (ci instanceof CellInfoGsm) { |
| 3397 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3398 | } else if (ci instanceof CellInfoWcdma) { |
| 3399 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3400 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3401 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3402 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3405 | private List<CellInfo> getCachedCellInfo() { |
| 3406 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3407 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3408 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3409 | if (info != null) cellInfos.addAll(info); |
| 3410 | } |
| 3411 | return cellInfos; |
| 3412 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3413 | |
| 3414 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3415 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3416 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3417 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3418 | |
| 3419 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3420 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3421 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3422 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3423 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3424 | .setCallingPid(Binder.getCallingPid()) |
| 3425 | .setCallingUid(Binder.getCallingUid()) |
| 3426 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3427 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3428 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3429 | .build()); |
| 3430 | switch (locationResult) { |
| 3431 | case DENIED_HARD: |
| 3432 | throw new SecurityException("Not allowed to access cell info"); |
| 3433 | case DENIED_SOFT: |
| 3434 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3437 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3438 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3439 | return getCachedCellInfo(); |
| 3440 | } |
| 3441 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3442 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3443 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
| 3446 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3447 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3448 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3449 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3450 | if (info != null) cellInfos.addAll(info); |
| 3451 | } |
| 3452 | return cellInfos; |
| 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3455 | } |
| 3456 | } |
| 3457 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3458 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3459 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3460 | String callingFeatureId) { |
| 3461 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3462 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3466 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3467 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3468 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3469 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3472 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3473 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3474 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3475 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3476 | |
| 3477 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3478 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3479 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3480 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3481 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3482 | .setCallingPid(Binder.getCallingPid()) |
| 3483 | .setCallingUid(Binder.getCallingUid()) |
| 3484 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3485 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3486 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3487 | .build()); |
| 3488 | switch (locationResult) { |
| 3489 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3490 | if (TelephonyPermissions |
| 3491 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3492 | // Safetynet logging for b/154934934 |
| 3493 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3494 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3495 | throw new SecurityException("Not allowed to access cell info"); |
| 3496 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3497 | if (TelephonyPermissions |
| 3498 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3499 | // Safetynet logging for b/154934934 |
| 3500 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3501 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3502 | try { |
| 3503 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3504 | } catch (RemoteException re) { |
| 3505 | // Drop without consequences |
| 3506 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3507 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3510 | |
| 3511 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3512 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3513 | |
| 3514 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3515 | } |
| 3516 | |
| 3517 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3518 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3519 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3520 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3521 | |
| 3522 | final long identity = Binder.clearCallingIdentity(); |
| 3523 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3524 | Phone phone = getPhone(subId); |
| 3525 | if (phone == null) { |
| 3526 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3527 | } else { |
| 3528 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3530 | } finally { |
| 3531 | Binder.restoreCallingIdentity(identity); |
| 3532 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3533 | } |
| 3534 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3535 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3536 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3537 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3538 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3539 | return null; |
| 3540 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3541 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3542 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3543 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3544 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3545 | return null; |
| 3546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3547 | |
| 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | return phone.getImei(); |
| 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
| 3553 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3557 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3558 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3559 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3560 | callingFeatureId, "getPrimaryImei")) { |
| 3561 | throw new SecurityException("Caller does not have permission"); |
| 3562 | } |
| 3563 | final long identity = Binder.clearCallingIdentity(); |
| 3564 | try { |
| 3565 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3566 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3567 | return phone.getImei(); |
| 3568 | } |
| 3569 | } |
| 3570 | throw new UnsupportedOperationException("Operation not supported"); |
| 3571 | } finally { |
| 3572 | Binder.restoreCallingIdentity(identity); |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3577 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3578 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3579 | String tac = null; |
| 3580 | if (phone != null) { |
| 3581 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3582 | try { |
| 3583 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3584 | } catch (IndexOutOfBoundsException e) { |
| 3585 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3586 | return null; |
| 3587 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3588 | } |
| 3589 | return tac; |
| 3590 | } |
| 3591 | |
| 3592 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3593 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3594 | try { |
| 3595 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3596 | } catch (SecurityException se) { |
| 3597 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3598 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3599 | + Binder.getCallingUid()); |
| 3600 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3601 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3602 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3603 | return null; |
| 3604 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3605 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3606 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3607 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3608 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3609 | return null; |
| 3610 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3611 | |
| 3612 | final long identity = Binder.clearCallingIdentity(); |
| 3613 | try { |
| 3614 | return phone.getMeid(); |
| 3615 | } finally { |
| 3616 | Binder.restoreCallingIdentity(identity); |
| 3617 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3621 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3622 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3623 | String manufacturerCode = null; |
| 3624 | if (phone != null) { |
| 3625 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3626 | try { |
| 3627 | manufacturerCode = |
| 3628 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3629 | } catch (IndexOutOfBoundsException e) { |
| 3630 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3631 | return null; |
| 3632 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3633 | } |
| 3634 | return manufacturerCode; |
| 3635 | } |
| 3636 | |
| 3637 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3638 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3639 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3640 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3641 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3642 | return null; |
| 3643 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3644 | int subId = phone.getSubId(); |
| 3645 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3646 | mApp, subId, callingPackage, callingFeatureId, |
| 3647 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3648 | return null; |
| 3649 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3650 | |
| 3651 | final long identity = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | return phone.getDeviceSvn(); |
| 3654 | } finally { |
| 3655 | Binder.restoreCallingIdentity(identity); |
| 3656 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3659 | @Override |
| 3660 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
| 3663 | final Phone phone = getPhone(subId); |
| 3664 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3665 | } finally { |
| 3666 | Binder.restoreCallingIdentity(identity); |
| 3667 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | @Override |
| 3671 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3672 | final long identity = Binder.clearCallingIdentity(); |
| 3673 | try { |
| 3674 | final Phone phone = getPhone(subId); |
| 3675 | return phone == null ? null : phone.getCarrierName(); |
| 3676 | } finally { |
| 3677 | Binder.restoreCallingIdentity(identity); |
| 3678 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3679 | } |
| 3680 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3681 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3682 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3683 | final long identity = Binder.clearCallingIdentity(); |
| 3684 | try { |
| 3685 | final Phone phone = getPhone(subId); |
| 3686 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3687 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(identity); |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3694 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3695 | final long identity = Binder.clearCallingIdentity(); |
| 3696 | try { |
| 3697 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3698 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
| 3701 | } |
| 3702 | } |
| 3703 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3704 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3705 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3706 | if (!isSubscriptionMccMnc) { |
| 3707 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3708 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3709 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3710 | if (phone == null) { |
| 3711 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3712 | } |
| 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3716 | } finally { |
| 3717 | Binder.restoreCallingIdentity(identity); |
| 3718 | } |
| 3719 | } |
| 3720 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3721 | // |
| 3722 | // Internal helper methods. |
| 3723 | // |
| 3724 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3725 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3726 | * Make sure the caller is the calling package itself |
| 3727 | * |
| 3728 | * @throws SecurityException if the caller is not the calling package |
| 3729 | */ |
| 3730 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3731 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3732 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3733 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3734 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3735 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3736 | } catch (PackageManager.NameNotFoundException e) { |
| 3737 | // packageUid is -1 |
| 3738 | } |
| 3739 | if (packageUid != callingUid) { |
| 3740 | throw new SecurityException(message + ": Package " + callingPackage |
| 3741 | + " does not belong to " + callingUid); |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3746 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3747 | * |
| 3748 | * @throws SecurityException if the caller does not have the required permission |
| 3749 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3750 | @VisibleForTesting |
| 3751 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3752 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3753 | } |
| 3754 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3755 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3756 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3757 | * |
| 3758 | * @throws SecurityException if the caller does not have the required permission |
| 3759 | */ |
| 3760 | @VisibleForTesting |
| 3761 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3762 | enforceReadPermission(null); |
| 3763 | } |
| 3764 | |
| 3765 | /** |
| 3766 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3767 | * |
| 3768 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3769 | */ |
| 3770 | @VisibleForTesting |
| 3771 | public void enforceReadPermission(String msg) { |
| 3772 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3775 | private void enforceActiveEmergencySessionPermission() { |
| 3776 | mApp.enforceCallingOrSelfPermission( |
| 3777 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3778 | } |
| 3779 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3780 | /** |
| 3781 | * Make sure the caller has the CALL_PHONE permission. |
| 3782 | * |
| 3783 | * @throws SecurityException if the caller does not have the required permission |
| 3784 | */ |
| 3785 | private void enforceCallPermission() { |
| 3786 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3787 | } |
| 3788 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3789 | private void enforceSettingsPermission() { |
| 3790 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3791 | } |
| 3792 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3793 | private void enforceRebootPermission() { |
| 3794 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3795 | } |
| 3796 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3797 | /** |
| 3798 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3799 | * @param message - log message to print. |
| 3800 | * @throws SecurityException if the caller does not have the required permission |
| 3801 | */ |
| 3802 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3803 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3804 | } |
| 3805 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3806 | private String createTelUrl(String number) { |
| 3807 | if (TextUtils.isEmpty(number)) { |
| 3808 | return null; |
| 3809 | } |
| 3810 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3811 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3814 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3815 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3818 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3819 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3822 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3823 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3826 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3827 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3828 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3831 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3832 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3833 | final long identity = Binder.clearCallingIdentity(); |
| 3834 | try { |
| 3835 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3836 | if (phone == null) { |
| 3837 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3838 | } else { |
| 3839 | return phone.getPhoneType(); |
| 3840 | } |
| 3841 | } finally { |
| 3842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3843 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3844 | } |
| 3845 | |
| 3846 | /** |
| 3847 | * Returns the CDMA ERI icon index to display |
| 3848 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3849 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3850 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3851 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3852 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3853 | } |
| 3854 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3855 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3856 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3857 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3858 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3859 | mApp, subId, callingPackage, callingFeatureId, |
| 3860 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3861 | return -1; |
| 3862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | |
| 3864 | final long identity = Binder.clearCallingIdentity(); |
| 3865 | try { |
| 3866 | final Phone phone = getPhone(subId); |
| 3867 | if (phone != null) { |
| 3868 | return phone.getCdmaEriIconIndex(); |
| 3869 | } else { |
| 3870 | return -1; |
| 3871 | } |
| 3872 | } finally { |
| 3873 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | /** |
| 3878 | * Returns the CDMA ERI icon mode, |
| 3879 | * 0 - ON |
| 3880 | * 1 - FLASHING |
| 3881 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3882 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3883 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3884 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3885 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3888 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3889 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3890 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3891 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3892 | mApp, subId, callingPackage, callingFeatureId, |
| 3893 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3894 | return -1; |
| 3895 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3896 | |
| 3897 | final long identity = Binder.clearCallingIdentity(); |
| 3898 | try { |
| 3899 | final Phone phone = getPhone(subId); |
| 3900 | if (phone != null) { |
| 3901 | return phone.getCdmaEriIconMode(); |
| 3902 | } else { |
| 3903 | return -1; |
| 3904 | } |
| 3905 | } finally { |
| 3906 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3907 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | /** |
| 3911 | * Returns the CDMA ERI text, |
| 3912 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3913 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3914 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3915 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3916 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3917 | } |
| 3918 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3919 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3920 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3921 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3922 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3923 | mApp, subId, callingPackage, callingFeatureId, |
| 3924 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3925 | return null; |
| 3926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | |
| 3928 | final long identity = Binder.clearCallingIdentity(); |
| 3929 | try { |
| 3930 | final Phone phone = getPhone(subId); |
| 3931 | if (phone != null) { |
| 3932 | return phone.getCdmaEriText(); |
| 3933 | } else { |
| 3934 | return null; |
| 3935 | } |
| 3936 | } finally { |
| 3937 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3938 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3942 | * Returns the CDMA MDN. |
| 3943 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3944 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3945 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3946 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3947 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3948 | |
| 3949 | final long identity = Binder.clearCallingIdentity(); |
| 3950 | try { |
| 3951 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3952 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3953 | return phone.getLine1Number(); |
| 3954 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3955 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3956 | return null; |
| 3957 | } |
| 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | /** |
| 3964 | * Returns the CDMA MIN. |
| 3965 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3966 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3967 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3969 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3970 | |
| 3971 | final long identity = Binder.clearCallingIdentity(); |
| 3972 | try { |
| 3973 | final Phone phone = getPhone(subId); |
| 3974 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3975 | return phone.getCdmaMin(); |
| 3976 | } else { |
| 3977 | return null; |
| 3978 | } |
| 3979 | } finally { |
| 3980 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3984 | @Override |
| 3985 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3986 | INumberVerificationCallback callback, String callingPackage) { |
| 3987 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3988 | != PERMISSION_GRANTED) { |
| 3989 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3990 | } |
| 3991 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3992 | |
| 3993 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3994 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3995 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3996 | + "calling package: " + callingPackage |
| 3997 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3998 | } |
| 3999 | |
| 4000 | if (range == null) { |
| 4001 | throw new NullPointerException("Range must be non-null"); |
| 4002 | } |
| 4003 | |
| 4004 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4005 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4006 | |
| 4007 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4008 | } |
| 4009 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4010 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4011 | * Returns true if CDMA provisioning needs to run. |
| 4012 | */ |
| 4013 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4014 | final long identity = Binder.clearCallingIdentity(); |
| 4015 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4016 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | } finally { |
| 4018 | Binder.restoreCallingIdentity(identity); |
| 4019 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4023 | * Sets the voice mail number of a given subId. |
| 4024 | */ |
| 4025 | @Override |
| 4026 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4027 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4028 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4029 | |
| 4030 | final long identity = Binder.clearCallingIdentity(); |
| 4031 | try { |
| 4032 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4033 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4034 | return success; |
| 4035 | } finally { |
| 4036 | Binder.restoreCallingIdentity(identity); |
| 4037 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4038 | } |
| 4039 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4040 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4041 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4042 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4043 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4044 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4045 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4046 | throw new SecurityException("caller must be system dialer"); |
| 4047 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | |
| 4049 | final long identity = Binder.clearCallingIdentity(); |
| 4050 | try { |
| 4051 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4052 | if (phoneAccountHandle == null) { |
| 4053 | return null; |
| 4054 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4055 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4058 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4062 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4063 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4064 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4065 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4066 | mApp, subId, callingPackage, callingFeatureId, |
| 4067 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4068 | return null; |
| 4069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4070 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4071 | final long identity = Binder.clearCallingIdentity(); |
| 4072 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4073 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4074 | } finally { |
| 4075 | Binder.restoreCallingIdentity(identity); |
| 4076 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4080 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4081 | VisualVoicemailSmsFilterSettings settings) { |
| 4082 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4083 | |
| 4084 | final long identity = Binder.clearCallingIdentity(); |
| 4085 | try { |
| 4086 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4087 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4088 | } finally { |
| 4089 | Binder.restoreCallingIdentity(identity); |
| 4090 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4094 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4095 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4096 | |
| 4097 | final long identity = Binder.clearCallingIdentity(); |
| 4098 | try { |
| 4099 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4100 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(identity); |
| 4103 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4107 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4108 | String callingPackage, int subId) { |
| 4109 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4110 | |
| 4111 | final long identity = Binder.clearCallingIdentity(); |
| 4112 | try { |
| 4113 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4114 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4115 | } finally { |
| 4116 | Binder.restoreCallingIdentity(identity); |
| 4117 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4121 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4122 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4123 | |
| 4124 | final long identity = Binder.clearCallingIdentity(); |
| 4125 | try { |
| 4126 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4127 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4128 | } finally { |
| 4129 | Binder.restoreCallingIdentity(identity); |
| 4130 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4134 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4135 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4136 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4137 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4138 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4139 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4140 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4141 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4142 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4143 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4144 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4145 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4146 | * Sets the voice activation state of a given subId. |
| 4147 | */ |
| 4148 | @Override |
| 4149 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4151 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4152 | |
| 4153 | final long identity = Binder.clearCallingIdentity(); |
| 4154 | try { |
| 4155 | final Phone phone = getPhone(subId); |
| 4156 | if (phone != null) { |
| 4157 | phone.setVoiceActivationState(activationState); |
| 4158 | } else { |
| 4159 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4160 | } |
| 4161 | } finally { |
| 4162 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | /** |
| 4167 | * Sets the data activation state of a given subId. |
| 4168 | */ |
| 4169 | @Override |
| 4170 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4172 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4173 | |
| 4174 | final long identity = Binder.clearCallingIdentity(); |
| 4175 | try { |
| 4176 | final Phone phone = getPhone(subId); |
| 4177 | if (phone != null) { |
| 4178 | phone.setDataActivationState(activationState); |
| 4179 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4180 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4181 | } |
| 4182 | } finally { |
| 4183 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | /** |
| 4188 | * Returns the voice activation state of a given subId. |
| 4189 | */ |
| 4190 | @Override |
| 4191 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4192 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4193 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4194 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 | final long identity = Binder.clearCallingIdentity(); |
| 4196 | try { |
| 4197 | if (phone != null) { |
| 4198 | return phone.getVoiceActivationState(); |
| 4199 | } else { |
| 4200 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4201 | } |
| 4202 | } finally { |
| 4203 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | /** |
| 4208 | * Returns the data activation state of a given subId. |
| 4209 | */ |
| 4210 | @Override |
| 4211 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4212 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4214 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | final long identity = Binder.clearCallingIdentity(); |
| 4216 | try { |
| 4217 | if (phone != null) { |
| 4218 | return phone.getDataActivationState(); |
| 4219 | } else { |
| 4220 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4221 | } |
| 4222 | } finally { |
| 4223 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4228 | * Returns the unread count of voicemails for a subId |
| 4229 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4230 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4231 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4232 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4233 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4234 | mApp, subId, callingPackage, callingFeatureId, |
| 4235 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4236 | return 0; |
| 4237 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4238 | final long identity = Binder.clearCallingIdentity(); |
| 4239 | try { |
| 4240 | final Phone phone = getPhone(subId); |
| 4241 | if (phone != null) { |
| 4242 | return phone.getVoiceMessageCount(); |
| 4243 | } else { |
| 4244 | return 0; |
| 4245 | } |
| 4246 | } finally { |
| 4247 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4248 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4252 | * returns true, if the device is in a state where both voice and data |
| 4253 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4254 | */ |
| 4255 | @Override |
| 4256 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4257 | final long identity = Binder.clearCallingIdentity(); |
| 4258 | try { |
| 4259 | final Phone phone = getPhone(subId); |
| 4260 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4261 | } finally { |
| 4262 | Binder.restoreCallingIdentity(identity); |
| 4263 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4267 | * Send the dialer code if called from the current default dialer or the caller has |
| 4268 | * carrier privilege. |
| 4269 | * @param inputCode The dialer code to send |
| 4270 | */ |
| 4271 | @Override |
| 4272 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4273 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4274 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4275 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4276 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4277 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4278 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4279 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4280 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4281 | |
| 4282 | final long identity = Binder.clearCallingIdentity(); |
| 4283 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4284 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4285 | } finally { |
| 4286 | Binder.restoreCallingIdentity(identity); |
| 4287 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4288 | } |
| 4289 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4290 | @Override |
| 4291 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4292 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4293 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4294 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4295 | final long identity = Binder.clearCallingIdentity(); |
| 4296 | try { |
| 4297 | if (!isActiveSubscription(subId)) { |
| 4298 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4299 | } |
| 4300 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4301 | } finally { |
| 4302 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4303 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4304 | } |
| 4305 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4306 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4307 | public boolean isInEmergencySmsMode() { |
| 4308 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
| 4311 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4312 | if (phone.isInEmergencySmsMode()) { |
| 4313 | return true; |
| 4314 | } |
| 4315 | } |
| 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
| 4318 | } |
| 4319 | return false; |
| 4320 | } |
| 4321 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4322 | /** |
| 4323 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4324 | * @param subId The subscription to use to check the configuration. |
| 4325 | * @param c The callback that will be used to send the result. |
| 4326 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4327 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4328 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4329 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4330 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4331 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4332 | |
| 4333 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4334 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4335 | "IMS not available on device."); |
| 4336 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4337 | final long token = Binder.clearCallingIdentity(); |
| 4338 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4339 | int slotId = getSlotIndexOrException(subId); |
| 4340 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4341 | |
| 4342 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4343 | if (controller != null) { |
| 4344 | ImsManager imsManager = controller.getImsManager(subId); |
| 4345 | if (imsManager != null) { |
| 4346 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4347 | } else { |
| 4348 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4349 | } |
| 4350 | } else { |
| 4351 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4352 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4353 | } catch (ImsException e) { |
| 4354 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4355 | } finally { |
| 4356 | Binder.restoreCallingIdentity(token); |
| 4357 | } |
| 4358 | } |
| 4359 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4360 | /** |
| 4361 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4362 | * @param subId The subscription to use to check the configuration. |
| 4363 | * @param c The callback that will be used to send the result. |
| 4364 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4365 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4366 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4367 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4368 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4369 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4370 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4371 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4372 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4373 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4374 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4375 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4376 | if (controller != null) { |
| 4377 | ImsManager imsManager = controller.getImsManager(subId); |
| 4378 | if (imsManager != null) { |
| 4379 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4380 | } else { |
| 4381 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4382 | + "is inactive, ignoring unregister."); |
| 4383 | // If the ImsManager is not valid, just return, since the callback |
| 4384 | // will already have been removed internally. |
| 4385 | } |
| 4386 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4387 | } finally { |
| 4388 | Binder.restoreCallingIdentity(token); |
| 4389 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4390 | } |
| 4391 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4392 | /** |
| 4393 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4394 | */ |
| 4395 | @Override |
| 4396 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4397 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4398 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4399 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4400 | "IMS not available on device."); |
| 4401 | } |
| 4402 | final long token = Binder.clearCallingIdentity(); |
| 4403 | try { |
| 4404 | Phone phone = getPhone(subId); |
| 4405 | if (phone == null) { |
| 4406 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4407 | + subId + "'"); |
| 4408 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4409 | } |
| 4410 | phone.getImsRegistrationState(regState -> { |
| 4411 | try { |
| 4412 | consumer.accept((regState == null) |
| 4413 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4414 | } catch (RemoteException e) { |
| 4415 | // Ignore if the remote process is no longer available to call back. |
| 4416 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4417 | } |
| 4418 | }); |
| 4419 | } finally { |
| 4420 | Binder.restoreCallingIdentity(token); |
| 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | /** |
| 4425 | * Get the transport type for the IMS service registration state. |
| 4426 | */ |
| 4427 | @Override |
| 4428 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4429 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4430 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4431 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4432 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4433 | "IMS not available on device."); |
| 4434 | } |
| 4435 | final long token = Binder.clearCallingIdentity(); |
| 4436 | try { |
| 4437 | Phone phone = getPhone(subId); |
| 4438 | if (phone == null) { |
| 4439 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4440 | + subId + "'"); |
| 4441 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4442 | } |
| 4443 | phone.getImsRegistrationTech(regTech -> { |
| 4444 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4445 | int regTechConverted = (regTech == null) |
| 4446 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4447 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4448 | regTechConverted); |
| 4449 | try { |
| 4450 | consumer.accept(regTechConverted); |
| 4451 | } catch (RemoteException e) { |
| 4452 | // Ignore if the remote process is no longer available to call back. |
| 4453 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4454 | } |
| 4455 | }); |
| 4456 | } finally { |
| 4457 | Binder.restoreCallingIdentity(token); |
| 4458 | } |
| 4459 | } |
| 4460 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4461 | /** |
| 4462 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4463 | * @param subId The subscription to use to check the configuration. |
| 4464 | * @param c The callback that will be used to send the result. |
| 4465 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4466 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4467 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4468 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4469 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4470 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4471 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4472 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4473 | "IMS not available on device."); |
| 4474 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4475 | final long token = Binder.clearCallingIdentity(); |
| 4476 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4477 | int slotId = getSlotIndexOrException(subId); |
| 4478 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4479 | |
| 4480 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4481 | if (controller != null) { |
| 4482 | ImsManager imsManager = controller.getImsManager(subId); |
| 4483 | if (imsManager != null) { |
| 4484 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4485 | } else { |
| 4486 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4487 | } |
| 4488 | } else { |
| 4489 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4490 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4491 | } catch (ImsException e) { |
| 4492 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4493 | } finally { |
| 4494 | Binder.restoreCallingIdentity(token); |
| 4495 | } |
| 4496 | } |
| 4497 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4498 | /** |
| 4499 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4500 | * @param subId The subscription to use to check the configuration. |
| 4501 | * @param c The callback that will be used to send the result. |
| 4502 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4503 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4504 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4505 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4506 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4507 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4508 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4509 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4510 | |
| 4511 | final long token = Binder.clearCallingIdentity(); |
| 4512 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4513 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4514 | if (controller != null) { |
| 4515 | ImsManager imsManager = controller.getImsManager(subId); |
| 4516 | if (imsManager != null) { |
| 4517 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4518 | } else { |
| 4519 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4520 | + " is inactive, ignoring unregister."); |
| 4521 | // If the ImsManager is not valid, just return, since the callback |
| 4522 | // will already have been removed internally. |
| 4523 | } |
| 4524 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4525 | } finally { |
| 4526 | Binder.restoreCallingIdentity(token); |
| 4527 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
| 4530 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4531 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4532 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4533 | final long token = Binder.clearCallingIdentity(); |
| 4534 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4535 | int slotId = getSlotIndexOrException(subId); |
| 4536 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4537 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4538 | } catch (com.android.ims.ImsException e) { |
| 4539 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4540 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4541 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4542 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4543 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4544 | } finally { |
| 4545 | Binder.restoreCallingIdentity(token); |
| 4546 | } |
| 4547 | } |
| 4548 | |
| 4549 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4550 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4551 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4552 | final long token = Binder.clearCallingIdentity(); |
| 4553 | try { |
| 4554 | Phone phone = getPhone(subId); |
| 4555 | if (phone == null) return false; |
| 4556 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4557 | } catch (com.android.ims.ImsException e) { |
| 4558 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4559 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4560 | } finally { |
| 4561 | Binder.restoreCallingIdentity(token); |
| 4562 | } |
| 4563 | } |
| 4564 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4565 | /** |
| 4566 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4567 | * subscription. |
| 4568 | * @param subId The subscription to use to check the configuration. |
| 4569 | * @param callback The callback that will be used to send the result. |
| 4570 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4571 | * @param transportType The transport type of the MmTelFeature capability. |
| 4572 | */ |
| 4573 | @Override |
| 4574 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4575 | int transportType) { |
| 4576 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4577 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4578 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4579 | "IMS not available on device."); |
| 4580 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4581 | final long token = Binder.clearCallingIdentity(); |
| 4582 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4583 | int slotId = getSlotIndex(subId); |
| 4584 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4585 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4586 | + subId + "'"); |
| 4587 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4588 | } |
| 4589 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4590 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4591 | transportType, aBoolean -> { |
| 4592 | try { |
| 4593 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4594 | } catch (RemoteException e) { |
| 4595 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4596 | + "running. Ignore"); |
| 4597 | } |
| 4598 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4599 | } catch (ImsException e) { |
| 4600 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4601 | } finally { |
| 4602 | Binder.restoreCallingIdentity(token); |
| 4603 | } |
| 4604 | } |
| 4605 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4606 | /** |
| 4607 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4608 | * @param subId The subscription to use to check the configuration. |
| 4609 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4610 | @Override |
| 4611 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4612 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4613 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4614 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4615 | final long token = Binder.clearCallingIdentity(); |
| 4616 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4617 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4618 | // 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] | 4619 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4620 | } catch (ImsException e) { |
| 4621 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4622 | } finally { |
| 4623 | Binder.restoreCallingIdentity(token); |
| 4624 | } |
| 4625 | } |
| 4626 | |
| 4627 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4628 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4630 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4631 | final long identity = Binder.clearCallingIdentity(); |
| 4632 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4633 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4634 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4635 | // 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] | 4636 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4637 | } catch (ImsException e) { |
| 4638 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(identity); |
| 4641 | } |
| 4642 | } |
| 4643 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4644 | /** |
| 4645 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4646 | * @param subId The subscription to use to check the configuration. |
| 4647 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4648 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4649 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4650 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4651 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4652 | final long identity = Binder.clearCallingIdentity(); |
| 4653 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4654 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4655 | // 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] | 4656 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4657 | } catch (ImsException e) { |
| 4658 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4659 | } finally { |
| 4660 | Binder.restoreCallingIdentity(identity); |
| 4661 | } |
| 4662 | } |
| 4663 | |
| 4664 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4665 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4666 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4667 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4668 | final long identity = Binder.clearCallingIdentity(); |
| 4669 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4670 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4671 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4672 | // 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] | 4673 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4674 | } catch (ImsException e) { |
| 4675 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4676 | } finally { |
| 4677 | Binder.restoreCallingIdentity(identity); |
| 4678 | } |
| 4679 | } |
| 4680 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4681 | /** |
| 4682 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4683 | * @param subId The subscription to use to check the configuration. |
| 4684 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4685 | @Override |
| 4686 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4687 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4688 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4689 | final long identity = Binder.clearCallingIdentity(); |
| 4690 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4691 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4692 | // 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] | 4693 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4694 | } catch (ImsException e) { |
| 4695 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4696 | } finally { |
| 4697 | Binder.restoreCallingIdentity(identity); |
| 4698 | } |
| 4699 | } |
| 4700 | |
| 4701 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4702 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4703 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4704 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4705 | final long identity = Binder.clearCallingIdentity(); |
| 4706 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4707 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4708 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4709 | // 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] | 4710 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4711 | } catch (ImsException e) { |
| 4712 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4713 | } finally { |
| 4714 | Binder.restoreCallingIdentity(identity); |
| 4715 | } |
| 4716 | } |
| 4717 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4718 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4719 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4720 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4721 | * @param subId The subscription to use to check the configuration. |
| 4722 | */ |
| 4723 | @Override |
| 4724 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4725 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4726 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4727 | final long identity = Binder.clearCallingIdentity(); |
| 4728 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4729 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4730 | // 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] | 4731 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4732 | } catch (ImsException e) { |
| 4733 | throw new ServiceSpecificException(e.getCode()); |
| 4734 | } finally { |
| 4735 | Binder.restoreCallingIdentity(identity); |
| 4736 | } |
| 4737 | } |
| 4738 | |
| 4739 | /** |
| 4740 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4741 | * Requires MODIFY_PHONE_STATE permission. |
| 4742 | * @param subId The subscription to use to check the configuration. |
| 4743 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4744 | * false otherwise |
| 4745 | */ |
| 4746 | @Override |
| 4747 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4748 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4749 | "setCrossSimCallingEnabled"); |
| 4750 | final long identity = Binder.clearCallingIdentity(); |
| 4751 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4752 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4753 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4754 | // 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] | 4755 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4756 | } catch (ImsException e) { |
| 4757 | throw new ServiceSpecificException(e.getCode()); |
| 4758 | } finally { |
| 4759 | Binder.restoreCallingIdentity(identity); |
| 4760 | } |
| 4761 | } |
| 4762 | |
| 4763 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4764 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4765 | * @param subId The subscription to use to check the configuration. |
| 4766 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4767 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4768 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4769 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4770 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4771 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4772 | final long identity = Binder.clearCallingIdentity(); |
| 4773 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4774 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4775 | // 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] | 4776 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4777 | } catch (ImsException e) { |
| 4778 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4779 | } finally { |
| 4780 | Binder.restoreCallingIdentity(identity); |
| 4781 | } |
| 4782 | } |
| 4783 | |
| 4784 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4785 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4786 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4787 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4788 | final long identity = Binder.clearCallingIdentity(); |
| 4789 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4790 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4791 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4792 | // 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] | 4793 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4794 | } catch (ImsException e) { |
| 4795 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4796 | } finally { |
| 4797 | Binder.restoreCallingIdentity(identity); |
| 4798 | } |
| 4799 | } |
| 4800 | |
| 4801 | @Override |
| 4802 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4803 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4804 | "setVoWiFiNonPersistent"); |
| 4805 | final long identity = Binder.clearCallingIdentity(); |
| 4806 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4807 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4808 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4809 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4810 | } catch (ImsException e) { |
| 4811 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4812 | } finally { |
| 4813 | Binder.restoreCallingIdentity(identity); |
| 4814 | } |
| 4815 | } |
| 4816 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4817 | /** |
| 4818 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4819 | * @param subId The subscription to use to check the configuration. |
| 4820 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4821 | @Override |
| 4822 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4823 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4824 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4825 | final long identity = Binder.clearCallingIdentity(); |
| 4826 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4827 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4828 | // 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] | 4829 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4830 | } catch (ImsException e) { |
| 4831 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4832 | } finally { |
| 4833 | Binder.restoreCallingIdentity(identity); |
| 4834 | } |
| 4835 | } |
| 4836 | |
| 4837 | @Override |
| 4838 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4840 | "setVoWiFiModeSetting"); |
| 4841 | final long identity = Binder.clearCallingIdentity(); |
| 4842 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4843 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4844 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4845 | // 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] | 4846 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4847 | } catch (ImsException e) { |
| 4848 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4849 | } finally { |
| 4850 | Binder.restoreCallingIdentity(identity); |
| 4851 | } |
| 4852 | } |
| 4853 | |
| 4854 | @Override |
| 4855 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4856 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4857 | final long identity = Binder.clearCallingIdentity(); |
| 4858 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4859 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4860 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4861 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4862 | } catch (ImsException e) { |
| 4863 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4864 | } finally { |
| 4865 | Binder.restoreCallingIdentity(identity); |
| 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | @Override |
| 4870 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4872 | "setVoWiFiRoamingModeSetting"); |
| 4873 | final long identity = Binder.clearCallingIdentity(); |
| 4874 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4875 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4876 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4877 | // 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] | 4878 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4879 | } catch (ImsException e) { |
| 4880 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4881 | } finally { |
| 4882 | Binder.restoreCallingIdentity(identity); |
| 4883 | } |
| 4884 | } |
| 4885 | |
| 4886 | @Override |
| 4887 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4889 | "setRttCapabilityEnabled"); |
| 4890 | final long identity = Binder.clearCallingIdentity(); |
| 4891 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4892 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4893 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4894 | // 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] | 4895 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4896 | } catch (ImsException e) { |
| 4897 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4898 | } finally { |
| 4899 | Binder.restoreCallingIdentity(identity); |
| 4900 | } |
| 4901 | } |
| 4902 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4903 | /** |
| 4904 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4905 | * @param subId The subscription to use to check the configuration. |
| 4906 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4907 | @Override |
| 4908 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4909 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4910 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4911 | final long identity = Binder.clearCallingIdentity(); |
| 4912 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4913 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4914 | // 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] | 4915 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4916 | } catch (ImsException e) { |
| 4917 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4918 | } finally { |
| 4919 | Binder.restoreCallingIdentity(identity); |
| 4920 | } |
| 4921 | } |
| 4922 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4923 | @Override |
| 4924 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4925 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4926 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4927 | final long identity = Binder.clearCallingIdentity(); |
| 4928 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4929 | if (!isImsAvailableOnDevice()) { |
| 4930 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4931 | "IMS not available on device."); |
| 4932 | } |
| 4933 | int slotId = getSlotIndexOrException(subId); |
| 4934 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4935 | |
| 4936 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4937 | if (controller != null) { |
| 4938 | ImsManager imsManager = controller.getImsManager(subId); |
| 4939 | if (imsManager != null) { |
| 4940 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 4941 | } else { |
| 4942 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4943 | } |
| 4944 | } else { |
| 4945 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4946 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4947 | } catch (ImsException e) { |
| 4948 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4949 | } finally { |
| 4950 | Binder.restoreCallingIdentity(identity); |
| 4951 | } |
| 4952 | } |
| 4953 | |
| 4954 | @Override |
| 4955 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4956 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4957 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4958 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4959 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4960 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4961 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4962 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4963 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4964 | if (controller != null) { |
| 4965 | ImsManager imsManager = controller.getImsManager(subId); |
| 4966 | if (imsManager != null) { |
| 4967 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 4968 | } else { |
| 4969 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4970 | + " is inactive, ignoring unregister."); |
| 4971 | // If the ImsManager is not valid, just return, since the callback will already |
| 4972 | // have been removed internally. |
| 4973 | } |
| 4974 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4975 | } finally { |
| 4976 | Binder.restoreCallingIdentity(identity); |
| 4977 | } |
| 4978 | } |
| 4979 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4980 | @Override |
| 4981 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4982 | IFeatureProvisioningCallback callback) { |
| 4983 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4984 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4985 | |
| 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4988 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4989 | } |
| 4990 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4991 | try { |
| 4992 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4993 | if (controller == null) { |
| 4994 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4995 | "Device does not support IMS"); |
| 4996 | } |
| 4997 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4998 | } finally { |
| 4999 | Binder.restoreCallingIdentity(identity); |
| 5000 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5001 | } |
| 5002 | |
| 5003 | @Override |
| 5004 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5005 | IFeatureProvisioningCallback callback) { |
| 5006 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5007 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5008 | |
| 5009 | final long identity = Binder.clearCallingIdentity(); |
| 5010 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5011 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5012 | } |
| 5013 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5014 | try { |
| 5015 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5016 | if (controller == null) { |
| 5017 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5018 | return; |
| 5019 | } |
| 5020 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5021 | } finally { |
| 5022 | Binder.restoreCallingIdentity(identity); |
| 5023 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5024 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5025 | |
| 5026 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5027 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5028 | message); |
| 5029 | } |
| 5030 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5031 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5032 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5033 | boolean isProvisioned) { |
| 5034 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5035 | |
| 5036 | final long identity = Binder.clearCallingIdentity(); |
| 5037 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5038 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5039 | if (controller == null) { |
| 5040 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5041 | return; |
| 5042 | } |
| 5043 | controller.setRcsProvisioningStatusForCapability( |
| 5044 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5045 | } finally { |
| 5046 | Binder.restoreCallingIdentity(identity); |
| 5047 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | |
| 5051 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5052 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5053 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5054 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5055 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5056 | final long identity = Binder.clearCallingIdentity(); |
| 5057 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5058 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5059 | if (controller == null) { |
| 5060 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5061 | |
| 5062 | // device does not support IMS, this method will return true always. |
| 5063 | return true; |
| 5064 | } |
| 5065 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5066 | } finally { |
| 5067 | Binder.restoreCallingIdentity(identity); |
| 5068 | } |
| 5069 | } |
| 5070 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5071 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5072 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5073 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5074 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5075 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5076 | final long identity = Binder.clearCallingIdentity(); |
| 5077 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5078 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5079 | if (controller == null) { |
| 5080 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5081 | return; |
| 5082 | } |
| 5083 | controller.setImsProvisioningStatusForCapability( |
| 5084 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
| 5087 | } |
| 5088 | } |
| 5089 | |
| 5090 | @Override |
| 5091 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5092 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5093 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5094 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5095 | final long identity = Binder.clearCallingIdentity(); |
| 5096 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5097 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5098 | if (controller == null) { |
| 5099 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5100 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5101 | // device does not support IMS, this method will return true always. |
| 5102 | return true; |
| 5103 | } |
| 5104 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5105 | } finally { |
| 5106 | Binder.restoreCallingIdentity(identity); |
| 5107 | } |
| 5108 | } |
| 5109 | |
| 5110 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5111 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5112 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5113 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5114 | |
| 5115 | final long identity = Binder.clearCallingIdentity(); |
| 5116 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5117 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5118 | if (controller == null) { |
| 5119 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5120 | |
| 5121 | // device does not support IMS, this method will return false |
| 5122 | return false; |
| 5123 | } |
| 5124 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5127 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5131 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5132 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5133 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5134 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5135 | final long identity = Binder.clearCallingIdentity(); |
| 5136 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5137 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5138 | if (controller == null) { |
| 5139 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5140 | |
| 5141 | // device does not support IMS, this method will return false |
| 5142 | return false; |
| 5143 | } |
| 5144 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5145 | } finally { |
| 5146 | Binder.restoreCallingIdentity(identity); |
| 5147 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5148 | } |
| 5149 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5150 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5151 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5152 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5153 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5154 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5155 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5156 | mApp, subId, "getImsProvisioningInt"); |
| 5157 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5158 | final long identity = Binder.clearCallingIdentity(); |
| 5159 | try { |
| 5160 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5161 | int slotId = getSlotIndex(subId); |
| 5162 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5163 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5164 | + subId + "' for key:" + key); |
| 5165 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5166 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5167 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5168 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5169 | if (controller == null) { |
| 5170 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5171 | |
| 5172 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5173 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5174 | } |
| 5175 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5176 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5177 | return retVal; |
| 5178 | } |
| 5179 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5180 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5181 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5182 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5183 | + subId + "' for key:" + key); |
| 5184 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5185 | } finally { |
| 5186 | Binder.restoreCallingIdentity(identity); |
| 5187 | } |
| 5188 | } |
| 5189 | |
| 5190 | @Override |
| 5191 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5192 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5193 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5194 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5195 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5196 | mApp, subId, "getImsProvisioningString"); |
| 5197 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5198 | final long identity = Binder.clearCallingIdentity(); |
| 5199 | try { |
| 5200 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5201 | int slotId = getSlotIndex(subId); |
| 5202 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5203 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5204 | + subId + "' for key:" + key); |
| 5205 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5206 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5207 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5208 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5209 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5210 | + subId + "' for key:" + key); |
| 5211 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5212 | } finally { |
| 5213 | Binder.restoreCallingIdentity(identity); |
| 5214 | } |
| 5215 | } |
| 5216 | |
| 5217 | @Override |
| 5218 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5219 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5220 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5221 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5222 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5223 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5224 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5225 | final long identity = Binder.clearCallingIdentity(); |
| 5226 | try { |
| 5227 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5228 | int slotId = getSlotIndex(subId); |
| 5229 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5230 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5231 | + subId + "' for key:" + key); |
| 5232 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5233 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5234 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5235 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5236 | if (controller == null) { |
| 5237 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5238 | |
| 5239 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5240 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5241 | } |
| 5242 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5243 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5244 | return retVal; |
| 5245 | } |
| 5246 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5247 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5248 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5249 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5250 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5251 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5252 | } finally { |
| 5253 | Binder.restoreCallingIdentity(identity); |
| 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | @Override |
| 5258 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5259 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5260 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5261 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5262 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5263 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5264 | final long identity = Binder.clearCallingIdentity(); |
| 5265 | try { |
| 5266 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5267 | int slotId = getSlotIndex(subId); |
| 5268 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5269 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5270 | + subId + "' for key:" + key); |
| 5271 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5272 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5273 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5274 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5275 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5276 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5277 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5278 | } finally { |
| 5279 | Binder.restoreCallingIdentity(identity); |
| 5280 | } |
| 5281 | } |
| 5282 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5283 | /** |
| 5284 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5285 | * for the given slot ID or no ImsResolver instance has been created. |
| 5286 | * @param slotId The slot ID that the IMS service is created for. |
| 5287 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5288 | */ |
| 5289 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5290 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5291 | ImsFeature.FEATURE_MMTEL)) { |
| 5292 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5293 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5294 | } |
| 5295 | } |
| 5296 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5297 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5298 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5299 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5300 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5301 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5302 | } |
| 5303 | return slotId; |
| 5304 | } |
| 5305 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5306 | private int getSlotIndex(int subId) { |
| 5307 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5308 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5309 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5310 | } |
| 5311 | return slotId; |
| 5312 | } |
| 5313 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5314 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5315 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5316 | */ |
| 5317 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5318 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5319 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5320 | try { |
| 5321 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5322 | } catch (SecurityException se) { |
| 5323 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5324 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5325 | + Binder.getCallingUid()); |
| 5326 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5327 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5328 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5329 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5330 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5331 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5332 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5333 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5334 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5335 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5336 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5337 | final long identity = Binder.clearCallingIdentity(); |
| 5338 | try { |
| 5339 | final Phone phone = getPhone(subId); |
| 5340 | if (phone != null) { |
| 5341 | return phone.getServiceState().getDataNetworkType(); |
| 5342 | } else { |
| 5343 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5344 | } |
| 5345 | } finally { |
| 5346 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5347 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | /** |
| 5351 | * Returns the data network type |
| 5352 | */ |
| 5353 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5354 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5355 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5356 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | /** |
| 5360 | * Returns the data network type for a subId |
| 5361 | */ |
| 5362 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5363 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5364 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5365 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5366 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5367 | mApp, functionName)) { |
| 5368 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5369 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5370 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5371 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5372 | } |
| 5373 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5374 | final long identity = Binder.clearCallingIdentity(); |
| 5375 | try { |
| 5376 | final Phone phone = getPhone(subId); |
| 5377 | if (phone != null) { |
| 5378 | return phone.getServiceState().getDataNetworkType(); |
| 5379 | } else { |
| 5380 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5381 | } |
| 5382 | } finally { |
| 5383 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5384 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5388 | * Returns the Voice network type for a subId |
| 5389 | */ |
| 5390 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5391 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5392 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5393 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5394 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5395 | mApp, functionName)) { |
| 5396 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5397 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5398 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5399 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5400 | } |
| 5401 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5402 | final long identity = Binder.clearCallingIdentity(); |
| 5403 | try { |
| 5404 | final Phone phone = getPhone(subId); |
| 5405 | if (phone != null) { |
| 5406 | return phone.getServiceState().getVoiceNetworkType(); |
| 5407 | } else { |
| 5408 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5409 | } |
| 5410 | } finally { |
| 5411 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5412 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | /** |
| 5416 | * @return true if a ICC card is present |
| 5417 | */ |
| 5418 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5419 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5420 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5421 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5425 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5426 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5427 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5428 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5429 | final long identity = Binder.clearCallingIdentity(); |
| 5430 | try { |
| 5431 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5432 | if (phone != null) { |
| 5433 | return phone.getIccCard().hasIccCard(); |
| 5434 | } else { |
| 5435 | return false; |
| 5436 | } |
| 5437 | } finally { |
| 5438 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5439 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | /** |
| 5443 | * Return if the current radio is LTE on CDMA. This |
| 5444 | * is a tri-state return value as for a period of time |
| 5445 | * the mode may be unknown. |
| 5446 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5447 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5448 | * @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] | 5449 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5450 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5451 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5452 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5453 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5454 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5455 | } |
| 5456 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5457 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5458 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5459 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5460 | try { |
| 5461 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5462 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5463 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5464 | } |
| 5465 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5466 | final long identity = Binder.clearCallingIdentity(); |
| 5467 | try { |
| 5468 | final Phone phone = getPhone(subId); |
| 5469 | if (phone == null) { |
| 5470 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5471 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5472 | return TelephonyProperties.lte_on_cdma_device() |
| 5473 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5474 | } |
| 5475 | } finally { |
| 5476 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5477 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5478 | } |
| 5479 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5480 | /** |
| 5481 | * {@hide} |
| 5482 | * Returns Default subId, 0 in the case of single standby. |
| 5483 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5484 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5485 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5486 | } |
| 5487 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5488 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5489 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5490 | } |
| 5491 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5492 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5493 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5494 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5495 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5496 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5497 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 5498 | return getSubscriptionManagerService().isActiveSubId(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5499 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5500 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5501 | return mSubscriptionController.isActiveSubId(subId); |
| 5502 | } |
| 5503 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5504 | /** |
| 5505 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5506 | */ |
| 5507 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5508 | final long identity = Binder.clearCallingIdentity(); |
| 5509 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5510 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5512 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5513 | } finally { |
| 5514 | Binder.restoreCallingIdentity(identity); |
| 5515 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | /** |
| 5519 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5520 | */ |
| 5521 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
| 5524 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5525 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5526 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5527 | } finally { |
| 5528 | Binder.restoreCallingIdentity(identity); |
| 5529 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5530 | } |
| 5531 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5532 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5533 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5534 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5535 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5536 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5537 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5538 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5539 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5540 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5541 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5542 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5543 | } |
| 5544 | return PhoneFactory.getPhone(phoneId); |
| 5545 | } |
| 5546 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5547 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5548 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5549 | @NonNull IccLogicalChannelRequest request) { |
| 5550 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5551 | /*message=*/ "iccOpenLogicalChannel"); |
| 5552 | |
| 5553 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5554 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5555 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5556 | |
| 5557 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5558 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5559 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5560 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5561 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5562 | Phone phone; |
| 5563 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5564 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5565 | mApp, request.subId, message); |
| 5566 | phone = getPhoneFromSubId(request.subId); |
| 5567 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5568 | enforceModifyPermission(); |
| 5569 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5570 | } else { |
| 5571 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5572 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5573 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5577 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5580 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5582 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5583 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5584 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5585 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | loge("The calling package is not allowed to access ISD-R."); |
| 5587 | throw new SecurityException( |
| 5588 | "The calling package is not allowed to access ISD-R."); |
| 5589 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5590 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5591 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5592 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5593 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5594 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 | return response; |
| 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
| 5598 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5602 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5603 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5604 | /*message=*/"iccCloseLogicalChannel"); |
| 5605 | |
| 5606 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5607 | |
| 5608 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5609 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5610 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5611 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5612 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5613 | // before this feature is enabled, this API should only return false if |
| 5614 | // the operation fails instead of throwing runtime exception for |
| 5615 | // backward-compatibility. |
| 5616 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5617 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5618 | final long identity = Binder.clearCallingIdentity(); |
| 5619 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5620 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5621 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5622 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5623 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5624 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5625 | Boolean success = false; |
| 5626 | if (result instanceof RuntimeException) { |
| 5627 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5628 | if (shouldThrowExceptionOnFailure) { |
| 5629 | throw (RuntimeException) result; |
| 5630 | } else { |
| 5631 | return false; |
| 5632 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5633 | } else if (result instanceof Boolean) { |
| 5634 | success = (Boolean) result; |
| 5635 | } else { |
| 5636 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5637 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5638 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | return success; |
| 5640 | } finally { |
| 5641 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5642 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5643 | } |
| 5644 | |
| 5645 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5646 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5647 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5648 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5649 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5650 | if (DBG) { |
| 5651 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5652 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5653 | + p3 + " data=" + data); |
| 5654 | } |
| 5655 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5656 | command, p1, p2, p3, data); |
| 5657 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5658 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5659 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5660 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5661 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5662 | enforceModifyPermission(); |
| 5663 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5664 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5665 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5666 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5667 | } |
| 5668 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5669 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5670 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5671 | } |
| 5672 | |
| 5673 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5674 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5675 | final long identity = Binder.clearCallingIdentity(); |
| 5676 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5677 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5678 | return ""; |
| 5679 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5680 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5682 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5683 | null /* workSource */); |
| 5684 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5685 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | // Append the returned status code to the end of the response payload. |
| 5687 | String s = Integer.toHexString( |
| 5688 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5689 | if (response.payload != null) { |
| 5690 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5691 | } |
| 5692 | return s; |
| 5693 | } finally { |
| 5694 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5695 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5696 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5697 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5698 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5699 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5700 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5701 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5702 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5703 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5704 | if (DBG) { |
| 5705 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5706 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5707 | } |
| 5708 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5709 | cla, command, p1, p2, p3, data); |
| 5710 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5711 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5712 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5713 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5714 | 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] | 5715 | enforceModifyPermission(); |
| 5716 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5717 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5718 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5719 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5720 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5724 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5725 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5729 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5730 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5731 | final long identity = Binder.clearCallingIdentity(); |
| 5732 | try { |
| 5733 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5734 | && TextUtils.equals(ISDR_AID, data)) { |
| 5735 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5736 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5737 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5738 | if (bestComponent == null |
| 5739 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5740 | loge("The calling package is not allowed to select ISD-R."); |
| 5741 | throw new SecurityException( |
| 5742 | "The calling package is not allowed to select ISD-R."); |
| 5743 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5744 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5746 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5747 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5748 | null /* workSource */); |
| 5749 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | // Append the returned status code to the end of the response payload. |
| 5752 | String s = Integer.toHexString( |
| 5753 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5754 | if (response.payload != null) { |
| 5755 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5756 | } |
| 5757 | return s; |
| 5758 | } finally { |
| 5759 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5760 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5764 | 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] | 5765 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5767 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5768 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | final long identity = Binder.clearCallingIdentity(); |
| 5770 | try { |
| 5771 | if (DBG) { |
| 5772 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5773 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5774 | } |
| 5775 | |
| 5776 | IccIoResult response = |
| 5777 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5778 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5779 | subId); |
| 5780 | |
| 5781 | if (DBG) { |
| 5782 | log("Exchange SIM_IO [R]" + response); |
| 5783 | } |
| 5784 | |
| 5785 | byte[] result = null; |
| 5786 | int length = 2; |
| 5787 | if (response.payload != null) { |
| 5788 | length = 2 + response.payload.length; |
| 5789 | result = new byte[length]; |
| 5790 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5791 | } else { |
| 5792 | result = new byte[length]; |
| 5793 | } |
| 5794 | |
| 5795 | result[length - 1] = (byte) response.sw2; |
| 5796 | result[length - 2] = (byte) response.sw1; |
| 5797 | return result; |
| 5798 | } finally { |
| 5799 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5800 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5801 | } |
| 5802 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5803 | /** |
| 5804 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5805 | * on a particular subscription |
| 5806 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5807 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5808 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5809 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5810 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5811 | return null; |
| 5812 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5813 | |
| 5814 | final long identity = Binder.clearCallingIdentity(); |
| 5815 | try { |
| 5816 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5817 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5818 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5819 | return null; |
| 5820 | } |
| 5821 | Object response = sendRequest( |
| 5822 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5823 | if (response instanceof String[]) { |
| 5824 | return (String[]) response; |
| 5825 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5826 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5827 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5828 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5829 | } finally { |
| 5830 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5831 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5832 | } |
| 5833 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5834 | /** |
| 5835 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5836 | * subscription. |
| 5837 | * |
| 5838 | * @param subId the id of the subscription. |
| 5839 | * @param appType the uicc app type, must be USIM or SIM. |
| 5840 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5841 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5842 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5843 | * @return number of fplmns that is successfully written to the SIM. |
| 5844 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5845 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5846 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5847 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5848 | mApp, subId, "setForbiddenPlmns"); |
| 5849 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5850 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5851 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5852 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5853 | } |
| 5854 | if (fplmns == null) { |
| 5855 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5856 | } |
| 5857 | for (String fplmn : fplmns) { |
| 5858 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5859 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5860 | } |
| 5861 | } |
| 5862 | final long identity = Binder.clearCallingIdentity(); |
| 5863 | try { |
| 5864 | Object response = sendRequest( |
| 5865 | CMD_SET_FORBIDDEN_PLMNS, |
| 5866 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5867 | subId); |
| 5868 | return (int) response; |
| 5869 | } finally { |
| 5870 | Binder.restoreCallingIdentity(identity); |
| 5871 | } |
| 5872 | } |
| 5873 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5874 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5875 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5876 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5877 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | final long identity = Binder.clearCallingIdentity(); |
| 5880 | try { |
| 5881 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5882 | if (response.payload == null) { |
| 5883 | return ""; |
| 5884 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5885 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5886 | // Append the returned status code to the end of the response payload. |
| 5887 | String s = Integer.toHexString( |
| 5888 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5889 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5890 | return s; |
| 5891 | } finally { |
| 5892 | Binder.restoreCallingIdentity(identity); |
| 5893 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5894 | } |
| 5895 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5896 | /** |
| 5897 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5898 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5899 | * |
| 5900 | * @param itemID the ID of the item to read |
| 5901 | * @return the NV item as a String, or null on error. |
| 5902 | */ |
| 5903 | @Override |
| 5904 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5905 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5906 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5907 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5908 | |
| 5909 | final long identity = Binder.clearCallingIdentity(); |
| 5910 | try { |
| 5911 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5912 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5913 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5914 | return value; |
| 5915 | } finally { |
| 5916 | Binder.restoreCallingIdentity(identity); |
| 5917 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | /** |
| 5921 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5922 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5923 | * |
| 5924 | * @param itemID the ID of the item to read |
| 5925 | * @param itemValue the value to write, as a String |
| 5926 | * @return true on success; false on any failure |
| 5927 | */ |
| 5928 | @Override |
| 5929 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5930 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5932 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5933 | |
| 5934 | final long identity = Binder.clearCallingIdentity(); |
| 5935 | try { |
| 5936 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5937 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5938 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5939 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5940 | return success; |
| 5941 | } finally { |
| 5942 | Binder.restoreCallingIdentity(identity); |
| 5943 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5944 | } |
| 5945 | |
| 5946 | /** |
| 5947 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5948 | * Used for device configuration by some CDMA operators. |
| 5949 | * |
| 5950 | * @param preferredRoamingList byte array containing the new PRL |
| 5951 | * @return true on success; false on any failure |
| 5952 | */ |
| 5953 | @Override |
| 5954 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5956 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5957 | |
| 5958 | final long identity = Binder.clearCallingIdentity(); |
| 5959 | try { |
| 5960 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5961 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5962 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5963 | return success; |
| 5964 | } finally { |
| 5965 | Binder.restoreCallingIdentity(identity); |
| 5966 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5967 | } |
| 5968 | |
| 5969 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5970 | * 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] | 5971 | * Used for device configuration by some CDMA operators. |
| 5972 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5973 | * @param slotIndex - device slot. |
| 5974 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5975 | * @return true on success; false on any failure |
| 5976 | */ |
| 5977 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5978 | public boolean resetModemConfig(int slotIndex) { |
| 5979 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5980 | if (phone != null) { |
| 5981 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5982 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5983 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5984 | final long identity = Binder.clearCallingIdentity(); |
| 5985 | try { |
| 5986 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5987 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5988 | return success; |
| 5989 | } finally { |
| 5990 | Binder.restoreCallingIdentity(identity); |
| 5991 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5993 | return false; |
| 5994 | } |
| 5995 | |
| 5996 | /** |
| 5997 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5998 | * |
| 5999 | * @param slotIndex - device slot. |
| 6000 | * |
| 6001 | * @return true on success; false on any failure |
| 6002 | */ |
| 6003 | @Override |
| 6004 | public boolean rebootModem(int slotIndex) { |
| 6005 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6006 | if (phone != null) { |
| 6007 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6008 | mApp, phone.getSubId(), "rebootModem"); |
| 6009 | |
| 6010 | final long identity = Binder.clearCallingIdentity(); |
| 6011 | try { |
| 6012 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6013 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6014 | return success; |
| 6015 | } finally { |
| 6016 | Binder.restoreCallingIdentity(identity); |
| 6017 | } |
| 6018 | } |
| 6019 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6020 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6021 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6022 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6023 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6024 | * {@link #disableIms(int)}. |
| 6025 | * @param slotIndex device slot. |
| 6026 | */ |
| 6027 | public void resetIms(int slotIndex) { |
| 6028 | enforceModifyPermission(); |
| 6029 | |
| 6030 | final long identity = Binder.clearCallingIdentity(); |
| 6031 | try { |
| 6032 | if (mImsResolver == null) { |
| 6033 | // may happen if the does not support IMS. |
| 6034 | return; |
| 6035 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6036 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6037 | } finally { |
| 6038 | Binder.restoreCallingIdentity(identity); |
| 6039 | } |
| 6040 | } |
| 6041 | |
| 6042 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6043 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6044 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6045 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6046 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6047 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6048 | |
| 6049 | final long identity = Binder.clearCallingIdentity(); |
| 6050 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6051 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6052 | // may happen if the device does not support IMS. |
| 6053 | return; |
| 6054 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6055 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6056 | } finally { |
| 6057 | Binder.restoreCallingIdentity(identity); |
| 6058 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6059 | } |
| 6060 | |
| 6061 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6062 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6063 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6064 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6065 | public void disableIms(int slotId) { |
| 6066 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | |
| 6068 | final long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6070 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6071 | // may happen if the device does not support IMS. |
| 6072 | return; |
| 6073 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6074 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6075 | } finally { |
| 6076 | Binder.restoreCallingIdentity(identity); |
| 6077 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6078 | } |
| 6079 | |
| 6080 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6081 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6082 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6083 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6084 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6085 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6086 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | |
| 6088 | final long identity = Binder.clearCallingIdentity(); |
| 6089 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6090 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6091 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6092 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6093 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6094 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6095 | } finally { |
| 6096 | Binder.restoreCallingIdentity(identity); |
| 6097 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6098 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6099 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6100 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6101 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6102 | @Override |
| 6103 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6104 | enforceModifyPermission(); |
| 6105 | |
| 6106 | final long identity = Binder.clearCallingIdentity(); |
| 6107 | try { |
| 6108 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6109 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6110 | } finally { |
| 6111 | Binder.restoreCallingIdentity(identity); |
| 6112 | } |
| 6113 | } |
| 6114 | |
| 6115 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6116 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6117 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6118 | */ |
| 6119 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6120 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6121 | |
| 6122 | final long identity = Binder.clearCallingIdentity(); |
| 6123 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6124 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6125 | // may happen if the device does not support IMS. |
| 6126 | return null; |
| 6127 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6128 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | } finally { |
| 6130 | Binder.restoreCallingIdentity(identity); |
| 6131 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6132 | } |
| 6133 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6134 | /** |
| 6135 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6136 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6137 | */ |
| 6138 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6139 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6140 | |
| 6141 | final long identity = Binder.clearCallingIdentity(); |
| 6142 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6143 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6144 | // may happen if the device does not support IMS. |
| 6145 | return null; |
| 6146 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6147 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6148 | } finally { |
| 6149 | Binder.restoreCallingIdentity(identity); |
| 6150 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6151 | } |
| 6152 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6153 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6154 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6155 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6156 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6157 | * @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] | 6158 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6159 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6160 | * @param packageName The name of the package that the current configuration will be replaced |
| 6161 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6162 | * @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] | 6163 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6164 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6165 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6166 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6167 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6168 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6169 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6170 | final long identity = Binder.clearCallingIdentity(); |
| 6171 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6172 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6173 | // may happen if the device does not support IMS. |
| 6174 | return false; |
| 6175 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6176 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6177 | for (int featureType : featureTypes) { |
| 6178 | featureConfig.put(featureType, packageName); |
| 6179 | } |
| 6180 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6181 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6182 | } finally { |
| 6183 | Binder.restoreCallingIdentity(identity); |
| 6184 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6188 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6189 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6190 | * |
| 6191 | * This should only be used for testing. |
| 6192 | * |
| 6193 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6194 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6195 | */ |
| 6196 | @Override |
| 6197 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6198 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6199 | "clearCarrierImsServiceOverride"); |
| 6200 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6201 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6202 | |
| 6203 | final long identity = Binder.clearCallingIdentity(); |
| 6204 | try { |
| 6205 | if (mImsResolver == null) { |
| 6206 | // may happen if the device does not support IMS. |
| 6207 | return false; |
| 6208 | } |
| 6209 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6210 | } finally { |
| 6211 | Binder.restoreCallingIdentity(identity); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6216 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6217 | * |
| 6218 | * @param slotId The slot that the ImsService is associated with. |
| 6219 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6220 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6221 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6222 | * @return the package name of the ImsService configuration. |
| 6223 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6224 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6225 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6226 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6227 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6228 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6229 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6230 | final long identity = Binder.clearCallingIdentity(); |
| 6231 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6232 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6233 | // may happen if the device does not support IMS. |
| 6234 | return ""; |
| 6235 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6236 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6237 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6238 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6239 | } finally { |
| 6240 | Binder.restoreCallingIdentity(identity); |
| 6241 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6244 | /** |
| 6245 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6246 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6247 | * @param callback A callback with an integer containing the |
| 6248 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6249 | */ |
| 6250 | @Override |
| 6251 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6252 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6253 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6254 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6255 | "IMS not available on device."); |
| 6256 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6257 | final long token = Binder.clearCallingIdentity(); |
| 6258 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6259 | int slotId = getSlotIndex(subId); |
| 6260 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6261 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6262 | + subId + "'"); |
| 6263 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6264 | } |
| 6265 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6266 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6267 | try { |
| 6268 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6269 | } catch (RemoteException e) { |
| 6270 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6271 | + "Ignore"); |
| 6272 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6273 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6274 | } catch (ImsException e) { |
| 6275 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6276 | } finally { |
| 6277 | Binder.restoreCallingIdentity(token); |
| 6278 | } |
| 6279 | } |
| 6280 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6281 | /** |
| 6282 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6283 | */ |
| 6284 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6285 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | |
| 6287 | final long identity = Binder.clearCallingIdentity(); |
| 6288 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6289 | // NOTE: Before S, this method only set the default phone. |
| 6290 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6291 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6292 | phone.setImsRegistrationState(registered); |
| 6293 | } |
| 6294 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6295 | } finally { |
| 6296 | Binder.restoreCallingIdentity(identity); |
| 6297 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6301 | * Set the network selection mode to automatic. |
| 6302 | * |
| 6303 | */ |
| 6304 | @Override |
| 6305 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6306 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6307 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6308 | |
| 6309 | final long identity = Binder.clearCallingIdentity(); |
| 6310 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6311 | if (!isActiveSubscription(subId)) { |
| 6312 | return; |
| 6313 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6314 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6315 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6316 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6317 | } finally { |
| 6318 | Binder.restoreCallingIdentity(identity); |
| 6319 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6320 | } |
| 6321 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6322 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6323 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6324 | * |
| 6325 | * @param subId the id of the subscription. |
| 6326 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6327 | * the operator to attach to. |
| 6328 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6329 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6330 | * normal network selection next time. |
| 6331 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6332 | */ |
| 6333 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6334 | public boolean setNetworkSelectionModeManual( |
| 6335 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6336 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6337 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6338 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6339 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6340 | if (!isActiveSubscription(subId)) { |
| 6341 | return false; |
| 6342 | } |
| 6343 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6344 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6345 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6346 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6347 | if (DBG) { |
| 6348 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6349 | + " operator: " + operatorInfo); |
| 6350 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6351 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6352 | } finally { |
| 6353 | Binder.restoreCallingIdentity(identity); |
| 6354 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6355 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6356 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6357 | * Get the manual network selection |
| 6358 | * |
| 6359 | * @param subId the id of the subscription. |
| 6360 | * |
| 6361 | * @return the previously saved user selected PLMN |
| 6362 | */ |
| 6363 | @Override |
| 6364 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6365 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6366 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6367 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6368 | |
| 6369 | final long identity = Binder.clearCallingIdentity(); |
| 6370 | try { |
| 6371 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6372 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | final Phone phone = getPhone(subId); |
| 6376 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6377 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6378 | } |
| 6379 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6380 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6381 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6382 | } finally { |
| 6383 | Binder.restoreCallingIdentity(identity); |
| 6384 | } |
| 6385 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6386 | |
| 6387 | /** |
| 6388 | * Scans for available networks. |
| 6389 | */ |
| 6390 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6391 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6392 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6393 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6394 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6395 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6396 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6397 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6398 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6399 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6400 | .setCallingPid(Binder.getCallingPid()) |
| 6401 | .setCallingUid(Binder.getCallingUid()) |
| 6402 | .setMethod("getCellNetworkScanResults") |
| 6403 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6404 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6405 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6406 | .build()); |
| 6407 | switch (locationResult) { |
| 6408 | case DENIED_HARD: |
| 6409 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6410 | case DENIED_SOFT: |
| 6411 | return null; |
| 6412 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6413 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6414 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | try { |
| 6416 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6417 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6418 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6419 | } finally { |
| 6420 | Binder.restoreCallingIdentity(identity); |
| 6421 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6425 | * Get the call forwarding info, given the call forwarding reason. |
| 6426 | */ |
| 6427 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6428 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6429 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6430 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6431 | long identity = Binder.clearCallingIdentity(); |
| 6432 | try { |
| 6433 | if (DBG) { |
| 6434 | log("getCallForwarding: subId " + subId |
| 6435 | + " callForwardingReason" + callForwardingReason); |
| 6436 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6437 | |
| 6438 | Phone phone = getPhone(subId); |
| 6439 | if (phone == null) { |
| 6440 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6441 | callback.onError( |
| 6442 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6443 | } catch (RemoteException e) { |
| 6444 | // ignore |
| 6445 | } |
| 6446 | return; |
| 6447 | } |
| 6448 | |
| 6449 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6450 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6451 | @Override |
| 6452 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6453 | try { |
| 6454 | callback.onCallForwardingInfoAvailable(info); |
| 6455 | } catch (RemoteException e) { |
| 6456 | // ignore |
| 6457 | } |
| 6458 | } |
| 6459 | |
| 6460 | @Override |
| 6461 | public void onError(int error) { |
| 6462 | try { |
| 6463 | callback.onError(error); |
| 6464 | } catch (RemoteException e) { |
| 6465 | // ignore |
| 6466 | } |
| 6467 | } |
| 6468 | }); |
| 6469 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6470 | } finally { |
| 6471 | Binder.restoreCallingIdentity(identity); |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | /** |
| 6476 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6477 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6478 | */ |
| 6479 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6480 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6481 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6482 | enforceModifyPermission(); |
| 6483 | long identity = Binder.clearCallingIdentity(); |
| 6484 | try { |
| 6485 | if (DBG) { |
| 6486 | log("setCallForwarding: subId " + subId |
| 6487 | + " callForwardingInfo" + callForwardingInfo); |
| 6488 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6489 | |
| 6490 | Phone phone = getPhone(subId); |
| 6491 | if (phone == null) { |
| 6492 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6493 | callback.accept( |
| 6494 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6495 | } catch (RemoteException e) { |
| 6496 | // ignore |
| 6497 | } |
| 6498 | return; |
| 6499 | } |
| 6500 | |
| 6501 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6502 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6503 | |
| 6504 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6505 | } finally { |
| 6506 | Binder.restoreCallingIdentity(identity); |
| 6507 | } |
| 6508 | } |
| 6509 | |
| 6510 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6511 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6512 | */ |
| 6513 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6514 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6515 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6516 | long identity = Binder.clearCallingIdentity(); |
| 6517 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6518 | Phone phone = getPhone(subId); |
| 6519 | if (phone == null) { |
| 6520 | try { |
| 6521 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6522 | } catch (RemoteException e) { |
| 6523 | // ignore |
| 6524 | } |
| 6525 | return; |
| 6526 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6527 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6528 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6529 | boolean requireUssd = c.getBoolean( |
| 6530 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6531 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6532 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6533 | if (requireUssd) { |
| 6534 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6535 | getSubscriptionCarrierId(subId)); |
| 6536 | String newUssdCommand = ""; |
| 6537 | try { |
| 6538 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6539 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6540 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6541 | } catch (NullPointerException e) { |
| 6542 | loge("Failed to generate USSD number" + e); |
| 6543 | } |
| 6544 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6545 | mMainThreadHandler, callback, carrierXmlParser, |
| 6546 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6547 | final String ussdCommand = newUssdCommand; |
| 6548 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6549 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6550 | }); |
| 6551 | } else { |
| 6552 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6553 | callback::accept); |
| 6554 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6555 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6556 | } finally { |
| 6557 | Binder.restoreCallingIdentity(identity); |
| 6558 | } |
| 6559 | } |
| 6560 | |
| 6561 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6562 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6563 | */ |
| 6564 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6565 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6566 | enforceModifyPermission(); |
| 6567 | long identity = Binder.clearCallingIdentity(); |
| 6568 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6569 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6570 | |
| 6571 | Phone phone = getPhone(subId); |
| 6572 | if (phone == null) { |
| 6573 | try { |
| 6574 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6575 | } catch (RemoteException e) { |
| 6576 | // ignore |
| 6577 | } |
| 6578 | return; |
| 6579 | } |
| 6580 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6581 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6582 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6583 | boolean requireUssd = c.getBoolean( |
| 6584 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6585 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6586 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6587 | if (requireUssd) { |
| 6588 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6589 | getSubscriptionCarrierId(subId)); |
| 6590 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6591 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6592 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6593 | String newUssdCommand = ""; |
| 6594 | try { |
| 6595 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6596 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6597 | .makeCommand(ssAction, null); |
| 6598 | } catch (NullPointerException e) { |
| 6599 | loge("Failed to generate USSD number" + e); |
| 6600 | } |
| 6601 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6602 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6603 | final String ussdCommand = newUssdCommand; |
| 6604 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6605 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6606 | }); |
| 6607 | } else { |
| 6608 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6609 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6610 | |
| 6611 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6612 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6613 | } finally { |
| 6614 | Binder.restoreCallingIdentity(identity); |
| 6615 | } |
| 6616 | } |
| 6617 | |
| 6618 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6619 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6620 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6621 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6622 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6623 | * location related information which will be sent if the caller already possess |
| 6624 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6625 | * @param request contains the radio access networks with bands/channels to scan |
| 6626 | * @param messenger callback messenger for scan results or errors |
| 6627 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6628 | * @return the id of the requested scan which can be used to stop the scan. |
| 6629 | */ |
| 6630 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6631 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6632 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6633 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6635 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6636 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6637 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6638 | if (!renounceFineLocationAccess) { |
| 6639 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6640 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6641 | .setCallingPackage(callingPackage) |
| 6642 | .setCallingFeatureId(callingFeatureId) |
| 6643 | .setCallingPid(Binder.getCallingPid()) |
| 6644 | .setCallingUid(Binder.getCallingUid()) |
| 6645 | .setMethod("requestNetworkScan") |
| 6646 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6647 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6648 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6649 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6650 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6651 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6652 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6653 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6654 | if (e != null) { |
| 6655 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6656 | throw e; |
| 6657 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6658 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6659 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6660 | } |
| 6661 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6662 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6663 | int callingUid = Binder.getCallingUid(); |
| 6664 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6665 | final long identity = Binder.clearCallingIdentity(); |
| 6666 | try { |
| 6667 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6668 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6669 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6670 | } finally { |
| 6671 | Binder.restoreCallingIdentity(identity); |
| 6672 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6673 | } |
| 6674 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6675 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6676 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6677 | boolean hasCarrierPriv; |
| 6678 | final long identity = Binder.clearCallingIdentity(); |
| 6679 | try { |
| 6680 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6681 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6682 | } finally { |
| 6683 | Binder.restoreCallingIdentity(identity); |
| 6684 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6685 | boolean hasNetworkScanPermission = |
| 6686 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6687 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6688 | |
| 6689 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6690 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6691 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6692 | } |
| 6693 | |
| 6694 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6695 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6696 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6697 | return new SecurityException("Specific channels must not be" |
| 6698 | + " scanned without location access."); |
| 6699 | } |
| 6700 | } |
| 6701 | } |
| 6702 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6703 | return null; |
| 6704 | } |
| 6705 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6706 | /** |
| 6707 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6708 | * |
| 6709 | * @param subId id of the subscription |
| 6710 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6711 | */ |
| 6712 | @Override |
| 6713 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6715 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6716 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6717 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | final long identity = Binder.clearCallingIdentity(); |
| 6719 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6720 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6721 | } finally { |
| 6722 | Binder.restoreCallingIdentity(identity); |
| 6723 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6724 | } |
| 6725 | |
| 6726 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6727 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6728 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6729 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6730 | */ |
| 6731 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6732 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6733 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6734 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6735 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6736 | |
| 6737 | final long identity = Binder.clearCallingIdentity(); |
| 6738 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6739 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6740 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6741 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6742 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6743 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6744 | } finally { |
| 6745 | Binder.restoreCallingIdentity(identity); |
| 6746 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6750 | * Get the allowed network types for certain reason. |
| 6751 | * |
| 6752 | * @param subId the id of the subscription. |
| 6753 | * @param reason the reason the allowed network type change is taking place |
| 6754 | * @return the allowed network types. |
| 6755 | */ |
| 6756 | @Override |
| 6757 | public long getAllowedNetworkTypesForReason(int subId, |
| 6758 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6759 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6760 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6761 | final long identity = Binder.clearCallingIdentity(); |
| 6762 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6763 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6764 | } finally { |
| 6765 | Binder.restoreCallingIdentity(identity); |
| 6766 | } |
| 6767 | } |
| 6768 | |
| 6769 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6770 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6771 | * @param subId subscription id of the sim card |
| 6772 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6773 | * This can be passed following states |
| 6774 | * <ol> |
| 6775 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6776 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6777 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6778 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6779 | * </ol> |
| 6780 | * @return operation result. |
| 6781 | */ |
| 6782 | @Override |
| 6783 | public int setNrDualConnectivityState(int subId, |
| 6784 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6786 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6787 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6788 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6789 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6790 | } |
| 6791 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6792 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6793 | final long identity = Binder.clearCallingIdentity(); |
| 6794 | try { |
| 6795 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6796 | nrDualConnectivityState, subId, |
| 6797 | workSource); |
| 6798 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6799 | return result; |
| 6800 | } finally { |
| 6801 | Binder.restoreCallingIdentity(identity); |
| 6802 | } |
| 6803 | } |
| 6804 | |
| 6805 | /** |
| 6806 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6807 | * @return true if dual connectivity is enabled else false |
| 6808 | */ |
| 6809 | @Override |
| 6810 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6811 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6812 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6813 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6814 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6815 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6816 | return false; |
| 6817 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6818 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6819 | final long identity = Binder.clearCallingIdentity(); |
| 6820 | try { |
| 6821 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6822 | null, subId, workSource); |
| 6823 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6824 | return isEnabled; |
| 6825 | } finally { |
| 6826 | Binder.restoreCallingIdentity(identity); |
| 6827 | } |
| 6828 | } |
| 6829 | |
| 6830 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6831 | * Set the allowed network types of the device and |
| 6832 | * provide the reason triggering the allowed network change. |
| 6833 | * |
| 6834 | * @param subId the id of the subscription. |
| 6835 | * @param reason the reason the allowed network type change is taking place |
| 6836 | * @param allowedNetworkTypes the allowed network types. |
| 6837 | * @return true on success; false on any failure. |
| 6838 | */ |
| 6839 | @Override |
| 6840 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6841 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6842 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6844 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6845 | // If the caller only has carrier privileges, then they should not be able to override |
| 6846 | // any network types which were set for security reasons. |
| 6847 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6848 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6849 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6850 | throw new SecurityException( |
| 6851 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6852 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6853 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6854 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6855 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6856 | return false; |
| 6857 | } |
| 6858 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6859 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6860 | return false; |
| 6861 | } |
| 6862 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6863 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6864 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6865 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6866 | Phone phone = getPhone(subId); |
| 6867 | if (phone == null) { |
| 6868 | return false; |
| 6869 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6870 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6871 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6872 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6873 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6874 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6875 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6876 | final long identity = Binder.clearCallingIdentity(); |
| 6877 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6878 | Boolean success = (Boolean) sendRequest( |
| 6879 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6880 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6881 | |
| 6882 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6883 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6884 | } finally { |
| 6885 | Binder.restoreCallingIdentity(identity); |
| 6886 | } |
| 6887 | } |
| 6888 | |
| 6889 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6890 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6891 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6892 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6893 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6894 | * @hide |
| 6895 | */ |
| 6896 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6897 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6898 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6899 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6900 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6901 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6902 | if (phone != null) { |
| 6903 | return phone.hasMatchedTetherApnSetting(); |
| 6904 | } else { |
| 6905 | return false; |
| 6906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6907 | } finally { |
| 6908 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6909 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6910 | } |
| 6911 | |
| 6912 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6913 | * Get the user enabled state of Mobile Data. |
| 6914 | * |
| 6915 | * TODO: remove and use isUserDataEnabled. |
| 6916 | * This can't be removed now because some vendor codes |
| 6917 | * calls through ITelephony directly while they should |
| 6918 | * use TelephonyManager. |
| 6919 | * |
| 6920 | * @return true on enabled |
| 6921 | */ |
| 6922 | @Override |
| 6923 | public boolean getDataEnabled(int subId) { |
| 6924 | return isUserDataEnabled(subId); |
| 6925 | } |
| 6926 | |
| 6927 | /** |
| 6928 | * Get whether mobile data is enabled per user setting. |
| 6929 | * |
| 6930 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6931 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6932 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6933 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6934 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6935 | * |
| 6936 | * @return {@code true} if data is enabled else {@code false} |
| 6937 | */ |
| 6938 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6939 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6940 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6941 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6942 | try { |
| 6943 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6944 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6945 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6946 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6947 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6948 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6950 | mApp, subId, functionName); |
| 6951 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6952 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6953 | |
| 6954 | final long identity = Binder.clearCallingIdentity(); |
| 6955 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6956 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6957 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6958 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6959 | if (phone != null) { |
| 6960 | boolean retVal = phone.isUserDataEnabled(); |
| 6961 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6962 | return retVal; |
| 6963 | } else { |
| 6964 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6965 | return false; |
| 6966 | } |
| 6967 | } finally { |
| 6968 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6969 | } |
| 6970 | } |
| 6971 | |
| 6972 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6973 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6974 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6975 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6976 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6977 | * @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] | 6978 | */ |
| 6979 | @Override |
| 6980 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6981 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6982 | try { |
| 6983 | try { |
| 6984 | mApp.enforceCallingOrSelfPermission( |
| 6985 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6986 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6987 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6988 | try { |
| 6989 | mApp.enforceCallingOrSelfPermission( |
| 6990 | android.Manifest.permission.READ_PHONE_STATE, |
| 6991 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6992 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6993 | mApp.enforceCallingOrSelfPermission( |
| 6994 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6995 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6996 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6997 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6998 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6999 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7000 | |
| 7001 | final long identity = Binder.clearCallingIdentity(); |
| 7002 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7003 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7004 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7005 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7006 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7007 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7008 | return retVal; |
| 7009 | } else { |
| 7010 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7011 | return false; |
| 7012 | } |
| 7013 | } finally { |
| 7014 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7015 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7016 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7017 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7018 | /** |
| 7019 | * Check if data is enabled for a specific reason |
| 7020 | * @param subId Subscription index |
| 7021 | * @param reason the reason the data enable change is taking place |
| 7022 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7023 | */ |
| 7024 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7025 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7026 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7027 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7028 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7029 | try { |
| 7030 | mApp.enforceCallingOrSelfPermission( |
| 7031 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7032 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7033 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7034 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7035 | functionName); |
| 7036 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7037 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7038 | try { |
| 7039 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7040 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7041 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7043 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7044 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | |
| 7048 | final long identity = Binder.clearCallingIdentity(); |
| 7049 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7050 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7051 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7052 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7053 | + " reason=" + reason); |
| 7054 | } |
| 7055 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7056 | if (phone != null) { |
| 7057 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7058 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7059 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7060 | return retVal; |
| 7061 | } else { |
| 7062 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7063 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7064 | + subId + " retVal=false"); |
| 7065 | } |
| 7066 | return false; |
| 7067 | } |
| 7068 | } finally { |
| 7069 | Binder.restoreCallingIdentity(identity); |
| 7070 | } |
| 7071 | } |
| 7072 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7073 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7074 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7075 | // No permission needed; this only lets the caller inspect their own status. |
| 7076 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7077 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7078 | |
| 7079 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7080 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7081 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7082 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7083 | } |
| 7084 | |
| 7085 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7086 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7087 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7088 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7089 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7090 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7091 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7092 | if (cpt == null) { |
| 7093 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7094 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7095 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7096 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7097 | } |
| 7098 | |
| 7099 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7100 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7101 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7102 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7103 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7104 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7105 | Phone phone = getPhone(subId); |
| 7106 | if (phone == null) { |
| 7107 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7108 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7109 | } |
| 7110 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7111 | if (cpt == null) { |
| 7112 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7113 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7114 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7115 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7116 | } |
| 7117 | |
| 7118 | @Override |
| 7119 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7120 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7121 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7122 | } |
| 7123 | |
| 7124 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7125 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7126 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7127 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7128 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7129 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7130 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7131 | if (phone == null) { |
| 7132 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7133 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7134 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7135 | if (cpt == null) { |
| 7136 | continue; |
| 7137 | } |
| 7138 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7139 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7140 | break; |
| 7141 | } |
| 7142 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7143 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7144 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7145 | |
| 7146 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7147 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7148 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7149 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7150 | if (phone == null) { |
| 7151 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7152 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7153 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7154 | if (cpt == null) { |
| 7155 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7156 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7157 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7158 | } |
| 7159 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7160 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7161 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7162 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7163 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7164 | if (phone == null) { |
| 7165 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7166 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7167 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7168 | if (cpt == null) { |
| 7169 | return Collections.emptyList(); |
| 7170 | } |
| 7171 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7172 | } |
| 7173 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7174 | @Override |
| 7175 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7176 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7177 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7178 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7179 | try { |
| 7180 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7181 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7182 | } |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7185 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7186 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7187 | } |
| 7188 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7189 | @Override |
| 7190 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7191 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7192 | |
| 7193 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7194 | if (phone == null) { |
| 7195 | return null; |
| 7196 | } |
| 7197 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7198 | if (cpt == null) { |
| 7199 | return null; |
| 7200 | } |
| 7201 | return cpt.getCarrierServicePackageName(); |
| 7202 | } |
| 7203 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7204 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7205 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7206 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7207 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7208 | return null; |
| 7209 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7210 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7211 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7212 | return null; |
| 7213 | } |
| 7214 | return iccId; |
| 7215 | } |
| 7216 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7217 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7218 | public void setCallComposerStatus(int subId, int status) { |
| 7219 | enforceModifyPermission(); |
| 7220 | |
| 7221 | final long identity = Binder.clearCallingIdentity(); |
| 7222 | try { |
| 7223 | Phone phone = getPhone(subId); |
| 7224 | if (phone != null) { |
| 7225 | Phone defaultPhone = phone.getImsPhone(); |
| 7226 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7227 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7228 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7229 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7230 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7231 | } |
| 7232 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7233 | } catch (ImsException e) { |
| 7234 | throw new ServiceSpecificException(e.getCode()); |
| 7235 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7236 | Binder.restoreCallingIdentity(identity); |
| 7237 | } |
| 7238 | } |
| 7239 | |
| 7240 | @Override |
| 7241 | public int getCallComposerStatus(int subId) { |
| 7242 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7243 | |
| 7244 | final long identity = Binder.clearCallingIdentity(); |
| 7245 | try { |
| 7246 | Phone phone = getPhone(subId); |
| 7247 | if (phone != null) { |
| 7248 | Phone defaultPhone = phone.getImsPhone(); |
| 7249 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7250 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7251 | return imsPhone.getCallComposerStatus(); |
| 7252 | } |
| 7253 | } |
| 7254 | } finally { |
| 7255 | Binder.restoreCallingIdentity(identity); |
| 7256 | } |
| 7257 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7258 | } |
| 7259 | |
| 7260 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7261 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7262 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7263 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7264 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7265 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7266 | final long identity = Binder.clearCallingIdentity(); |
| 7267 | try { |
| 7268 | final String iccId = getIccId(subId); |
| 7269 | final Phone phone = getPhone(subId); |
| 7270 | if (phone == null) { |
| 7271 | return false; |
| 7272 | } |
| 7273 | final String subscriberId = phone.getSubscriberId(); |
| 7274 | |
| 7275 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7276 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7277 | + subscriberId + " to " + number); |
| 7278 | } |
| 7279 | |
| 7280 | if (TextUtils.isEmpty(iccId)) { |
| 7281 | return false; |
| 7282 | } |
| 7283 | |
| 7284 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7285 | |
| 7286 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7287 | if (alphaTag == null) { |
| 7288 | editor.remove(alphaTagPrefKey); |
| 7289 | } else { |
| 7290 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7291 | } |
| 7292 | |
| 7293 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7294 | // track all merged IMSIs based on line number |
| 7295 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7296 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7297 | if (number == null) { |
| 7298 | editor.remove(numberPrefKey); |
| 7299 | editor.remove(subscriberPrefKey); |
| 7300 | } else { |
| 7301 | editor.putString(numberPrefKey, number); |
| 7302 | editor.putString(subscriberPrefKey, subscriberId); |
| 7303 | } |
| 7304 | |
| 7305 | editor.commit(); |
| 7306 | return true; |
| 7307 | } finally { |
| 7308 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7309 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7310 | } |
| 7311 | |
| 7312 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7313 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7314 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7315 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7316 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7317 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7318 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7319 | return null; |
| 7320 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7321 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7322 | final long identity = Binder.clearCallingIdentity(); |
| 7323 | try { |
| 7324 | String iccId = getIccId(subId); |
| 7325 | if (iccId != null) { |
| 7326 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7327 | if (DBG_MERGE) { |
| 7328 | log("getLine1NumberForDisplay returning " |
| 7329 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7330 | } |
| 7331 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7334 | return null; |
| 7335 | } finally { |
| 7336 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7337 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7338 | } |
| 7339 | |
| 7340 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7341 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7342 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7343 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7344 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7345 | return null; |
| 7346 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7347 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7348 | final long identity = Binder.clearCallingIdentity(); |
| 7349 | try { |
| 7350 | String iccId = getIccId(subId); |
| 7351 | if (iccId != null) { |
| 7352 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7353 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7354 | } |
| 7355 | return null; |
| 7356 | } finally { |
| 7357 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7358 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7359 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7360 | |
| 7361 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7362 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7363 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7364 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7365 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7366 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7367 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7368 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7369 | return null; |
| 7370 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7371 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7372 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7373 | // the process, where TelephonyManager was instantiated. |
| 7374 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7375 | final long identity = Binder.clearCallingIdentity(); |
| 7376 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7377 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7378 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7379 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7380 | |
| 7381 | // Figure out what subscribers are currently active |
| 7382 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7383 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7384 | // Only consider subs which match the current subId |
| 7385 | // This logic can be simplified. See b/131189269 for progress. |
| 7386 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7387 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7388 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | |
| 7390 | // First pass, find a number override for an active subscriber |
| 7391 | String mergeNumber = null; |
| 7392 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7393 | for (String key : prefs.keySet()) { |
| 7394 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7395 | final String subscriberId = (String) prefs.get(key); |
| 7396 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7397 | final String iccId = key.substring( |
| 7398 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7399 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7400 | mergeNumber = (String) prefs.get(numberKey); |
| 7401 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7402 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7403 | + " for active subscriber " + subscriberId); |
| 7404 | } |
| 7405 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7406 | break; |
| 7407 | } |
| 7408 | } |
| 7409 | } |
| 7410 | } |
| 7411 | |
| 7412 | // Shortcut when no active merged subscribers |
| 7413 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7414 | return null; |
| 7415 | } |
| 7416 | |
| 7417 | // Second pass, find all subscribers under that line override |
| 7418 | final ArraySet<String> result = new ArraySet<>(); |
| 7419 | for (String key : prefs.keySet()) { |
| 7420 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7421 | final String number = (String) prefs.get(key); |
| 7422 | if (mergeNumber.equals(number)) { |
| 7423 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7424 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7425 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7426 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7427 | result.add(subscriberId); |
| 7428 | } |
| 7429 | } |
| 7430 | } |
| 7431 | } |
| 7432 | |
| 7433 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7434 | Arrays.sort(resultArray); |
| 7435 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7436 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7437 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7438 | } |
| 7439 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7440 | } finally { |
| 7441 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7442 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7446 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7447 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7448 | |
| 7449 | final long identity = Binder.clearCallingIdentity(); |
| 7450 | try { |
| 7451 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7452 | TelephonyManager.class); |
| 7453 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7454 | if (subscriberId == null) { |
| 7455 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7456 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7457 | + subId); |
| 7458 | } |
| 7459 | return null; |
| 7460 | } |
| 7461 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7462 | ParcelUuid groupUuid; |
| 7463 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7464 | final SubscriptionInfo info = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7465 | .getSubscriptionInfo(subId); |
| 7466 | groupUuid = info.getGroupUuid(); |
| 7467 | } else { |
| 7468 | final SubscriptionInfo info = mSubscriptionController |
| 7469 | .getSubscriptionInfo(subId); |
| 7470 | groupUuid = info.getGroupUuid(); |
| 7471 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7472 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7473 | if (groupUuid == null) { |
| 7474 | return new String[]{subscriberId}; |
| 7475 | } |
| 7476 | |
| 7477 | // Get all subscriberIds from the group. |
| 7478 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7479 | List<SubscriptionInfo> groupInfos; |
| 7480 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7481 | groupInfos = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7482 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7483 | mApp.getAttributionTag()); |
| 7484 | } else { |
| 7485 | groupInfos = mSubscriptionController |
| 7486 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7487 | mApp.getAttributionTag()); |
| 7488 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7489 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7490 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7491 | if (subscriberId != null) { |
| 7492 | mergedSubscriberIds.add(subscriberId); |
| 7493 | } |
| 7494 | } |
| 7495 | |
| 7496 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7497 | } finally { |
| 7498 | Binder.restoreCallingIdentity(identity); |
| 7499 | |
| 7500 | } |
| 7501 | } |
| 7502 | |
| 7503 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7504 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7505 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7506 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7507 | |
| 7508 | final long identity = Binder.clearCallingIdentity(); |
| 7509 | try { |
| 7510 | final Phone phone = getPhone(subId); |
| 7511 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7512 | } finally { |
| 7513 | Binder.restoreCallingIdentity(identity); |
| 7514 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7515 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7516 | |
| 7517 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7518 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7519 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7520 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7521 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7522 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7523 | |
| 7524 | final long identity = Binder.clearCallingIdentity(); |
| 7525 | try { |
| 7526 | final Phone phone = getPhone(subId); |
| 7527 | if (phone == null) { |
| 7528 | return false; |
| 7529 | } |
| 7530 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7531 | cdmaNonRoamingList); |
| 7532 | } finally { |
| 7533 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7534 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7535 | } |
| 7536 | |
| 7537 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7538 | @Deprecated |
| 7539 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7540 | enforceModifyPermission(); |
| 7541 | |
| 7542 | int returnValue = 0; |
| 7543 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7544 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7545 | if(result.exception == null) { |
| 7546 | if (result.result != null) { |
| 7547 | byte[] responseData = (byte[])(result.result); |
| 7548 | if(responseData.length > oemResp.length) { |
| 7549 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7550 | responseData.length + "bytes. Buffer Size is " + |
| 7551 | oemResp.length + "bytes."); |
| 7552 | } |
| 7553 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7554 | returnValue = responseData.length; |
| 7555 | } |
| 7556 | } else { |
| 7557 | CommandException ex = (CommandException) result.exception; |
| 7558 | returnValue = ex.getCommandError().ordinal(); |
| 7559 | if(returnValue > 0) returnValue *= -1; |
| 7560 | } |
| 7561 | } catch (RuntimeException e) { |
| 7562 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7563 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7564 | if(returnValue > 0) returnValue *= -1; |
| 7565 | } |
| 7566 | |
| 7567 | return returnValue; |
| 7568 | } |
| 7569 | |
| 7570 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7571 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7572 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7573 | try { |
| 7574 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7575 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7576 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7577 | } catch (SecurityException e) { |
| 7578 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7579 | throw e; |
| 7580 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7581 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7582 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7583 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7584 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7585 | final long identity = Binder.clearCallingIdentity(); |
| 7586 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7587 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7588 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7589 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7590 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7591 | } finally { |
| 7592 | Binder.restoreCallingIdentity(identity); |
| 7593 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7594 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7595 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7596 | |
| 7597 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7598 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7599 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7600 | try { |
| 7601 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7602 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7603 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7604 | } |
| 7605 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7606 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7607 | } |
| 7608 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7609 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7610 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7611 | throw new SecurityException("App must be the dialer role holder to" |
| 7612 | + " upload a call composer pic"); |
| 7613 | } |
| 7614 | |
| 7615 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7616 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7617 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7618 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7619 | boolean readUntilEnd = false; |
| 7620 | int totalBytesRead = 0; |
| 7621 | byte[] buffer = new byte[16 * 1024]; |
| 7622 | while (true) { |
| 7623 | int numRead; |
| 7624 | try { |
| 7625 | numRead = input.read(buffer); |
| 7626 | } catch (IOException e) { |
| 7627 | try { |
| 7628 | fd.checkError(); |
| 7629 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7630 | null); |
| 7631 | } catch (IOException e1) { |
| 7632 | // This means that the other side closed explicitly with an error. If this |
| 7633 | // happens, log and ignore. |
| 7634 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7635 | } |
| 7636 | break; |
| 7637 | } |
| 7638 | if (numRead == -1) { |
| 7639 | readUntilEnd = true; |
| 7640 | break; |
| 7641 | } |
| 7642 | totalBytesRead += numRead; |
| 7643 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7644 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7645 | try { |
| 7646 | input.close(); |
| 7647 | } catch (IOException e) { |
| 7648 | // ignore |
| 7649 | } |
| 7650 | break; |
| 7651 | } |
| 7652 | output.write(buffer, 0, numRead); |
| 7653 | } |
| 7654 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7655 | // close is above, where the picture size is too big. |
| 7656 | |
| 7657 | try { |
| 7658 | fd.checkError(); |
| 7659 | } catch (IOException e) { |
| 7660 | loge("Remote end for call composer closed with an error: " + e); |
| 7661 | return; |
| 7662 | } |
| 7663 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7664 | if (!readUntilEnd) { |
| 7665 | loge("Did not finish reading entire image; aborting"); |
| 7666 | return; |
| 7667 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7668 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7669 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7670 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7671 | new CallComposerPictureTransfer.Factory() {}, |
| 7672 | imageData, |
| 7673 | (result) -> { |
| 7674 | if (result.first != null) { |
| 7675 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7676 | Bundle outputResult = new Bundle(); |
| 7677 | outputResult.putParcelable( |
| 7678 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7679 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7680 | outputResult); |
| 7681 | } else { |
| 7682 | callback.send(result.second, null); |
| 7683 | } |
| 7684 | } |
| 7685 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7686 | }); |
| 7687 | } |
| 7688 | |
| 7689 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7690 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7691 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7692 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7693 | |
| 7694 | final long identity = Binder.clearCallingIdentity(); |
| 7695 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7696 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7697 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7698 | } finally { |
| 7699 | Binder.restoreCallingIdentity(identity); |
| 7700 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7701 | } |
| 7702 | |
| 7703 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7704 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7705 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7706 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7707 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7708 | return false; |
| 7709 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7710 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7711 | final long identity = Binder.clearCallingIdentity(); |
| 7712 | try { |
| 7713 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7714 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7715 | // In the long run, we may instead need to check if there exists a connection service |
| 7716 | // which can support video calling. |
| 7717 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7718 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7719 | return imsManager.isVtEnabledByPlatform() |
| 7720 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7721 | && imsManager.isVtEnabledByUser(); |
| 7722 | } finally { |
| 7723 | Binder.restoreCallingIdentity(identity); |
| 7724 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7725 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7726 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7727 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7728 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7729 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7730 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7731 | mApp, subId, callingPackage, callingFeatureId, |
| 7732 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7733 | return false; |
| 7734 | } |
| 7735 | |
| 7736 | final long identity = Binder.clearCallingIdentity(); |
| 7737 | try { |
| 7738 | CarrierConfigManager configManager = |
| 7739 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7740 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7741 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7742 | } finally { |
| 7743 | Binder.restoreCallingIdentity(identity); |
| 7744 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7745 | } |
| 7746 | |
| 7747 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7748 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7750 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7751 | return false; |
| 7752 | } |
| 7753 | |
| 7754 | final long identity = Binder.clearCallingIdentity(); |
| 7755 | try { |
| 7756 | CarrierConfigManager configManager = |
| 7757 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7758 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7759 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7760 | } finally { |
| 7761 | Binder.restoreCallingIdentity(identity); |
| 7762 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7763 | } |
| 7764 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7765 | @Override |
| 7766 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7767 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7768 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7769 | } |
| 7770 | |
| 7771 | @Override |
| 7772 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7773 | final long identity = Binder.clearCallingIdentity(); |
| 7774 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7775 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7776 | } finally { |
| 7777 | Binder.restoreCallingIdentity(identity); |
| 7778 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7779 | } |
| 7780 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7781 | /** |
| 7782 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7783 | * support for the feature and device firmware support. |
| 7784 | * |
| 7785 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7786 | */ |
| 7787 | @Override |
| 7788 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7789 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7790 | final Phone phone = getPhone(subscriptionId); |
| 7791 | if (phone == null) { |
| 7792 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7793 | return false; |
| 7794 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7795 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7796 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7798 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7799 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7800 | return isCarrierSupported && isDeviceSupported; |
| 7801 | } finally { |
| 7802 | Binder.restoreCallingIdentity(identity); |
| 7803 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7804 | } |
| 7805 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7806 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7807 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7808 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7809 | * 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] | 7810 | */ |
| 7811 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7812 | final long identity = Binder.clearCallingIdentity(); |
| 7813 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7814 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7815 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7816 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7817 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7818 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7819 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | } finally { |
| 7821 | Binder.restoreCallingIdentity(identity); |
| 7822 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7823 | } |
| 7824 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7825 | @Deprecated |
| 7826 | @Override |
| 7827 | public String getDeviceId(String callingPackage) { |
| 7828 | return getDeviceIdWithFeature(callingPackage, null); |
| 7829 | } |
| 7830 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7831 | /** |
| 7832 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7833 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7834 | * |
| 7835 | * <p>Requires Permission: |
| 7836 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7837 | */ |
| 7838 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7839 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7840 | try { |
| 7841 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7842 | } catch (SecurityException se) { |
| 7843 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7844 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7845 | + Binder.getCallingUid()); |
| 7846 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7847 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7848 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7849 | return null; |
| 7850 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7851 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7852 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7853 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7854 | return null; |
| 7855 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7856 | |
| 7857 | final long identity = Binder.clearCallingIdentity(); |
| 7858 | try { |
| 7859 | return phone.getDeviceId(); |
| 7860 | } finally { |
| 7861 | Binder.restoreCallingIdentity(identity); |
| 7862 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7863 | } |
| 7864 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7865 | /** |
| 7866 | * {@hide} |
| 7867 | * Returns the IMS Registration Status on a particular subid |
| 7868 | * |
| 7869 | * @param subId |
| 7870 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7871 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7872 | Phone phone = getPhone(subId); |
| 7873 | if (phone != null) { |
| 7874 | return phone.isImsRegistered(); |
| 7875 | } else { |
| 7876 | return false; |
| 7877 | } |
| 7878 | } |
| 7879 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7880 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7881 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7882 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7883 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7884 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7885 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7886 | } |
| 7887 | final long identity = Binder.clearCallingIdentity(); |
| 7888 | try { |
| 7889 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7890 | } finally { |
| 7891 | Binder.restoreCallingIdentity(identity); |
| 7892 | } |
| 7893 | } |
| 7894 | |
| 7895 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7896 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7897 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7898 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7899 | mApp, |
| 7900 | subscriptionId, |
| 7901 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7902 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7903 | final long identity = Binder.clearCallingIdentity(); |
| 7904 | try { |
| 7905 | Phone phone = getPhone(subscriptionId); |
| 7906 | if (phone == null) { |
| 7907 | return null; |
| 7908 | } |
| 7909 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7910 | } finally { |
| 7911 | Binder.restoreCallingIdentity(identity); |
| 7912 | } |
| 7913 | } |
| 7914 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7915 | /** |
| 7916 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7917 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7918 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7919 | final long identity = Binder.clearCallingIdentity(); |
| 7920 | try { |
| 7921 | Phone phone = getPhone(subId); |
| 7922 | if (phone != null) { |
| 7923 | return phone.isWifiCallingEnabled(); |
| 7924 | } else { |
| 7925 | return false; |
| 7926 | } |
| 7927 | } finally { |
| 7928 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7929 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7930 | } |
| 7931 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7932 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7933 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7934 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7935 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | final long identity = Binder.clearCallingIdentity(); |
| 7937 | try { |
| 7938 | Phone phone = getPhone(subId); |
| 7939 | if (phone != null) { |
| 7940 | return phone.isVideoEnabled(); |
| 7941 | } else { |
| 7942 | return false; |
| 7943 | } |
| 7944 | } finally { |
| 7945 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7946 | } |
| 7947 | } |
| 7948 | |
| 7949 | /** |
| 7950 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7951 | * defined in {@link ImsRegistrationImplBase}. |
| 7952 | */ |
| 7953 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7954 | final long identity = Binder.clearCallingIdentity(); |
| 7955 | try { |
| 7956 | Phone phone = getPhone(subId); |
| 7957 | if (phone != null) { |
| 7958 | return phone.getImsRegistrationTech(); |
| 7959 | } else { |
| 7960 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7961 | } |
| 7962 | } finally { |
| 7963 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7964 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7965 | } |
| 7966 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7967 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7968 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7969 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7970 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7971 | return; |
| 7972 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7973 | Phone defaultPhone = getDefaultPhone(); |
| 7974 | if (defaultPhone != null) { |
| 7975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7976 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7977 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7978 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7979 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7980 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7981 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7982 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7983 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7984 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7985 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7986 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7987 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7988 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7989 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7990 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7991 | // There has been issues when Sms raw table somehow stores orphan |
| 7992 | // fragments. They lead to garbled message when new fragments come |
| 7993 | // in and combined with those stale ones. In case this happens again, |
| 7994 | // user can reset all network settings which will clean up this table. |
| 7995 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7996 | // Clean up IMS settings as well here. |
| 7997 | int slotId = getSlotIndex(subId); |
| 7998 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7999 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8000 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8001 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8002 | if (defaultPhone == null) { |
| 8003 | return; |
| 8004 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8005 | // Erase modem config if erase modem on network setting is enabled. |
| 8006 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8007 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8008 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8009 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8010 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8011 | |
| 8012 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8013 | } finally { |
| 8014 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8015 | } |
| 8016 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8017 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8018 | @VisibleForTesting |
| 8019 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8020 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8021 | return; |
| 8022 | } |
| 8023 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8024 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8025 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8026 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8027 | "user=" + defaultNetworkType); |
| 8028 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8029 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8030 | defaultNetworkType, null); |
| 8031 | } |
| 8032 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8033 | private void cleanUpSmsRawTable(Context context) { |
| 8034 | ContentResolver resolver = context.getContentResolver(); |
| 8035 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8036 | resolver.delete(uri, null, null); |
| 8037 | } |
| 8038 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8039 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8040 | public String getSimLocaleForSubscriber(int subId) { |
| 8041 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8042 | final Phone phone = getPhone(subId); |
| 8043 | if (phone == null) { |
| 8044 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8045 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8046 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8047 | final long identity = Binder.clearCallingIdentity(); |
| 8048 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8049 | SubscriptionInfo info; |
| 8050 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8051 | info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8052 | phone.getContext().getOpPackageName(), |
| 8053 | phone.getContext().getAttributionTag()); |
| 8054 | if (info == null) { |
| 8055 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8056 | return null; |
| 8057 | } |
| 8058 | } else { |
| 8059 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 8060 | phone.getContext().getOpPackageName(), |
| 8061 | phone.getContext().getAttributionTag()); |
| 8062 | if (info == null) { |
| 8063 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8064 | return null; |
| 8065 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8067 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8068 | // preferences (EF-PL and EF-LI)... |
| 8069 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8070 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8071 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8072 | if (localeFromDefaultSim != null) { |
| 8073 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8074 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8075 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8076 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8077 | } else { |
| 8078 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8079 | } |
| 8080 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8081 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8082 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8083 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8084 | // the SIM and carrier preferences does not include a country we add the country |
| 8085 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8086 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8087 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8088 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8089 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8090 | } |
| 8091 | |
| 8092 | if (DBG) log("No locale found - returning null"); |
| 8093 | return null; |
| 8094 | } finally { |
| 8095 | Binder.restoreCallingIdentity(identity); |
| 8096 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8097 | } |
| 8098 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8099 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8100 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8101 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8102 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8103 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8104 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8105 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8106 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8107 | return localeTag; |
| 8108 | } |
| 8109 | } |
| 8110 | return inputLocale.toLanguageTag(); |
| 8111 | } |
| 8112 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8113 | /** |
| 8114 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8115 | */ |
| 8116 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8117 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8118 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8119 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8120 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8121 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8122 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8123 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8124 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8125 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8126 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8127 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8128 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8129 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8130 | * representing the state of the modem. |
| 8131 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8132 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8133 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8134 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8135 | */ |
| 8136 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8137 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8138 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8139 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8140 | |
| 8141 | final long identity = Binder.clearCallingIdentity(); |
| 8142 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8143 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8144 | } finally { |
| 8145 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8146 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8147 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8148 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8149 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8150 | // less than total activity duration. |
| 8151 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8152 | if (info == null) { |
| 8153 | return false; |
| 8154 | } |
| 8155 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8156 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8157 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8158 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8159 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8160 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8161 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8162 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8163 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8164 | } |
| 8165 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8166 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8167 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8168 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8169 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8170 | |
| 8171 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8172 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8173 | } |
| 8174 | |
| 8175 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8176 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8177 | rat, |
| 8178 | freq, |
| 8179 | info.getReceiveTimeMillis(rat, freq) |
| 8180 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8181 | } |
| 8182 | |
| 8183 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8184 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8185 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8186 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8187 | |
| 8188 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8189 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8190 | } |
| 8191 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8192 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8193 | rat, |
| 8194 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8195 | } |
| 8196 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8197 | /** |
| 8198 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8199 | * @param info recent ModemActivityInfo |
| 8200 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8201 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8202 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8203 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8204 | boolean matched; |
| 8205 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8206 | matched = false; |
| 8207 | int rat = info.getSpecificInfoRat(i); |
| 8208 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8209 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8210 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8211 | //if it already exists |
| 8212 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8213 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8214 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8215 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8216 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8217 | updateLastModemActivityInfo(info, rat, freq); |
| 8218 | matched = true; |
| 8219 | } |
| 8220 | } else { |
| 8221 | updateLastModemActivityInfo(info, rat); |
| 8222 | matched = true; |
| 8223 | } |
| 8224 | } |
| 8225 | } |
| 8226 | |
| 8227 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8228 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8229 | new ActivityStatsTechSpecificInfo( |
| 8230 | rat, |
| 8231 | freq, |
| 8232 | info.getTransmitTimeMillis(rat, freq), |
| 8233 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8234 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8235 | } |
| 8236 | } |
| 8237 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8238 | mLastModemActivitySpecificInfo = |
| 8239 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8240 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8241 | |
| 8242 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8243 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8244 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8245 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8246 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8247 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8248 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8249 | |
| 8250 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8251 | new ModemActivityInfo( |
| 8252 | mLastModemActivityInfo.getTimestampMillis(), |
| 8253 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8254 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8255 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8256 | } |
| 8257 | |
| 8258 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8259 | ActivityStatsTechSpecificInfo[] info) { |
| 8260 | int infoSize = info.length; |
| 8261 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8262 | for (int i = 0; i < infoSize; i++) { |
| 8263 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8264 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8265 | info[i].getTransmitTimeMillis(), |
| 8266 | (int) info[i].getReceiveTimeMillis()); |
| 8267 | } |
| 8268 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8269 | } |
| 8270 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8271 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8272 | * Returns the service state information on specified subscription. |
| 8273 | */ |
| 8274 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8275 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8276 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8277 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8279 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8280 | return null; |
| 8281 | } |
| 8282 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8283 | boolean hasFinePermission = false; |
| 8284 | boolean hasCoarsePermission = false; |
| 8285 | if (!renounceFineLocationAccess) { |
| 8286 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8287 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8288 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8289 | .setCallingPackage(callingPackage) |
| 8290 | .setCallingFeatureId(callingFeatureId) |
| 8291 | .setCallingPid(Binder.getCallingPid()) |
| 8292 | .setCallingUid(Binder.getCallingUid()) |
| 8293 | .setMethod("getServiceStateForSubscriber") |
| 8294 | .setLogAsInfo(true) |
| 8295 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8296 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8297 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8298 | .build()); |
| 8299 | hasFinePermission = |
| 8300 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8301 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8302 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8303 | if (!renounceCoarseLocationAccess) { |
| 8304 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8305 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8306 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8307 | .setCallingPackage(callingPackage) |
| 8308 | .setCallingFeatureId(callingFeatureId) |
| 8309 | .setCallingPid(Binder.getCallingPid()) |
| 8310 | .setCallingUid(Binder.getCallingUid()) |
| 8311 | .setMethod("getServiceStateForSubscriber") |
| 8312 | .setLogAsInfo(true) |
| 8313 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8314 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8315 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8316 | .build()); |
| 8317 | hasCoarsePermission = |
| 8318 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8319 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8320 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8321 | final Phone phone = getPhone(subId); |
| 8322 | if (phone == null) { |
| 8323 | return null; |
| 8324 | } |
| 8325 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8326 | final long identity = Binder.clearCallingIdentity(); |
| 8327 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8328 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8329 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8330 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8331 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8332 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8333 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8334 | .getSubscriptionInfoInternal(subId); |
| 8335 | if (subInfo == null || !subInfo.isActive()) { |
| 8336 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8337 | + "subId=" + subId); |
| 8338 | return null; |
| 8339 | } |
| 8340 | } else { |
| 8341 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8342 | callingFeatureId)) { |
| 8343 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8344 | + "subId=" + subId); |
| 8345 | return null; |
| 8346 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8347 | } |
| 8348 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8349 | ServiceState ss = phone.getServiceState(); |
| 8350 | |
| 8351 | // Scrub out the location info in ServiceState depending on what level of access |
| 8352 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8353 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8354 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8355 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8356 | } finally { |
| 8357 | Binder.restoreCallingIdentity(identity); |
| 8358 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8359 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8360 | |
| 8361 | /** |
| 8362 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8363 | * |
| 8364 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8365 | * voicemail ringtone. |
| 8366 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8367 | * PhoneAccount. |
| 8368 | */ |
| 8369 | @Override |
| 8370 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8371 | final long identity = Binder.clearCallingIdentity(); |
| 8372 | try { |
| 8373 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8374 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8375 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8376 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8377 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8378 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8379 | } finally { |
| 8380 | Binder.restoreCallingIdentity(identity); |
| 8381 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8382 | } |
| 8383 | |
| 8384 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8385 | * Sets the per-account voicemail ringtone. |
| 8386 | * |
| 8387 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8388 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8389 | * |
| 8390 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8391 | * voicemail ringtone. |
| 8392 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8393 | * PhoneAccount. |
| 8394 | */ |
| 8395 | @Override |
| 8396 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8397 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8398 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8399 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8400 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8401 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8402 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8403 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8404 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8405 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8406 | |
| 8407 | final long identity = Binder.clearCallingIdentity(); |
| 8408 | try { |
| 8409 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8410 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8411 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8412 | } |
| 8413 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8414 | } finally { |
| 8415 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8416 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8417 | } |
| 8418 | |
| 8419 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8420 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8421 | * |
| 8422 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8423 | * voicemail vibration setting. |
| 8424 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8425 | */ |
| 8426 | @Override |
| 8427 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8428 | final long identity = Binder.clearCallingIdentity(); |
| 8429 | try { |
| 8430 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8431 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8432 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8433 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8434 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8435 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8436 | } finally { |
| 8437 | Binder.restoreCallingIdentity(identity); |
| 8438 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8439 | } |
| 8440 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8441 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8442 | * Sets the per-account voicemail vibration. |
| 8443 | * |
| 8444 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8445 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8446 | * |
| 8447 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8448 | * voicemail vibration setting. |
| 8449 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8450 | * specific PhoneAccount. |
| 8451 | */ |
| 8452 | @Override |
| 8453 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8454 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8455 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8456 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8457 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8458 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8460 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8461 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8462 | } |
| 8463 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8464 | final long identity = Binder.clearCallingIdentity(); |
| 8465 | try { |
| 8466 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8467 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8468 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8469 | } |
| 8470 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8471 | } finally { |
| 8472 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8473 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8474 | } |
| 8475 | |
| 8476 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8477 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8478 | * |
| 8479 | * @throws SecurityException if the caller does not have the required permission |
| 8480 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8481 | @VisibleForTesting |
| 8482 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8483 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8484 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8485 | } |
| 8486 | |
| 8487 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8488 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8489 | * permission. |
| 8490 | * |
| 8491 | * @throws SecurityException if the caller does not have the required permission |
| 8492 | */ |
| 8493 | private void enforceSendSmsPermission() { |
| 8494 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8495 | } |
| 8496 | |
| 8497 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8498 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8499 | * users permission. |
| 8500 | * |
| 8501 | * @throws SecurityException if the caller does not have the required permission |
| 8502 | */ |
| 8503 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8504 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8505 | } |
| 8506 | |
| 8507 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8508 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8509 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8510 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8511 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8512 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8513 | final long identity = Binder.clearCallingIdentity(); |
| 8514 | try { |
| 8515 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8516 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8517 | if (componentName == null) { |
| 8518 | throw new SecurityException( |
| 8519 | "Caller not current active visual voicemail package[null]"); |
| 8520 | } |
| 8521 | String vvmPackage = componentName.getPackageName(); |
| 8522 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8523 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8524 | } |
| 8525 | } finally { |
| 8526 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8527 | } |
| 8528 | } |
| 8529 | |
| 8530 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8531 | * Return the application ID for the app type. |
| 8532 | * |
| 8533 | * @param subId the subscription ID that this request applies to. |
| 8534 | * @param appType the uicc app type. |
| 8535 | * @return Application ID for specificied app type, or null if no uicc. |
| 8536 | */ |
| 8537 | @Override |
| 8538 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8539 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8540 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8541 | |
| 8542 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8543 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8544 | if (phone == null) { |
| 8545 | return null; |
| 8546 | } |
| 8547 | String aid = null; |
| 8548 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8549 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8550 | .getApplicationByType(appType).getAid(); |
| 8551 | } catch (Exception e) { |
| 8552 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8553 | } |
| 8554 | return aid; |
| 8555 | } finally { |
| 8556 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8557 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8558 | } |
| 8559 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8560 | /** |
| 8561 | * Return the Electronic Serial Number. |
| 8562 | * |
| 8563 | * @param subId the subscription ID that this request applies to. |
| 8564 | * @return ESN or null if error. |
| 8565 | */ |
| 8566 | @Override |
| 8567 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8568 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8569 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8570 | |
| 8571 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8572 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8573 | if (phone == null) { |
| 8574 | return null; |
| 8575 | } |
| 8576 | String esn = null; |
| 8577 | try { |
| 8578 | esn = phone.getEsn(); |
| 8579 | } catch (Exception e) { |
| 8580 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8581 | } |
| 8582 | return esn; |
| 8583 | } finally { |
| 8584 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8585 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8586 | } |
| 8587 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8588 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8589 | * Return the Preferred Roaming List Version. |
| 8590 | * |
| 8591 | * @param subId the subscription ID that this request applies to. |
| 8592 | * @return PRLVersion or null if error. |
| 8593 | */ |
| 8594 | @Override |
| 8595 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8596 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8597 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8598 | |
| 8599 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8600 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8601 | if (phone == null) { |
| 8602 | return null; |
| 8603 | } |
| 8604 | String cdmaPrlVersion = null; |
| 8605 | try { |
| 8606 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8607 | } catch (Exception e) { |
| 8608 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8609 | } |
| 8610 | return cdmaPrlVersion; |
| 8611 | } finally { |
| 8612 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8613 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8614 | } |
| 8615 | |
| 8616 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8617 | * Get snapshot of Telephony histograms |
| 8618 | * @return List of Telephony histograms |
| 8619 | * @hide |
| 8620 | */ |
| 8621 | @Override |
| 8622 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8623 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8624 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8625 | |
| 8626 | final long identity = Binder.clearCallingIdentity(); |
| 8627 | try { |
| 8628 | return RIL.getTelephonyRILTimingHistograms(); |
| 8629 | } finally { |
| 8630 | Binder.restoreCallingIdentity(identity); |
| 8631 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8632 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8633 | |
| 8634 | /** |
| 8635 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8636 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8637 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8638 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8639 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8640 | * @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] | 8641 | */ |
| 8642 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8643 | @TelephonyManager.SetCarrierRestrictionResult |
| 8644 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8645 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8646 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8647 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8648 | if (carrierRestrictionRules == null) { |
| 8649 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8650 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8651 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8652 | final long identity = Binder.clearCallingIdentity(); |
| 8653 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8654 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8655 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8656 | } finally { |
| 8657 | Binder.restoreCallingIdentity(identity); |
| 8658 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8659 | } |
| 8660 | |
| 8661 | /** |
| 8662 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8663 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8664 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8665 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8666 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8667 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8668 | */ |
| 8669 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8670 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8671 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8672 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8673 | |
| 8674 | final long identity = Binder.clearCallingIdentity(); |
| 8675 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8676 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8677 | if (response instanceof CarrierRestrictionRules) { |
| 8678 | return (CarrierRestrictionRules) response; |
| 8679 | } |
| 8680 | // Response is an Exception of some kind, |
| 8681 | // which is signalled to the user as a NULL retval |
| 8682 | return null; |
| 8683 | } catch (Exception e) { |
| 8684 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8685 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8686 | } finally { |
| 8687 | Binder.restoreCallingIdentity(identity); |
| 8688 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8689 | } |
| 8690 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8691 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8692 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8693 | * through the callback. |
| 8694 | * |
| 8695 | * @param callback The callback that will be used to send the result. |
| 8696 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8697 | * the caller is not allowlisted. |
| 8698 | */ |
| 8699 | @Override |
| 8700 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8701 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8702 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8703 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8704 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8705 | throw new SecurityException("Not an authorized caller"); |
| 8706 | } |
| 8707 | final long identity = Binder.clearCallingIdentity(); |
| 8708 | try { |
| 8709 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8710 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8711 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8712 | } finally { |
| 8713 | Binder.restoreCallingIdentity(identity); |
| 8714 | } |
| 8715 | } |
| 8716 | |
| 8717 | @VisibleForTesting |
| 8718 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8719 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8720 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8721 | } |
| 8722 | |
| 8723 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8724 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8725 | * @param subId the subscription ID that this action applies to. |
| 8726 | * @param enabled control enable or disable radio. |
| 8727 | * {@hide} |
| 8728 | */ |
| 8729 | @Override |
| 8730 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8731 | enforceModifyPermission(); |
| 8732 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8733 | |
| 8734 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8735 | if (phone == null) { |
| 8736 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8737 | return; |
| 8738 | } |
| 8739 | try { |
| 8740 | phone.carrierActionSetRadioEnabled(enabled); |
| 8741 | } catch (Exception e) { |
| 8742 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8743 | } finally { |
| 8744 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8745 | } |
| 8746 | } |
| 8747 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8748 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8749 | * Enable or disable Voice over NR (VoNR) |
| 8750 | * @param subId the subscription ID that this action applies to. |
| 8751 | * @param enabled enable or disable VoNR. |
| 8752 | * @return operation result. |
| 8753 | */ |
| 8754 | @Override |
| 8755 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8756 | enforceModifyPermission(); |
| 8757 | final Phone phone = getPhone(subId); |
| 8758 | |
| 8759 | final long identity = Binder.clearCallingIdentity(); |
| 8760 | if (phone == null) { |
| 8761 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8762 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8763 | } |
| 8764 | |
| 8765 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8766 | try { |
| 8767 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8768 | workSource); |
| 8769 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8770 | |
| 8771 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8772 | if (DBG) { |
| 8773 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8774 | } |
| 8775 | SubscriptionManager.setSubscriptionProperty( |
| 8776 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8777 | (enabled ? "1" : "0")); |
| 8778 | } |
| 8779 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8780 | return result; |
| 8781 | } finally { |
| 8782 | Binder.restoreCallingIdentity(identity); |
| 8783 | } |
| 8784 | } |
| 8785 | |
| 8786 | /** |
| 8787 | * Is voice over NR enabled |
| 8788 | * @return true if VoNR is enabled else false |
| 8789 | */ |
| 8790 | @Override |
| 8791 | public boolean isVoNrEnabled(int subId) { |
| 8792 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8793 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8794 | final long identity = Binder.clearCallingIdentity(); |
| 8795 | try { |
| 8796 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8797 | null, subId, workSource); |
| 8798 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8799 | return isEnabled; |
| 8800 | } finally { |
| 8801 | Binder.restoreCallingIdentity(identity); |
| 8802 | } |
| 8803 | } |
| 8804 | |
| 8805 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8806 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8807 | * network status based on which carrier apps could apply actions accordingly, |
| 8808 | * enable/disable default url handler for example. |
| 8809 | * |
| 8810 | * @param subId the subscription ID that this action applies to. |
| 8811 | * @param report control start/stop reporting the default network status. |
| 8812 | * {@hide} |
| 8813 | */ |
| 8814 | @Override |
| 8815 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8816 | enforceModifyPermission(); |
| 8817 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8818 | |
| 8819 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8820 | if (phone == null) { |
| 8821 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8822 | return; |
| 8823 | } |
| 8824 | try { |
| 8825 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8826 | } catch (Exception e) { |
| 8827 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8828 | } finally { |
| 8829 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8830 | } |
| 8831 | } |
| 8832 | |
| 8833 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8834 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8835 | * @param subId the subscription ID that this action applies to. |
| 8836 | * {@hide} |
| 8837 | */ |
| 8838 | @Override |
| 8839 | public void carrierActionResetAll(int subId) { |
| 8840 | enforceModifyPermission(); |
| 8841 | final Phone phone = getPhone(subId); |
| 8842 | if (phone == null) { |
| 8843 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8844 | return; |
| 8845 | } |
| 8846 | try { |
| 8847 | phone.carrierActionResetAll(); |
| 8848 | } catch (Exception e) { |
| 8849 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8850 | } |
| 8851 | } |
| 8852 | |
| 8853 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8854 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8855 | * bug report is being generated. |
| 8856 | */ |
| 8857 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8858 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8859 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8860 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8861 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8862 | + Binder.getCallingPid() |
| 8863 | + ", uid=" + Binder.getCallingUid() |
| 8864 | + "without permission " |
| 8865 | + android.Manifest.permission.DUMP); |
| 8866 | return; |
| 8867 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8868 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8869 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8870 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8871 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8872 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8873 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8874 | @NonNull String[] args) { |
| 8875 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8876 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8877 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8878 | } |
| 8879 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8880 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8881 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8882 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8883 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8884 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8885 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8886 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8887 | */ |
| 8888 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8889 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8890 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8891 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8892 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8893 | try { |
| 8894 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8895 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8896 | } catch (SecurityException se) { |
| 8897 | enforceModifyPermission(); |
| 8898 | } |
| 8899 | } else { |
| 8900 | enforceModifyPermission(); |
| 8901 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8902 | |
| 8903 | final long identity = Binder.clearCallingIdentity(); |
| 8904 | try { |
| 8905 | Phone phone = getPhone(subId); |
| 8906 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8907 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8908 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8909 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8910 | phone.getDataSettingsManager().setDataEnabled( |
| 8911 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8912 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8913 | } |
| 8914 | } finally { |
| 8915 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8916 | } |
| 8917 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8918 | |
| 8919 | /** |
| 8920 | * Get Client request stats |
| 8921 | * @return List of Client Request Stats |
| 8922 | * @hide |
| 8923 | */ |
| 8924 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8925 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8926 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8927 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8928 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8929 | return null; |
| 8930 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8931 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8932 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8933 | final long identity = Binder.clearCallingIdentity(); |
| 8934 | try { |
| 8935 | if (phone != null) { |
| 8936 | return phone.getClientRequestStats(); |
| 8937 | } |
| 8938 | |
| 8939 | return null; |
| 8940 | } finally { |
| 8941 | Binder.restoreCallingIdentity(identity); |
| 8942 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8943 | } |
| 8944 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8945 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8946 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8947 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8948 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8949 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8950 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8951 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8952 | // commands that plumb through the RIL as root, like so: |
| 8953 | // $ adb root |
| 8954 | // $ adb shell cmd phone ... |
| 8955 | packageName = "root"; |
| 8956 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8957 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8958 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8959 | |
| 8960 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8961 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8962 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8963 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8964 | * @param state State of SIM (power down, power up, pass through) |
| 8965 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8966 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8967 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8968 | * |
| 8969 | **/ |
| 8970 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8971 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8972 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8973 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8974 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8975 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8976 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8977 | final long identity = Binder.clearCallingIdentity(); |
| 8978 | try { |
| 8979 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8980 | phone.setSimPowerState(state, null, workSource); |
| 8981 | } |
| 8982 | } finally { |
| 8983 | Binder.restoreCallingIdentity(identity); |
| 8984 | } |
| 8985 | } |
| 8986 | |
| 8987 | /** |
| 8988 | * Set SIM card power state. |
| 8989 | * |
| 8990 | * @param slotIndex SIM slot id. |
| 8991 | * @param state State of SIM (power down, power up, pass through) |
| 8992 | * @param callback callback to trigger after success or failure |
| 8993 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8994 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8995 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8996 | * |
| 8997 | **/ |
| 8998 | @Override |
| 8999 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9000 | IIntegerConsumer callback) { |
| 9001 | enforceModifyPermission(); |
| 9002 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9003 | |
| 9004 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9005 | |
| 9006 | final long identity = Binder.clearCallingIdentity(); |
| 9007 | try { |
| 9008 | if (phone != null) { |
| 9009 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9010 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9011 | } |
| 9012 | } finally { |
| 9013 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9014 | } |
| 9015 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9016 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9017 | private boolean isUssdApiAllowed(int subId) { |
| 9018 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9019 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9020 | if (configManager == null) { |
| 9021 | return false; |
| 9022 | } |
| 9023 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9024 | if (pb == null) { |
| 9025 | return false; |
| 9026 | } |
| 9027 | return pb.getBoolean( |
| 9028 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9029 | } |
| 9030 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9031 | /** |
| 9032 | * Check if phone is in emergency callback mode |
| 9033 | * @return true if phone is in emergency callback mode |
| 9034 | * @param subId sub id |
| 9035 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9036 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9037 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9038 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9039 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9040 | |
| 9041 | final long identity = Binder.clearCallingIdentity(); |
| 9042 | try { |
| 9043 | if (phone != null) { |
| 9044 | return phone.isInEcm(); |
| 9045 | } else { |
| 9046 | return false; |
| 9047 | } |
| 9048 | } finally { |
| 9049 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9050 | } |
| 9051 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9052 | |
| 9053 | /** |
| 9054 | * Get the current signal strength information for the given subscription. |
| 9055 | * Because this information is not updated when the device is in a low power state |
| 9056 | * it should not be relied-upon to be current. |
| 9057 | * @param subId Subscription index |
| 9058 | * @return the most recent cached signal strength info from the modem |
| 9059 | */ |
| 9060 | @Override |
| 9061 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9062 | final long identity = Binder.clearCallingIdentity(); |
| 9063 | try { |
| 9064 | Phone p = getPhone(subId); |
| 9065 | if (p == null) { |
| 9066 | return null; |
| 9067 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9068 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9069 | return p.getSignalStrength(); |
| 9070 | } finally { |
| 9071 | Binder.restoreCallingIdentity(identity); |
| 9072 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9073 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9074 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9075 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9076 | * Get the current modem radio state for the given slot. |
| 9077 | * @param slotIndex slot index. |
| 9078 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9079 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9080 | * @return the current radio power state from the modem |
| 9081 | */ |
| 9082 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9083 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9084 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9085 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9086 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9087 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9088 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9089 | } |
| 9090 | |
| 9091 | final long identity = Binder.clearCallingIdentity(); |
| 9092 | try { |
| 9093 | return phone.getRadioPowerState(); |
| 9094 | } finally { |
| 9095 | Binder.restoreCallingIdentity(identity); |
| 9096 | } |
| 9097 | } |
| 9098 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9099 | } |
| 9100 | |
| 9101 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9102 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9103 | * |
| 9104 | * <p>Requires one of the following permissions: |
| 9105 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9106 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9107 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9108 | * privileges. |
| 9109 | * |
| 9110 | * @param subId subscription id |
| 9111 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9112 | * {@code false}. |
| 9113 | */ |
| 9114 | @Override |
| 9115 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9116 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9117 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9118 | try { |
| 9119 | mApp.enforceCallingOrSelfPermission( |
| 9120 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9121 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9122 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9123 | mApp.enforceCallingOrSelfPermission( |
| 9124 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9125 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9126 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9127 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9128 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9129 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9130 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9131 | boolean isEnabled = false; |
| 9132 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9133 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9134 | Phone phone = getPhone(subId); |
| 9135 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9136 | } finally { |
| 9137 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9138 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9139 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9140 | } |
| 9141 | |
| 9142 | |
| 9143 | /** |
| 9144 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9145 | * |
| 9146 | * <p> Requires permission: |
| 9147 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9148 | * privileges. |
| 9149 | * |
| 9150 | * @param subId subscription id |
| 9151 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9152 | */ |
| 9153 | @Override |
| 9154 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9156 | mApp, subId, "setDataRoamingEnabled"); |
| 9157 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9158 | final long identity = Binder.clearCallingIdentity(); |
| 9159 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9160 | Phone phone = getPhone(subId); |
| 9161 | if (phone != null) { |
| 9162 | phone.setDataRoamingEnabled(isEnabled); |
| 9163 | } |
| 9164 | } finally { |
| 9165 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9166 | } |
| 9167 | } |
| 9168 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9169 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9170 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9171 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9172 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9173 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9174 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9175 | boolean isAllowed = true; |
| 9176 | final long identity = Binder.clearCallingIdentity(); |
| 9177 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9178 | Phone phone = getPhone(subId); |
| 9179 | if (phone != null) { |
| 9180 | isAllowed = phone.isCspPlmnEnabled(); |
| 9181 | } |
| 9182 | } finally { |
| 9183 | Binder.restoreCallingIdentity(identity); |
| 9184 | } |
| 9185 | return isAllowed; |
| 9186 | } |
| 9187 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9188 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9189 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9190 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9191 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9192 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9193 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9194 | if (phone == null) { |
| 9195 | return false; |
| 9196 | } |
| 9197 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9198 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9199 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9200 | } |
| 9201 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9202 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9203 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9204 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9205 | mApp.getSystemService(AppOpsManager.class) |
| 9206 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9207 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9208 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9209 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9210 | try { |
| 9211 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9212 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9213 | } catch (SecurityException e) { |
| 9214 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9215 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9216 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9217 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9218 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9219 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9220 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9221 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9222 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9223 | Binder.getCallingUid())) { |
| 9224 | isIccIdAccessRestricted = true; |
| 9225 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9226 | final long identity = Binder.clearCallingIdentity(); |
| 9227 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9228 | UiccController uiccController = UiccController.getInstance(); |
| 9229 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9230 | if (hasReadPermission) { |
| 9231 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9232 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9233 | |
| 9234 | // Remove private info if the caller doesn't have access |
| 9235 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9236 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9237 | //setting the value after compatibility check |
| 9238 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9239 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9240 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9241 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9242 | if (card == null) { |
| 9243 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9244 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9245 | continue; |
| 9246 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9247 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9248 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9249 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9250 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9251 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9252 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9253 | for (UiccPortInfo portInfo : portInfos) { |
| 9254 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9255 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9256 | if (port == null) { |
| 9257 | // assume no access if port is null |
| 9258 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9259 | continue; |
| 9260 | } |
| 9261 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9262 | uiccPortInfos.add(portInfo); |
| 9263 | } else { |
| 9264 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9265 | } |
| 9266 | } |
| 9267 | filteredInfos.add(new UiccCardInfo( |
| 9268 | cardInfo.isEuicc(), |
| 9269 | cardInfo.getCardId(), |
| 9270 | null, |
| 9271 | cardInfo.getPhysicalSlotIndex(), |
| 9272 | cardInfo.isRemovable(), |
| 9273 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9274 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9275 | } |
| 9276 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9277 | } finally { |
| 9278 | Binder.restoreCallingIdentity(identity); |
| 9279 | } |
| 9280 | } |
| 9281 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9282 | /** |
| 9283 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9284 | * generally private and require carrier privileges to view. |
| 9285 | * |
| 9286 | * @hide |
| 9287 | */ |
| 9288 | @NonNull |
| 9289 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9290 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9291 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9292 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9293 | } |
| 9294 | return new UiccCardInfo( |
| 9295 | cardInfo.isEuicc(), |
| 9296 | cardInfo.getCardId(), |
| 9297 | null, |
| 9298 | cardInfo.getPhysicalSlotIndex(), |
| 9299 | cardInfo.isRemovable(), |
| 9300 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9301 | portinfo |
| 9302 | ); |
| 9303 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9304 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9305 | /** |
| 9306 | * @hide |
| 9307 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9308 | * These values are generally private and require carrier privileges to view. |
| 9309 | */ |
| 9310 | @NonNull |
| 9311 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9312 | return new UiccPortInfo( |
| 9313 | UiccPortInfo.ICCID_REDACTED, |
| 9314 | portInfo.getPortIndex(), |
| 9315 | portInfo.getLogicalSlotIndex(), |
| 9316 | portInfo.isActive() |
| 9317 | ); |
| 9318 | } |
| 9319 | @Override |
| 9320 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9321 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9322 | mApp.getSystemService(AppOpsManager.class) |
| 9323 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9324 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9325 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9326 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9327 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9328 | // we are reading iccId which is PII data. |
| 9329 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9330 | |
| 9331 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9332 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9333 | Binder.getCallingUid())) { |
| 9334 | isLogicalSlotAccessRestricted = true; |
| 9335 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9336 | final long identity = Binder.clearCallingIdentity(); |
| 9337 | try { |
| 9338 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9339 | if (slots == null || slots.length == 0) { |
| 9340 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9341 | return null; |
| 9342 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9343 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9344 | for (int i = 0; i < slots.length; i++) { |
| 9345 | UiccSlot slot = slots[i]; |
| 9346 | if (slot == null) { |
| 9347 | continue; |
| 9348 | } |
| 9349 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9350 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9351 | UiccCard card = slot.getUiccCard(); |
| 9352 | if (card != null) { |
| 9353 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9354 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9355 | cardId = slot.getEid(); |
| 9356 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9357 | // If cardId is null, use iccId of default port as cardId. |
| 9358 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9359 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9360 | } |
| 9361 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9362 | if (cardId != null) { |
| 9363 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9364 | // if cardId is an EID, it's all digits so this is fine |
| 9365 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9366 | } |
| 9367 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9368 | int cardState = 0; |
| 9369 | switch (slot.getCardState()) { |
| 9370 | case CARDSTATE_ABSENT: |
| 9371 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9372 | break; |
| 9373 | case CARDSTATE_PRESENT: |
| 9374 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9375 | break; |
| 9376 | case CARDSTATE_ERROR: |
| 9377 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9378 | break; |
| 9379 | case CARDSTATE_RESTRICTED: |
| 9380 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9381 | break; |
| 9382 | default: |
| 9383 | break; |
| 9384 | |
| 9385 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9386 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9387 | int[] portIndexes = slot.getPortList(); |
| 9388 | for (int portIdx : portIndexes) { |
| 9389 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9390 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9391 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9392 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9393 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9394 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9395 | slot.isEuicc(), |
| 9396 | cardId, |
| 9397 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9398 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9399 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9400 | //setting the value after compatibility check |
| 9401 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9402 | } |
| 9403 | return infos; |
| 9404 | } finally { |
| 9405 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9406 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9407 | } |
| 9408 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9409 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9410 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9411 | boolean hasReadPermission) { |
| 9412 | String iccId = slot.getIccId(portIndex); |
| 9413 | if (hasReadPermission) { // if has read permission |
| 9414 | return iccId; |
| 9415 | } else { |
| 9416 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9417 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9418 | // if no read permission, checking carrier privilege access |
| 9419 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9420 | return iccId; |
| 9421 | } |
| 9422 | } |
| 9423 | } |
| 9424 | // No read permission or carrier privilege access. |
| 9425 | return UiccPortInfo.ICCID_REDACTED; |
| 9426 | } |
| 9427 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9428 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9429 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9430 | public boolean switchSlots(int[] physicalSlots) { |
| 9431 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9432 | |
| 9433 | final long identity = Binder.clearCallingIdentity(); |
| 9434 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9435 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9436 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9437 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9438 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9439 | physicalSlots[i], i)); |
| 9440 | } |
| 9441 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9442 | } finally { |
| 9443 | Binder.restoreCallingIdentity(identity); |
| 9444 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9445 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9446 | |
| 9447 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9448 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9449 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9450 | enforceModifyPermission(); |
| 9451 | |
| 9452 | final long identity = Binder.clearCallingIdentity(); |
| 9453 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9454 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9455 | } finally { |
| 9456 | Binder.restoreCallingIdentity(identity); |
| 9457 | } |
| 9458 | } |
| 9459 | |
| 9460 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9461 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9462 | final long identity = Binder.clearCallingIdentity(); |
| 9463 | try { |
| 9464 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9465 | } finally { |
| 9466 | Binder.restoreCallingIdentity(identity); |
| 9467 | } |
| 9468 | } |
| 9469 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9470 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9471 | * A test API to reload the UICC profile. |
| 9472 | * |
| 9473 | * <p>Requires that the calling app has permission |
| 9474 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9475 | * @hide |
| 9476 | */ |
| 9477 | @Override |
| 9478 | public void refreshUiccProfile(int subId) { |
| 9479 | enforceModifyPermission(); |
| 9480 | |
| 9481 | final long identity = Binder.clearCallingIdentity(); |
| 9482 | try { |
| 9483 | Phone phone = getPhone(subId); |
| 9484 | if (phone == null) { |
| 9485 | return; |
| 9486 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9487 | UiccPort uiccPort = phone.getUiccPort(); |
| 9488 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9489 | return; |
| 9490 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9491 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9492 | if (uiccProfile == null) { |
| 9493 | return; |
| 9494 | } |
| 9495 | uiccProfile.refresh(); |
| 9496 | } finally { |
| 9497 | Binder.restoreCallingIdentity(identity); |
| 9498 | } |
| 9499 | } |
| 9500 | |
| 9501 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9502 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9503 | */ |
| 9504 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9505 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9506 | } |
| 9507 | |
| 9508 | /** |
| 9509 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9510 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9511 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9512 | */ |
| 9513 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9514 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9515 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9516 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9517 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9518 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9519 | return isDataRoamingEnabled; |
| 9520 | } |
| 9521 | |
| 9522 | /** |
| 9523 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9524 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9525 | */ |
| 9526 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9527 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9528 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9529 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9530 | return list.get(phoneId); |
| 9531 | } |
| 9532 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9533 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9534 | |
| 9535 | @Override |
| 9536 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9537 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9538 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9539 | |
| 9540 | final long identity = Binder.clearCallingIdentity(); |
| 9541 | try { |
| 9542 | final Phone phone = getPhone(subId); |
| 9543 | if (phone == null) { |
| 9544 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9545 | return; |
| 9546 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9547 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9548 | if (cpt != null) { |
| 9549 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9550 | } |
| 9551 | // 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] | 9552 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9553 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9554 | if (carrierPrivilegeRules == null) { |
| 9555 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9556 | } else { |
| 9557 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9558 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9559 | } finally { |
| 9560 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9561 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9562 | } |
| 9563 | |
| 9564 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9565 | public void setCarrierServicePackageOverride( |
| 9566 | int subId, String carrierServicePackage, String callingPackage) { |
| 9567 | TelephonyPermissions.enforceShellOnly( |
| 9568 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9569 | |
| 9570 | // Verify that the callingPackage belongs to the calling UID |
| 9571 | mApp.getSystemService(AppOpsManager.class) |
| 9572 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9573 | |
| 9574 | final long identity = Binder.clearCallingIdentity(); |
| 9575 | try { |
| 9576 | final Phone phone = getPhone(subId); |
| 9577 | if (phone == null || phone.getSubId() != subId) { |
| 9578 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9579 | throw new IllegalArgumentException("No phone for subid"); |
| 9580 | } |
| 9581 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9582 | if (cpt == null) { |
| 9583 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9584 | throw new IllegalStateException("No CPT for phone"); |
| 9585 | } |
| 9586 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9587 | } finally { |
| 9588 | Binder.restoreCallingIdentity(identity); |
| 9589 | } |
| 9590 | } |
| 9591 | |
| 9592 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9593 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9594 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9595 | |
| 9596 | final long identity = Binder.clearCallingIdentity(); |
| 9597 | try { |
| 9598 | final Phone phone = getPhone(subId); |
| 9599 | if (phone == null) { |
| 9600 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9601 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9602 | } |
| 9603 | return phone.getCarrierIdListVersion(); |
| 9604 | } finally { |
| 9605 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9606 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9607 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9608 | |
| 9609 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9610 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9611 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9612 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9613 | mApp, subId, callingPackage, callingFeatureId, |
| 9614 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9615 | return -1; |
| 9616 | } |
| 9617 | |
| 9618 | final long identity = Binder.clearCallingIdentity(); |
| 9619 | try { |
| 9620 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9621 | } finally { |
| 9622 | Binder.restoreCallingIdentity(identity); |
| 9623 | } |
| 9624 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9625 | |
| 9626 | @Override |
| 9627 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9628 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9629 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9630 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9631 | |
| 9632 | final long identity = Binder.clearCallingIdentity(); |
| 9633 | try { |
| 9634 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9635 | } finally { |
| 9636 | Binder.restoreCallingIdentity(identity); |
| 9637 | } |
| 9638 | } |
| 9639 | |
| 9640 | @Override |
| 9641 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9643 | mApp, subId, "setCdmaRoamingMode"); |
| 9644 | |
| 9645 | final long identity = Binder.clearCallingIdentity(); |
| 9646 | try { |
| 9647 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9648 | } finally { |
| 9649 | Binder.restoreCallingIdentity(identity); |
| 9650 | } |
| 9651 | } |
| 9652 | |
| 9653 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9654 | public int getCdmaSubscriptionMode(int subId) { |
| 9655 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9656 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9657 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9658 | |
| 9659 | final long identity = Binder.clearCallingIdentity(); |
| 9660 | try { |
| 9661 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9662 | } finally { |
| 9663 | Binder.restoreCallingIdentity(identity); |
| 9664 | } |
| 9665 | } |
| 9666 | |
| 9667 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9668 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9670 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9671 | |
| 9672 | final long identity = Binder.clearCallingIdentity(); |
| 9673 | try { |
| 9674 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9675 | } finally { |
| 9676 | Binder.restoreCallingIdentity(identity); |
| 9677 | } |
| 9678 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9679 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9680 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9681 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9682 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9683 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9684 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9685 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9686 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9687 | } |
| 9688 | final long identity = Binder.clearCallingIdentity(); |
| 9689 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9690 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9691 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9692 | if (phone.getEmergencyNumberTracker() != null |
| 9693 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9694 | emergencyNumberListInternal.put( |
| 9695 | phone.getSubId(), |
| 9696 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9697 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9698 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9699 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9700 | } finally { |
| 9701 | Binder.restoreCallingIdentity(identity); |
| 9702 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9703 | } |
| 9704 | |
| 9705 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9706 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9707 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9708 | if (!exactMatch) { |
| 9709 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9710 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9711 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9712 | } |
| 9713 | final long identity = Binder.clearCallingIdentity(); |
| 9714 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9715 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9716 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9717 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9718 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9719 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9720 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9721 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9722 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9723 | } |
| 9724 | return false; |
| 9725 | } finally { |
| 9726 | Binder.restoreCallingIdentity(identity); |
| 9727 | } |
| 9728 | } |
| 9729 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9730 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9731 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9732 | */ |
| 9733 | @Override |
| 9734 | public void startEmergencyCallbackMode() { |
| 9735 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9736 | "startEmergencyCallbackMode"); |
| 9737 | enforceModifyPermission(); |
| 9738 | final long identity = Binder.clearCallingIdentity(); |
| 9739 | try { |
| 9740 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9741 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9742 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9743 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9744 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9745 | gsmCdmaPhone.obtainMessage( |
| 9746 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9747 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9748 | } |
| 9749 | } |
| 9750 | } finally { |
| 9751 | Binder.restoreCallingIdentity(identity); |
| 9752 | } |
| 9753 | } |
| 9754 | |
| 9755 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9756 | * Update emergency number list for test mode. |
| 9757 | */ |
| 9758 | @Override |
| 9759 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9760 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9761 | "updateEmergencyNumberListTestMode"); |
| 9762 | |
| 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
| 9765 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9766 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9767 | if (tracker != null) { |
| 9768 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9769 | } |
| 9770 | } |
| 9771 | } finally { |
| 9772 | Binder.restoreCallingIdentity(identity); |
| 9773 | } |
| 9774 | } |
| 9775 | |
| 9776 | /** |
| 9777 | * Get the full emergency number list for test mode. |
| 9778 | */ |
| 9779 | @Override |
| 9780 | public List<String> getEmergencyNumberListTestMode() { |
| 9781 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9782 | "getEmergencyNumberListTestMode"); |
| 9783 | |
| 9784 | final long identity = Binder.clearCallingIdentity(); |
| 9785 | try { |
| 9786 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9787 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9788 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9789 | if (tracker != null) { |
| 9790 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9791 | emergencyNumbers.add(num.getNumber()); |
| 9792 | } |
| 9793 | } |
| 9794 | } |
| 9795 | return new ArrayList<>(emergencyNumbers); |
| 9796 | } finally { |
| 9797 | Binder.restoreCallingIdentity(identity); |
| 9798 | } |
| 9799 | } |
| 9800 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9801 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9802 | public int getEmergencyNumberDbVersion(int subId) { |
| 9803 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9804 | |
| 9805 | final long identity = Binder.clearCallingIdentity(); |
| 9806 | try { |
| 9807 | final Phone phone = getPhone(subId); |
| 9808 | if (phone == null) { |
| 9809 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9810 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9811 | } |
| 9812 | return phone.getEmergencyNumberDbVersion(); |
| 9813 | } finally { |
| 9814 | Binder.restoreCallingIdentity(identity); |
| 9815 | } |
| 9816 | } |
| 9817 | |
| 9818 | @Override |
| 9819 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9820 | enforceModifyPermission(); |
| 9821 | |
| 9822 | final long identity = Binder.clearCallingIdentity(); |
| 9823 | try { |
| 9824 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9825 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9826 | if (tracker != null) { |
| 9827 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9828 | } |
| 9829 | } |
| 9830 | } finally { |
| 9831 | Binder.restoreCallingIdentity(identity); |
| 9832 | } |
| 9833 | } |
| 9834 | |
| 9835 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9836 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9837 | enforceActiveEmergencySessionPermission(); |
| 9838 | |
| 9839 | final long identity = Binder.clearCallingIdentity(); |
| 9840 | try { |
| 9841 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9842 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9843 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9844 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9845 | } |
| 9846 | } |
| 9847 | } finally { |
| 9848 | Binder.restoreCallingIdentity(identity); |
| 9849 | } |
| 9850 | } |
| 9851 | |
| 9852 | @Override |
| 9853 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9854 | enforceActiveEmergencySessionPermission(); |
| 9855 | |
| 9856 | final long identity = Binder.clearCallingIdentity(); |
| 9857 | try { |
| 9858 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9859 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9860 | if (tracker != null) { |
| 9861 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9862 | } |
| 9863 | } |
| 9864 | } finally { |
| 9865 | Binder.restoreCallingIdentity(identity); |
| 9866 | } |
| 9867 | } |
| 9868 | |
| 9869 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9870 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9871 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9872 | Phone phone = getPhone(subId); |
| 9873 | if (phone == null) { |
| 9874 | return null; |
| 9875 | } |
| 9876 | final long identity = Binder.clearCallingIdentity(); |
| 9877 | try { |
| 9878 | UiccProfile profile = UiccController.getInstance() |
| 9879 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9880 | if (profile != null) { |
| 9881 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9882 | } |
| 9883 | } finally { |
| 9884 | Binder.restoreCallingIdentity(identity); |
| 9885 | } |
| 9886 | return null; |
| 9887 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9888 | |
| 9889 | /** |
| 9890 | * Enable or disable a modem stack. |
| 9891 | */ |
| 9892 | @Override |
| 9893 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9894 | enforceModifyPermission(); |
| 9895 | |
| 9896 | final long identity = Binder.clearCallingIdentity(); |
| 9897 | try { |
| 9898 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9899 | if (phone == null) { |
| 9900 | return false; |
| 9901 | } else { |
| 9902 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9903 | } |
| 9904 | } finally { |
| 9905 | Binder.restoreCallingIdentity(identity); |
| 9906 | } |
| 9907 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9908 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9909 | /** |
| 9910 | * Whether a modem stack is enabled or not. |
| 9911 | */ |
| 9912 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9913 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9914 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9915 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9916 | if (phone == null) return false; |
| 9917 | |
| 9918 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9919 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9920 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9921 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9922 | } |
| 9923 | |
| 9924 | final long identity = Binder.clearCallingIdentity(); |
| 9925 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9926 | try { |
| 9927 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9928 | } catch (NoSuchElementException ex) { |
| 9929 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9930 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9931 | } finally { |
| 9932 | Binder.restoreCallingIdentity(identity); |
| 9933 | } |
| 9934 | } |
| 9935 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9936 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9937 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9938 | enforceModifyPermission(); |
| 9939 | |
| 9940 | final long identity = Binder.clearCallingIdentity(); |
| 9941 | try { |
| 9942 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9943 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9944 | .commit(); |
| 9945 | } finally { |
| 9946 | Binder.restoreCallingIdentity(identity); |
| 9947 | } |
| 9948 | } |
| 9949 | |
| 9950 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9951 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9952 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9953 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9954 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9955 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9956 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9957 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9958 | |
| 9959 | final long identity = Binder.clearCallingIdentity(); |
| 9960 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9961 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9962 | } finally { |
| 9963 | Binder.restoreCallingIdentity(identity); |
| 9964 | } |
| 9965 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9966 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9967 | @TelephonyManager.IsMultiSimSupportedResult |
| 9968 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9969 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9970 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9971 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9972 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9973 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9974 | } |
| 9975 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9976 | // supported by the modem, indicate that it is restricted. |
| 9977 | PhoneCapability staticCapability = |
| 9978 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9979 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9980 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9981 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9982 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9983 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9984 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9985 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9986 | } |
| 9987 | // Check if support of multiple SIMs is restricted by carrier |
| 9988 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9989 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9990 | } |
| 9991 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9992 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9993 | } |
| 9994 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9995 | /** |
| 9996 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9997 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9998 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9999 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10000 | * @param numOfSims number of active sims we want to switch to |
| 10001 | */ |
| 10002 | @Override |
| 10003 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10004 | if (numOfSims == 1) { |
| 10005 | enforceModifyPermission(); |
| 10006 | } else { |
| 10007 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10008 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10009 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10010 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10011 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10012 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10013 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10014 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10015 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10016 | return; |
| 10017 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10018 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10019 | } finally { |
| 10020 | Binder.restoreCallingIdentity(identity); |
| 10021 | } |
| 10022 | } |
| 10023 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10024 | @Override |
| 10025 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10026 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10027 | Phone phone = getPhone(subId); |
| 10028 | if (phone == null) { |
| 10029 | return false; |
| 10030 | } |
| 10031 | final long identity = Binder.clearCallingIdentity(); |
| 10032 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10033 | UiccPort uiccPort = phone.getUiccPort(); |
| 10034 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10035 | return false; |
| 10036 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10037 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10038 | if (uiccProfile == null) { |
| 10039 | return false; |
| 10040 | } |
| 10041 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10042 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10043 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10044 | } |
| 10045 | return false; |
| 10046 | } finally { |
| 10047 | Binder.restoreCallingIdentity(identity); |
| 10048 | } |
| 10049 | } |
| 10050 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10051 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10052 | * Get whether making changes to modem configurations will trigger reboot. |
| 10053 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10054 | */ |
| 10055 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10056 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10057 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10058 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10059 | mApp, subId, callingPackage, callingFeatureId, |
| 10060 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10061 | return false; |
| 10062 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10063 | final long identity = Binder.clearCallingIdentity(); |
| 10064 | try { |
| 10065 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10066 | } finally { |
| 10067 | Binder.restoreCallingIdentity(identity); |
| 10068 | } |
| 10069 | } |
| 10070 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10071 | private void updateModemStateMetrics() { |
| 10072 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10073 | // TODO: check the state for each modem if the api is ready. |
| 10074 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10075 | } |
| 10076 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10077 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10078 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10079 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10080 | // Verify that the callingPackage belongs to the calling UID |
| 10081 | mApp.getSystemService(AppOpsManager.class) |
| 10082 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10083 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10084 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10085 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10086 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10087 | if (slotInfos != null) { |
| 10088 | for (int i = 0; i < slotInfos.length; i++) { |
| 10089 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10090 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10091 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10092 | portInfo.getLogicalSlotIndex())); |
| 10093 | } |
| 10094 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10095 | } |
| 10096 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10097 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10098 | } finally { |
| 10099 | Binder.restoreCallingIdentity(identity); |
| 10100 | } |
| 10101 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10102 | |
| 10103 | /** |
| 10104 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10105 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10106 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10107 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10108 | @Override |
| 10109 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10110 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10111 | } |
| 10112 | |
| 10113 | /** |
| 10114 | * Get the HAL Version of a specific service |
| 10115 | */ |
| 10116 | @Override |
| 10117 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10118 | Phone phone = getDefaultPhone(); |
| 10119 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10120 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10121 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10122 | return hv.major * 100 + hv.minor; |
| 10123 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10124 | |
| 10125 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10126 | * Get the current calling package name. |
| 10127 | * @return the current calling package name |
| 10128 | */ |
| 10129 | @Override |
| 10130 | public String getCurrentPackageName() { |
| 10131 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10132 | } |
| 10133 | |
| 10134 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10135 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10136 | * corresponding network requests on a subId. |
| 10137 | * |
| 10138 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10139 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10140 | * 2) APN is un-metered for this subscription, or |
| 10141 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10142 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10143 | * |
| 10144 | * @return whether data is allowed for a apn type. |
| 10145 | * |
| 10146 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10147 | */ |
| 10148 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10149 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10150 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10151 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10152 | |
| 10153 | // Now that all security checks passes, perform the operation as ourselves. |
| 10154 | final long identity = Binder.clearCallingIdentity(); |
| 10155 | try { |
| 10156 | Phone phone = getPhone(subId); |
| 10157 | if (phone == null) return false; |
| 10158 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10159 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10160 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10161 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10162 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10163 | phone.getServiceState().getDataRoaming()); |
| 10164 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10165 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10166 | } finally { |
| 10167 | Binder.restoreCallingIdentity(identity); |
| 10168 | } |
| 10169 | } |
| 10170 | |
| 10171 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10172 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10173 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10174 | |
| 10175 | // Now that all security checks passes, perform the operation as ourselves. |
| 10176 | final long identity = Binder.clearCallingIdentity(); |
| 10177 | try { |
| 10178 | Phone phone = getPhone(subId); |
| 10179 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10180 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10181 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10182 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10183 | } finally { |
| 10184 | Binder.restoreCallingIdentity(identity); |
| 10185 | } |
| 10186 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10187 | |
| 10188 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10189 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10190 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10191 | enforceModifyPermission(); |
| 10192 | long token = Binder.clearCallingIdentity(); |
| 10193 | try { |
| 10194 | Phone phone = getPhone(subscriptionId); |
| 10195 | if (phone == null) { |
| 10196 | try { |
| 10197 | if (resultCallback != null) { |
| 10198 | resultCallback.accept(false); |
| 10199 | } |
| 10200 | } catch (RemoteException e) { |
| 10201 | // ignore |
| 10202 | } |
| 10203 | return; |
| 10204 | } |
| 10205 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10206 | Pair.create(specifiers, (x) -> { |
| 10207 | try { |
| 10208 | if (resultCallback != null) { |
| 10209 | resultCallback.accept(x); |
| 10210 | } |
| 10211 | } catch (RemoteException e) { |
| 10212 | // ignore |
| 10213 | } |
| 10214 | }); |
| 10215 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10216 | } finally { |
| 10217 | Binder.restoreCallingIdentity(token); |
| 10218 | } |
| 10219 | } |
| 10220 | |
| 10221 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10222 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10223 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10224 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10225 | mApp, subId, "getSystemSelectionChannels"); |
| 10226 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10227 | final long identity = Binder.clearCallingIdentity(); |
| 10228 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10229 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10230 | if (result instanceof IllegalStateException) { |
| 10231 | throw (IllegalStateException) result; |
| 10232 | } |
| 10233 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10234 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10235 | return specifiers; |
| 10236 | } finally { |
| 10237 | Binder.restoreCallingIdentity(identity); |
| 10238 | } |
| 10239 | } |
| 10240 | |
| 10241 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10242 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10243 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10244 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10245 | } |
| 10246 | |
| 10247 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10248 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10249 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10250 | if (callingPackage == null) { |
| 10251 | callingPackage = getCurrentPackageName(); |
| 10252 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10253 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10254 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10255 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10256 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10257 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10258 | } |
| 10259 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10260 | Intent intent = new Intent(); |
| 10261 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10262 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10263 | // Bring up choose default SMS subscription dialog right now |
| 10264 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10265 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10266 | mApp.startActivity(intent); |
| 10267 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10268 | |
| 10269 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10270 | public void showSwitchToManagedProfileDialog() { |
| 10271 | enforceModifyPermission(); |
| 10272 | |
| 10273 | Intent intent = new Intent(); |
| 10274 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10275 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10276 | mApp.startActivity(intent); |
| 10277 | } |
| 10278 | |
| 10279 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10280 | public String getMmsUAProfUrl(int subId) { |
| 10281 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10282 | final long identity = Binder.clearCallingIdentity(); |
| 10283 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10284 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10285 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10286 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10287 | return carrierUAProfUrl; |
| 10288 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10289 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10290 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10291 | } finally { |
| 10292 | Binder.restoreCallingIdentity(identity); |
| 10293 | } |
| 10294 | } |
| 10295 | |
| 10296 | @Override |
| 10297 | public String getMmsUserAgent(int subId) { |
| 10298 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10299 | final long identity = Binder.clearCallingIdentity(); |
| 10300 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10301 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10302 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10303 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10304 | return carrierUserAgent; |
| 10305 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10306 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10307 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10308 | } finally { |
| 10309 | Binder.restoreCallingIdentity(identity); |
| 10310 | } |
| 10311 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10312 | |
| 10313 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10314 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10315 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10316 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10317 | final long identity = Binder.clearCallingIdentity(); |
| 10318 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10319 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10320 | if (phone == null) return false; |
| 10321 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10322 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10323 | } finally { |
| 10324 | Binder.restoreCallingIdentity(identity); |
| 10325 | } |
| 10326 | } |
| 10327 | |
| 10328 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10329 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10330 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10331 | enforceModifyPermission(); |
| 10332 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10333 | final long identity = Binder.clearCallingIdentity(); |
| 10334 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10335 | Phone phone = getPhone(subscriptionId); |
| 10336 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10337 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10338 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10339 | } finally { |
| 10340 | Binder.restoreCallingIdentity(identity); |
| 10341 | } |
| 10342 | } |
| 10343 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10344 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10345 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10346 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10347 | * otherwise. |
| 10348 | */ |
| 10349 | @Override |
| 10350 | public void setCepEnabled(boolean isCepEnabled) { |
| 10351 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10352 | |
| 10353 | final long identity = Binder.clearCallingIdentity(); |
| 10354 | try { |
| 10355 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10356 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10357 | Phone defaultPhone = phone.getImsPhone(); |
| 10358 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10359 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10360 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10361 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10362 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10363 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10364 | + imsPhone.getMsisdn()); |
| 10365 | } |
| 10366 | } |
| 10367 | } finally { |
| 10368 | Binder.restoreCallingIdentity(identity); |
| 10369 | } |
| 10370 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10371 | |
| 10372 | /** |
| 10373 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10374 | * |
| 10375 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10376 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10377 | * before being read. |
| 10378 | */ |
| 10379 | @Override |
| 10380 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10381 | isCompressed) { |
| 10382 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10383 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10384 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10385 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10386 | } |
| 10387 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10388 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10389 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10390 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10391 | } |
| 10392 | |
| 10393 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10394 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10395 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10396 | } finally { |
| 10397 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10398 | } |
| 10399 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10400 | |
| 10401 | @Override |
| 10402 | public boolean isIccLockEnabled(int subId) { |
| 10403 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10404 | |
| 10405 | // Now that all security checks passes, perform the operation as ourselves. |
| 10406 | final long identity = Binder.clearCallingIdentity(); |
| 10407 | try { |
| 10408 | Phone phone = getPhone(subId); |
| 10409 | if (phone != null && phone.getIccCard() != null) { |
| 10410 | return phone.getIccCard().getIccLockEnabled(); |
| 10411 | } else { |
| 10412 | return false; |
| 10413 | } |
| 10414 | } finally { |
| 10415 | Binder.restoreCallingIdentity(identity); |
| 10416 | } |
| 10417 | } |
| 10418 | |
| 10419 | /** |
| 10420 | * Set the ICC pin lock enabled or disabled. |
| 10421 | * |
| 10422 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10423 | * three cases: |
| 10424 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10425 | * successfully. |
| 10426 | * - Positive number and zero for remaining password attempts. |
| 10427 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10428 | * |
| 10429 | */ |
| 10430 | @Override |
| 10431 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10432 | enforceModifyPermission(); |
| 10433 | |
| 10434 | Phone phone = getPhone(subId); |
| 10435 | if (phone == null) { |
| 10436 | return 0; |
| 10437 | } |
| 10438 | // Now that all security checks passes, perform the operation as ourselves. |
| 10439 | final long identity = Binder.clearCallingIdentity(); |
| 10440 | try { |
| 10441 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10442 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10443 | return attemptsRemaining; |
| 10444 | |
| 10445 | } catch (Exception e) { |
| 10446 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10447 | } finally { |
| 10448 | Binder.restoreCallingIdentity(identity); |
| 10449 | } |
| 10450 | return 0; |
| 10451 | } |
| 10452 | |
| 10453 | /** |
| 10454 | * Change the ICC password used in ICC pin lock. |
| 10455 | * |
| 10456 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10457 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10458 | * - Positive number and zero for remaining password attempts. |
| 10459 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10460 | * |
| 10461 | */ |
| 10462 | @Override |
| 10463 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10464 | enforceModifyPermission(); |
| 10465 | |
| 10466 | Phone phone = getPhone(subId); |
| 10467 | if (phone == null) { |
| 10468 | return 0; |
| 10469 | } |
| 10470 | // Now that all security checks passes, perform the operation as ourselves. |
| 10471 | final long identity = Binder.clearCallingIdentity(); |
| 10472 | try { |
| 10473 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10474 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10475 | return attemptsRemaining; |
| 10476 | |
| 10477 | } catch (Exception e) { |
| 10478 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10479 | } finally { |
| 10480 | Binder.restoreCallingIdentity(identity); |
| 10481 | } |
| 10482 | return 0; |
| 10483 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10484 | |
| 10485 | /** |
| 10486 | * Request for receiving user activity notification |
| 10487 | */ |
| 10488 | @Override |
| 10489 | public void requestUserActivityNotification() { |
| 10490 | if (!mNotifyUserActivity.get() |
| 10491 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10492 | mNotifyUserActivity.set(true); |
| 10493 | } |
| 10494 | } |
| 10495 | |
| 10496 | /** |
| 10497 | * Called when userActivity is signalled in the power manager. |
| 10498 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10499 | */ |
| 10500 | @Override |
| 10501 | public void userActivity() { |
| 10502 | // *************************************** |
| 10503 | // * Inherited from PhoneWindowManager * |
| 10504 | // *************************************** |
| 10505 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10506 | // WITH ITS LOCKS HELD. |
| 10507 | // |
| 10508 | // This code must be VERY careful about the locks |
| 10509 | // it acquires. |
| 10510 | // In fact, the current code acquires way too many, |
| 10511 | // and probably has lurking deadlocks. |
| 10512 | |
| 10513 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10514 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10515 | } |
| 10516 | |
| 10517 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10518 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10519 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10520 | } |
| 10521 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10522 | |
| 10523 | @Override |
| 10524 | public boolean canConnectTo5GInDsdsMode() { |
| 10525 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10526 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10527 | |
| 10528 | @Override |
| 10529 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10530 | String callingFeatureId) { |
| 10531 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10532 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10533 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10534 | } |
| 10535 | |
| 10536 | Phone phone = getPhone(subId); |
| 10537 | if (phone == null) { |
| 10538 | throw new RuntimeException("phone is not available"); |
| 10539 | } |
| 10540 | // Now that all security checks passes, perform the operation as ourselves. |
| 10541 | final long identity = Binder.clearCallingIdentity(); |
| 10542 | try { |
| 10543 | return phone.getEquivalentHomePlmns(); |
| 10544 | } finally { |
| 10545 | Binder.restoreCallingIdentity(identity); |
| 10546 | } |
| 10547 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10548 | |
| 10549 | @Override |
| 10550 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10551 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10552 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10553 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10554 | if (radioInterfaceCapabilities == null) { |
| 10555 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10556 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10557 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10558 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10559 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10560 | @Override |
| 10561 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10562 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10563 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10564 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10565 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10566 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10567 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10568 | if (DBG) { |
| 10569 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10570 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10571 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10572 | } |
| 10573 | |
| 10574 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10575 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10576 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10577 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10578 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10579 | if (callback != null) { |
| 10580 | try { |
| 10581 | callback.onAuthenticationFailure( |
| 10582 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10583 | } catch (RemoteException exception) { |
| 10584 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10585 | } |
| 10586 | return; |
| 10587 | } |
| 10588 | } |
| 10589 | |
| 10590 | final long token = Binder.clearCallingIdentity(); |
| 10591 | try { |
| 10592 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10593 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10594 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10595 | } finally { |
| 10596 | Binder.restoreCallingIdentity(token); |
| 10597 | } |
| 10598 | } |
| 10599 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10600 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10601 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10602 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10603 | * requested radio power state will actually be set. See {@link |
| 10604 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10605 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10606 | * @param enable {@code true} if trying to turn radio on. |
| 10607 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10608 | * false}. |
| 10609 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10610 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10611 | boolean isPhoneAvailable = false; |
| 10612 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10613 | Phone phone = PhoneFactory.getPhone(i); |
| 10614 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10615 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10616 | isPhoneAvailable = true; |
| 10617 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10618 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10619 | |
| 10620 | // return true if successfully informed the phone object about the thermal radio power |
| 10621 | // request. |
| 10622 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10623 | } |
| 10624 | |
| 10625 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10626 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10627 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10628 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10629 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10630 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10631 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10632 | } |
| 10633 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10634 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10635 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10636 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10637 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10638 | } |
| 10639 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10640 | setDataEnabledForReason( |
| 10641 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10642 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10643 | if (isDataThrottlingSupported) { |
| 10644 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10645 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10646 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10647 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10648 | } else if (thermalMitigationResult |
| 10649 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10650 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10651 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10652 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10653 | } |
| 10654 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10655 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10656 | |
| 10657 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10658 | } |
| 10659 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10660 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10661 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10662 | for (String pckg : context.getResources() |
| 10663 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10664 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10665 | } |
| 10666 | } |
| 10667 | |
| 10668 | return sThermalMitigationAllowlistedPackages; |
| 10669 | } |
| 10670 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10671 | private boolean isAnyPhoneInEmergencyState() { |
| 10672 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10673 | if (tm.isInEmergencyCall()) { |
| 10674 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10675 | return true; |
| 10676 | } |
| 10677 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10678 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10679 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10680 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10681 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10682 | return true; |
| 10683 | } |
| 10684 | } |
| 10685 | |
| 10686 | return false; |
| 10687 | } |
| 10688 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10689 | /** |
| 10690 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10691 | * @param packageName name of package to be allowlisted |
| 10692 | * @param context |
| 10693 | */ |
| 10694 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10695 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10696 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10697 | } |
| 10698 | |
| 10699 | /** |
| 10700 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10701 | * @param packageName name of package to remove from allowlist |
| 10702 | * @param context |
| 10703 | */ |
| 10704 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10705 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10706 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10707 | } |
| 10708 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10709 | /** |
| 10710 | * Thermal mitigation request to control functionalities at modem. |
| 10711 | * |
| 10712 | * @param subId the id of the subscription. |
| 10713 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10714 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10715 | * |
| 10716 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10717 | */ |
| 10718 | @Override |
| 10719 | @ThermalMitigationResult |
| 10720 | public int sendThermalMitigationRequest( |
| 10721 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10722 | ThermalMitigationRequest thermalMitigationRequest, |
| 10723 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10724 | enforceModifyPermission(); |
| 10725 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10726 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10727 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10728 | .contains(callingPackage)) { |
| 10729 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10730 | + "calling package: " + callingPackage); |
| 10731 | } |
| 10732 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10733 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10734 | final long identity = Binder.clearCallingIdentity(); |
| 10735 | |
| 10736 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10737 | try { |
| 10738 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10739 | switch (thermalMitigationAction) { |
| 10740 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10741 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10742 | handleDataThrottlingRequest(subId, |
| 10743 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10744 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10745 | break; |
| 10746 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10747 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10748 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10749 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10750 | } |
| 10751 | |
| 10752 | // Ensure that radio is on. If not able to power on due to phone being |
| 10753 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10754 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10755 | thermalMitigationResult = |
| 10756 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10757 | break; |
| 10758 | } |
| 10759 | |
| 10760 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10761 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10762 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10763 | break; |
| 10764 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10765 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10766 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10767 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10768 | } |
| 10769 | |
| 10770 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10771 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10772 | Phone phone = getPhone(subId); |
| 10773 | if (phone == null) { |
| 10774 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10775 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10776 | break; |
| 10777 | } |
| 10778 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10779 | TelephonyConnectionService service = |
| 10780 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10781 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10782 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10783 | thermalMitigationResult = |
| 10784 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10785 | break; |
| 10786 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10787 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10788 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10789 | break; |
| 10790 | } |
| 10791 | } else { |
| 10792 | thermalMitigationResult = |
| 10793 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10794 | break; |
| 10795 | } |
| 10796 | |
| 10797 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10798 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10799 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10800 | thermalMitigationResult = |
| 10801 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10802 | break; |
| 10803 | } |
| 10804 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10805 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10806 | break; |
| 10807 | default: |
| 10808 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10809 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10810 | } |
| 10811 | } catch (IllegalArgumentException e) { |
| 10812 | throw e; |
| 10813 | } catch (Exception e) { |
| 10814 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10815 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10816 | } finally { |
| 10817 | Binder.restoreCallingIdentity(identity); |
| 10818 | } |
| 10819 | |
| 10820 | if (DBG) { |
| 10821 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10822 | + thermalMitigationResult); |
| 10823 | } |
| 10824 | |
| 10825 | return thermalMitigationResult; |
| 10826 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10827 | |
| 10828 | /** |
| 10829 | * Set the GbaService Package Name that Telephony will bind to. |
| 10830 | * |
| 10831 | * @param subId The sim that the GbaService is associated with. |
| 10832 | * @param packageName The name of the package to be replaced with. |
| 10833 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10834 | */ |
| 10835 | @Override |
| 10836 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10837 | enforceModifyPermission(); |
| 10838 | |
| 10839 | final long identity = Binder.clearCallingIdentity(); |
| 10840 | try { |
| 10841 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10842 | } finally { |
| 10843 | Binder.restoreCallingIdentity(identity); |
| 10844 | } |
| 10845 | } |
| 10846 | |
| 10847 | /** |
| 10848 | * Return the package name of the currently bound GbaService. |
| 10849 | * |
| 10850 | * @param subId The sim that the GbaService is associated with. |
| 10851 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10852 | */ |
| 10853 | @Override |
| 10854 | public String getBoundGbaService(int subId) { |
| 10855 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10856 | |
| 10857 | final long identity = Binder.clearCallingIdentity(); |
| 10858 | try { |
| 10859 | return getGbaManager(subId).getServicePackage(); |
| 10860 | } finally { |
| 10861 | Binder.restoreCallingIdentity(identity); |
| 10862 | } |
| 10863 | } |
| 10864 | |
| 10865 | /** |
| 10866 | * Set the release time for telephony to unbind GbaService. |
| 10867 | * |
| 10868 | * @param subId The sim that the GbaService is associated with. |
| 10869 | * @param interval The release time to unbind GbaService by millisecond. |
| 10870 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10871 | */ |
| 10872 | @Override |
| 10873 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10874 | enforceModifyPermission(); |
| 10875 | |
| 10876 | final long identity = Binder.clearCallingIdentity(); |
| 10877 | try { |
| 10878 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10879 | } finally { |
| 10880 | Binder.restoreCallingIdentity(identity); |
| 10881 | } |
| 10882 | } |
| 10883 | |
| 10884 | /** |
| 10885 | * Return the release time for telephony to unbind GbaService. |
| 10886 | * |
| 10887 | * @param subId The sim that the GbaService is associated with. |
| 10888 | * @return The release time to unbind GbaService by millisecond. |
| 10889 | */ |
| 10890 | @Override |
| 10891 | public int getGbaReleaseTime(int subId) { |
| 10892 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10893 | |
| 10894 | final long identity = Binder.clearCallingIdentity(); |
| 10895 | try { |
| 10896 | return getGbaManager(subId).getReleaseTime(); |
| 10897 | } finally { |
| 10898 | Binder.restoreCallingIdentity(identity); |
| 10899 | } |
| 10900 | } |
| 10901 | |
| 10902 | private GbaManager getGbaManager(int subId) { |
| 10903 | GbaManager instance = GbaManager.getInstance(subId); |
| 10904 | if (instance == null) { |
| 10905 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10906 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10907 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10908 | } |
| 10909 | return instance; |
| 10910 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10911 | |
| 10912 | /** |
| 10913 | * indicate whether the device and the carrier can support |
| 10914 | * RCS VoLTE single registration. |
| 10915 | */ |
| 10916 | @Override |
| 10917 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10918 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10919 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10920 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10921 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10922 | |
| 10923 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10924 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10925 | } |
| 10926 | |
| 10927 | final long identity = Binder.clearCallingIdentity(); |
| 10928 | try { |
| 10929 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10930 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10931 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10932 | if (isCapable != null) { |
| 10933 | return isCapable; |
| 10934 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10935 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10936 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10937 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10938 | } finally { |
| 10939 | Binder.restoreCallingIdentity(identity); |
| 10940 | } |
| 10941 | } |
| 10942 | |
| 10943 | /** |
| 10944 | * Register RCS provisioning callback. |
| 10945 | */ |
| 10946 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10947 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10948 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10949 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10950 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10951 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10952 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10953 | |
| 10954 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10955 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10956 | } |
| 10957 | if (!isImsAvailableOnDevice()) { |
| 10958 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10959 | "IMS not available on device."); |
| 10960 | } |
| 10961 | |
| 10962 | final long identity = Binder.clearCallingIdentity(); |
| 10963 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10964 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10965 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10966 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10967 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10968 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10969 | } finally { |
| 10970 | Binder.restoreCallingIdentity(identity); |
| 10971 | } |
| 10972 | } |
| 10973 | |
| 10974 | /** |
| 10975 | * Unregister RCS provisioning callback. |
| 10976 | */ |
| 10977 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10978 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10979 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10980 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10981 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10982 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10983 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10984 | |
| 10985 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10986 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10987 | } |
| 10988 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10989 | // operation failed silently |
| 10990 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10991 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10992 | } |
| 10993 | |
| 10994 | final long identity = Binder.clearCallingIdentity(); |
| 10995 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10996 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10997 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10998 | } finally { |
| 10999 | Binder.restoreCallingIdentity(identity); |
| 11000 | } |
| 11001 | } |
| 11002 | |
| 11003 | /** |
| 11004 | * trigger RCS reconfiguration. |
| 11005 | */ |
| 11006 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11007 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11008 | "triggerRcsReconfiguration", |
| 11009 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11010 | |
| 11011 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11012 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11013 | } |
| 11014 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11015 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11016 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11017 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11018 | } |
| 11019 | |
| 11020 | final long identity = Binder.clearCallingIdentity(); |
| 11021 | try { |
| 11022 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11023 | } finally { |
| 11024 | Binder.restoreCallingIdentity(identity); |
| 11025 | } |
| 11026 | } |
| 11027 | |
| 11028 | /** |
| 11029 | * Provide the client configuration parameters of the RCS application. |
| 11030 | */ |
| 11031 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11032 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11033 | "setRcsClientConfiguration", |
| 11034 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11035 | |
| 11036 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11037 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11038 | } |
| 11039 | if (!isImsAvailableOnDevice()) { |
| 11040 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11041 | "IMS not available on device."); |
| 11042 | } |
| 11043 | |
| 11044 | final long identity = Binder.clearCallingIdentity(); |
| 11045 | |
| 11046 | try { |
| 11047 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11048 | if (configBinder == null) { |
| 11049 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11050 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11051 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11052 | } else { |
| 11053 | configBinder.setRcsClientConfiguration(rcc); |
| 11054 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11055 | |
| 11056 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11057 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11058 | } catch (RemoteException e) { |
| 11059 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11060 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11061 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11062 | } finally { |
| 11063 | Binder.restoreCallingIdentity(identity); |
| 11064 | } |
| 11065 | } |
| 11066 | |
| 11067 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11068 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11069 | */ |
| 11070 | @Override |
| 11071 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11072 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11073 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11074 | |
| 11075 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11076 | } |
| 11077 | |
| 11078 | /** |
| 11079 | * Gets the test mode for RCS VoLTE single registration. |
| 11080 | */ |
| 11081 | @Override |
| 11082 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11083 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11084 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11085 | |
| 11086 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11087 | } |
| 11088 | |
| 11089 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11090 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11091 | */ |
| 11092 | @Override |
| 11093 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11094 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11095 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11096 | enforceModifyPermission(); |
| 11097 | |
| 11098 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11099 | : Boolean.parseBoolean(enabledStr); |
| 11100 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11101 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11102 | } |
| 11103 | |
| 11104 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11105 | * Sends a device to device communication message. Only usable via shell. |
| 11106 | * @param message message to send. |
| 11107 | * @param value message value. |
| 11108 | */ |
| 11109 | @Override |
| 11110 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11111 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11112 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11113 | enforceModifyPermission(); |
| 11114 | |
| 11115 | final long identity = Binder.clearCallingIdentity(); |
| 11116 | try { |
| 11117 | TelephonyConnectionService service = |
| 11118 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11119 | if (service == null) { |
| 11120 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11121 | return; |
| 11122 | } |
| 11123 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11124 | } finally { |
| 11125 | Binder.restoreCallingIdentity(identity); |
| 11126 | } |
| 11127 | } |
| 11128 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11129 | /** |
| 11130 | * Sets the specified device to device transport active. |
| 11131 | * @param transport The transport to set active. |
| 11132 | */ |
| 11133 | @Override |
| 11134 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11135 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11136 | "setActiveDeviceToDeviceTransport"); |
| 11137 | enforceModifyPermission(); |
| 11138 | |
| 11139 | final long identity = Binder.clearCallingIdentity(); |
| 11140 | try { |
| 11141 | TelephonyConnectionService service = |
| 11142 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11143 | if (service == null) { |
| 11144 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11145 | return; |
| 11146 | } |
| 11147 | service.setActiveDeviceToDeviceTransport(transport); |
| 11148 | } finally { |
| 11149 | Binder.restoreCallingIdentity(identity); |
| 11150 | } |
| 11151 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11152 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11153 | @Override |
| 11154 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11155 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11156 | "setDeviceToDeviceForceEnabled"); |
| 11157 | |
| 11158 | final long identity = Binder.clearCallingIdentity(); |
| 11159 | try { |
| 11160 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11161 | p -> { |
| 11162 | Phone thePhone = p.getImsPhone(); |
| 11163 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11164 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11165 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11166 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11167 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11168 | (ImsPhoneCallTracker) tracker; |
| 11169 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11170 | } |
| 11171 | } |
| 11172 | } |
| 11173 | ); |
| 11174 | } finally { |
| 11175 | Binder.restoreCallingIdentity(identity); |
| 11176 | } |
| 11177 | } |
| 11178 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11179 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11180 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11181 | */ |
| 11182 | @Override |
| 11183 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11184 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11185 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11186 | } |
| 11187 | |
| 11188 | /** |
| 11189 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11190 | */ |
| 11191 | @Override |
| 11192 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11193 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11194 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11195 | enforceModifyPermission(); |
| 11196 | |
| 11197 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11198 | : Boolean.parseBoolean(enabledStr); |
| 11199 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11200 | subId, enabled); |
| 11201 | } |
| 11202 | |
| 11203 | /** |
| 11204 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11205 | */ |
| 11206 | @Override |
| 11207 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11208 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11209 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11210 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11211 | |
| 11212 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11213 | * Overrides the ims feature validation result |
| 11214 | */ |
| 11215 | @Override |
| 11216 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11217 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11218 | "setImsFeatureValidationOverride"); |
| 11219 | |
| 11220 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11221 | : Boolean.parseBoolean(enabledStr); |
| 11222 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11223 | subId, enabled); |
| 11224 | } |
| 11225 | |
| 11226 | /** |
| 11227 | * Gets the ims feature validation override value |
| 11228 | */ |
| 11229 | @Override |
| 11230 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11231 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11232 | "getImsFeatureValidationOverride"); |
| 11233 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11234 | } |
| 11235 | |
| 11236 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11237 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11238 | * their mobile plan. |
| 11239 | */ |
| 11240 | @Override |
| 11241 | public String getMobileProvisioningUrl() { |
| 11242 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11243 | final long identity = Binder.clearCallingIdentity(); |
| 11244 | try { |
| 11245 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11246 | } finally { |
| 11247 | Binder.restoreCallingIdentity(identity); |
| 11248 | } |
| 11249 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11250 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11251 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11252 | * Get the EAB contact from the EAB database. |
| 11253 | */ |
| 11254 | @Override |
| 11255 | public String getContactFromEab(String contact) { |
| 11256 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11257 | enforceModifyPermission(); |
| 11258 | final long identity = Binder.clearCallingIdentity(); |
| 11259 | try { |
| 11260 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11261 | } finally { |
| 11262 | Binder.restoreCallingIdentity(identity); |
| 11263 | } |
| 11264 | } |
| 11265 | |
| 11266 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11267 | * Get the EAB capability from the EAB database. |
| 11268 | */ |
| 11269 | @Override |
| 11270 | public String getCapabilityFromEab(String contact) { |
| 11271 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11272 | enforceModifyPermission(); |
| 11273 | final long identity = Binder.clearCallingIdentity(); |
| 11274 | try { |
| 11275 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11276 | } finally { |
| 11277 | Binder.restoreCallingIdentity(identity); |
| 11278 | } |
| 11279 | } |
| 11280 | |
| 11281 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11282 | * Remove the EAB contacts from the EAB database. |
| 11283 | */ |
| 11284 | @Override |
| 11285 | public int removeContactFromEab(int subId, String contacts) { |
| 11286 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11287 | enforceModifyPermission(); |
| 11288 | final long identity = Binder.clearCallingIdentity(); |
| 11289 | try { |
| 11290 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11291 | } finally { |
| 11292 | Binder.restoreCallingIdentity(identity); |
| 11293 | } |
| 11294 | } |
| 11295 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11296 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11297 | public boolean getDeviceUceEnabled() { |
| 11298 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11299 | final long identity = Binder.clearCallingIdentity(); |
| 11300 | try { |
| 11301 | return mApp.getDeviceUceEnabled(); |
| 11302 | } finally { |
| 11303 | Binder.restoreCallingIdentity(identity); |
| 11304 | } |
| 11305 | } |
| 11306 | |
| 11307 | @Override |
| 11308 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11309 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11310 | final long identity = Binder.clearCallingIdentity(); |
| 11311 | try { |
| 11312 | mApp.setDeviceUceEnabled(isEnabled); |
| 11313 | } finally { |
| 11314 | Binder.restoreCallingIdentity(identity); |
| 11315 | } |
| 11316 | } |
| 11317 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11318 | /** |
| 11319 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11320 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11321 | */ |
| 11322 | // Used for SHELL command only right now. |
| 11323 | @Override |
| 11324 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11325 | List<String> featureTags) { |
| 11326 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11327 | "addUceRegistrationOverrideShell"); |
| 11328 | final long identity = Binder.clearCallingIdentity(); |
| 11329 | try { |
| 11330 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11331 | new ArraySet<>(featureTags)); |
| 11332 | } catch (ImsException e) { |
| 11333 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11334 | } finally { |
| 11335 | Binder.restoreCallingIdentity(identity); |
| 11336 | } |
| 11337 | } |
| 11338 | |
| 11339 | /** |
| 11340 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11341 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11342 | */ |
| 11343 | // Used for SHELL command only right now. |
| 11344 | @Override |
| 11345 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11346 | List<String> featureTags) { |
| 11347 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11348 | "removeUceRegistrationOverrideShell"); |
| 11349 | final long identity = Binder.clearCallingIdentity(); |
| 11350 | try { |
| 11351 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11352 | new ArraySet<>(featureTags)); |
| 11353 | } catch (ImsException e) { |
| 11354 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11355 | } finally { |
| 11356 | Binder.restoreCallingIdentity(identity); |
| 11357 | } |
| 11358 | } |
| 11359 | |
| 11360 | /** |
| 11361 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11362 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11363 | */ |
| 11364 | // Used for SHELL command only right now. |
| 11365 | @Override |
| 11366 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11367 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11368 | "clearUceRegistrationOverrideShell"); |
| 11369 | final long identity = Binder.clearCallingIdentity(); |
| 11370 | try { |
| 11371 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11372 | } catch (ImsException e) { |
| 11373 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11374 | } finally { |
| 11375 | Binder.restoreCallingIdentity(identity); |
| 11376 | } |
| 11377 | } |
| 11378 | |
| 11379 | /** |
| 11380 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11381 | */ |
| 11382 | // Used for SHELL command only right now. |
| 11383 | @Override |
| 11384 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11385 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11386 | "getLatestRcsContactUceCapabilityShell"); |
| 11387 | final long identity = Binder.clearCallingIdentity(); |
| 11388 | try { |
| 11389 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11390 | } catch (ImsException e) { |
| 11391 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11392 | } finally { |
| 11393 | Binder.restoreCallingIdentity(identity); |
| 11394 | } |
| 11395 | } |
| 11396 | |
| 11397 | /** |
| 11398 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11399 | * device does not have an active PUBLISH. |
| 11400 | */ |
| 11401 | // Used for SHELL command only right now. |
| 11402 | @Override |
| 11403 | public String getLastUcePidfXmlShell(int subId) { |
| 11404 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11405 | final long identity = Binder.clearCallingIdentity(); |
| 11406 | try { |
| 11407 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11408 | } catch (ImsException e) { |
| 11409 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11410 | } finally { |
| 11411 | Binder.restoreCallingIdentity(identity); |
| 11412 | } |
| 11413 | } |
| 11414 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11415 | /** |
| 11416 | * Remove UCE requests cannot be sent to the network status. |
| 11417 | */ |
| 11418 | // Used for SHELL command only right now. |
| 11419 | @Override |
| 11420 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11421 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11422 | final long identity = Binder.clearCallingIdentity(); |
| 11423 | try { |
| 11424 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11425 | } catch (ImsException e) { |
| 11426 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11427 | } finally { |
| 11428 | Binder.restoreCallingIdentity(identity); |
| 11429 | } |
| 11430 | } |
| 11431 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11432 | /** |
| 11433 | * Remove UCE requests cannot be sent to the network status. |
| 11434 | */ |
| 11435 | // Used for SHELL command only. |
| 11436 | @Override |
| 11437 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11438 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11439 | final long identity = Binder.clearCallingIdentity(); |
| 11440 | try { |
| 11441 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11442 | } catch (ImsException e) { |
| 11443 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11444 | } finally { |
| 11445 | Binder.restoreCallingIdentity(identity); |
| 11446 | } |
| 11447 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11448 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11449 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11450 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11451 | String callingPackage) { |
| 11452 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11453 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11454 | |
| 11455 | final int callingUid = Binder.getCallingUid(); |
| 11456 | // Verify that tha callingPackage belongs to the calling UID |
| 11457 | mApp.getSystemService(AppOpsManager.class) |
| 11458 | .checkPackage(callingUid, callingPackage); |
| 11459 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11460 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11461 | |
| 11462 | final long identity = Binder.clearCallingIdentity(); |
| 11463 | try { |
| 11464 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11465 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11466 | |
| 11467 | if (result instanceof IllegalStateException) { |
| 11468 | throw (IllegalStateException) result; |
| 11469 | } |
| 11470 | } finally { |
| 11471 | Binder.restoreCallingIdentity(identity); |
| 11472 | } |
| 11473 | } |
| 11474 | |
| 11475 | @Override |
| 11476 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11477 | String callingPackage) { |
| 11478 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11479 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11480 | |
| 11481 | final int callingUid = Binder.getCallingUid(); |
| 11482 | // Verify that tha callingPackage belongs to the calling UID |
| 11483 | mApp.getSystemService(AppOpsManager.class) |
| 11484 | .checkPackage(callingUid, callingPackage); |
| 11485 | |
| 11486 | final long identity = Binder.clearCallingIdentity(); |
| 11487 | try { |
| 11488 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11489 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11490 | |
| 11491 | if (result instanceof IllegalStateException) { |
| 11492 | throw (IllegalStateException) result; |
| 11493 | } |
| 11494 | } finally { |
| 11495 | Binder.restoreCallingIdentity(identity); |
| 11496 | } |
| 11497 | } |
| 11498 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11499 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11500 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11501 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11502 | // phone/system process do not have further restriction on request |
| 11503 | return; |
| 11504 | } |
| 11505 | |
| 11506 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11507 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11508 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11509 | context.enforceCallingOrSelfPermission( |
| 11510 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11511 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11512 | } |
| 11513 | |
| 11514 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11515 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11516 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11517 | || info.isEnabled()) { |
| 11518 | throw new IllegalArgumentException( |
| 11519 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11520 | } |
| 11521 | |
| 11522 | // Thresholds length for each RAN need in range. This has been validated in |
| 11523 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11524 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11525 | final int[] thresholds = info.getThresholds(); |
| 11526 | Objects.requireNonNull(thresholds); |
| 11527 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11528 | || thresholds.length |
| 11529 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11530 | throw new IllegalArgumentException( |
| 11531 | "thresholds length is out of range: " + thresholds.length); |
| 11532 | } |
| 11533 | } |
| 11534 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11535 | |
| 11536 | /** |
| 11537 | * Gets the current phone capability. |
| 11538 | * |
| 11539 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11540 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11541 | * It's used to evaluate possible phone config change, for example from single |
| 11542 | * SIM device to multi-SIM device. |
| 11543 | */ |
| 11544 | @Override |
| 11545 | public PhoneCapability getPhoneCapability() { |
| 11546 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11547 | final long identity = Binder.clearCallingIdentity(); |
| 11548 | try { |
| 11549 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11550 | } finally { |
| 11551 | Binder.restoreCallingIdentity(identity); |
| 11552 | } |
| 11553 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11554 | |
| 11555 | /** |
| 11556 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11557 | * required to be done shortly after the API is invoked. |
| 11558 | */ |
| 11559 | @Override |
| 11560 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11561 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11562 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11563 | enforceRebootPermission(); |
| 11564 | |
| 11565 | final long identity = Binder.clearCallingIdentity(); |
| 11566 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11567 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11568 | } finally { |
| 11569 | Binder.restoreCallingIdentity(identity); |
| 11570 | } |
| 11571 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11572 | |
| 11573 | /** |
| 11574 | * Request to get the current slicing configuration including URSP rules and |
| 11575 | * NSSAIs (configured, allowed and rejected). |
| 11576 | * |
| 11577 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11578 | */ |
| 11579 | @Override |
| 11580 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11581 | TelephonyPermissions |
| 11582 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11583 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11584 | |
| 11585 | final long identity = Binder.clearCallingIdentity(); |
| 11586 | try { |
| 11587 | Phone phone = getDefaultPhone(); |
| 11588 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11589 | } finally { |
| 11590 | Binder.restoreCallingIdentity(identity); |
| 11591 | } |
| 11592 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11593 | |
| 11594 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11595 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11596 | * |
| 11597 | * @param capability The premium capability to check. |
| 11598 | * @param subId The subId to check the premium capability for. |
| 11599 | * |
| 11600 | * @return Whether the given premium capability is available to purchase. |
| 11601 | */ |
| 11602 | @Override |
| 11603 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11604 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11605 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11606 | log("Premium capability " |
| 11607 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11608 | + " is not available for purchase due to missing permissions."); |
| 11609 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11610 | + "permission READ_BASIC_PHONE_STATE."); |
| 11611 | } |
| 11612 | |
| 11613 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11614 | if (phone == null) { |
| 11615 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11616 | return false; |
| 11617 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11618 | final long identity = Binder.clearCallingIdentity(); |
| 11619 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11620 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11621 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11622 | } finally { |
| 11623 | Binder.restoreCallingIdentity(identity); |
| 11624 | } |
| 11625 | } |
| 11626 | |
| 11627 | /** |
| 11628 | * Purchase the given premium capability from the carrier. |
| 11629 | * |
| 11630 | * @param capability The premium capability to purchase. |
| 11631 | * @param callback The result of the purchase request. |
| 11632 | * @param subId The subId to purchase the premium capability for. |
| 11633 | */ |
| 11634 | @Override |
| 11635 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11636 | log("purchasePremiumCapability: capability=" |
| 11637 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11638 | + getCurrentPackageName()); |
| 11639 | |
| 11640 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11641 | mApp, "purchasePremiumCapability")) { |
| 11642 | log("purchasePremiumCapability " |
| 11643 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11644 | + " failed due to missing permissions."); |
| 11645 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11646 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11647 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11648 | mApp, "purchasePremiumCapability")) { |
| 11649 | log("purchasePremiumCapability " |
| 11650 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11651 | + " failed due to missing permissions."); |
| 11652 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11653 | } |
| 11654 | |
| 11655 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11656 | if (phone == null) { |
| 11657 | try { |
| 11658 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11659 | callback.accept(result); |
| 11660 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11661 | } catch (RemoteException e) { |
| 11662 | String logStr = "Purchase premium capability " |
| 11663 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11664 | + " failed due to RemoteException handling null phone: " + e; |
| 11665 | if (DBG) log(logStr); |
| 11666 | AnomalyReporter.reportAnomaly( |
| 11667 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11668 | } |
| 11669 | return; |
| 11670 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11671 | |
| 11672 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11673 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11674 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11675 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11676 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11677 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11678 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11679 | |
| 11680 | boolean isVisible = false; |
| 11681 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11682 | if (am != null) { |
| 11683 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11684 | if (processes != null) { |
| 11685 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11686 | log("purchasePremiumCapability: process " + process.processName |
| 11687 | + "has importance " + process.importance); |
| 11688 | if (process.processName.equals(callingProcess) && process.importance |
| 11689 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11690 | isVisible = true; |
| 11691 | break; |
| 11692 | } |
| 11693 | } |
| 11694 | } |
| 11695 | } |
| 11696 | |
| 11697 | if (!isVisible) { |
| 11698 | try { |
| 11699 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11700 | callback.accept(result); |
| 11701 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11702 | } catch (RemoteException e) { |
| 11703 | String logStr = "Purchase premium capability " |
| 11704 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11705 | + " failed due to RemoteException handling background application: " + e; |
| 11706 | if (DBG) log(logStr); |
| 11707 | AnomalyReporter.reportAnomaly( |
| 11708 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11709 | } |
| 11710 | return; |
| 11711 | } |
| 11712 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11713 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11714 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11715 | } |
| 11716 | |
| 11717 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11718 | * Register an IMS connection state callback |
| 11719 | */ |
| 11720 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11721 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11722 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11723 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11724 | // ImsMmTelManager |
| 11725 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11726 | TelephonyPermissions |
| 11727 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11728 | mApp, subId, "registerImsStateCallback"); |
| 11729 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11730 | // ImsRcsManager or SipDelegateManager |
| 11731 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11732 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11733 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11734 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11735 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11736 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11737 | } |
| 11738 | |
| 11739 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11740 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11741 | "IMS not available on device."); |
| 11742 | } |
| 11743 | |
| 11744 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11745 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11746 | } |
| 11747 | |
| 11748 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11749 | if (controller == null) { |
| 11750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11751 | "IMS not available on device."); |
| 11752 | } |
| 11753 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11754 | if (callingPackage == null) { |
| 11755 | callingPackage = getCurrentPackageName(); |
| 11756 | } |
| 11757 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11758 | final long token = Binder.clearCallingIdentity(); |
| 11759 | try { |
| 11760 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11761 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11762 | } catch (ImsException e) { |
| 11763 | throw new ServiceSpecificException(e.getCode()); |
| 11764 | } finally { |
| 11765 | Binder.restoreCallingIdentity(token); |
| 11766 | } |
| 11767 | } |
| 11768 | |
| 11769 | /** |
| 11770 | * Unregister an IMS connection state callback |
| 11771 | */ |
| 11772 | @Override |
| 11773 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11774 | final long token = Binder.clearCallingIdentity(); |
| 11775 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11776 | if (controller == null) { |
| 11777 | return; |
| 11778 | } |
| 11779 | try { |
| 11780 | controller.unregisterImsStateCallback(cb); |
| 11781 | } finally { |
| 11782 | Binder.restoreCallingIdentity(token); |
| 11783 | } |
| 11784 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11785 | |
| 11786 | /** |
| 11787 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11788 | * |
| 11789 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11790 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11791 | * SecurityException. |
| 11792 | * If there is current registered network this value will be same as the registered cell |
| 11793 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11794 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11795 | * it will be cleared and null will be returned. |
| 11796 | * |
| 11797 | */ |
| 11798 | @Override |
| 11799 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11800 | String callingFeatureId) { |
| 11801 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11802 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11803 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11804 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11805 | .setCallingPackage(callingPackage) |
| 11806 | .setCallingFeatureId(callingFeatureId) |
| 11807 | .setCallingPid(Binder.getCallingPid()) |
| 11808 | .setCallingUid(Binder.getCallingUid()) |
| 11809 | .setMethod("getLastKnownCellIdentity") |
| 11810 | .setLogAsInfo(true) |
| 11811 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11812 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11813 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11814 | .build()); |
| 11815 | |
| 11816 | boolean hasFinePermission = |
| 11817 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11818 | if (!hasFinePermission |
| 11819 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11820 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11821 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11822 | } |
| 11823 | |
| 11824 | final long identity = Binder.clearCallingIdentity(); |
| 11825 | try { |
| 11826 | Phone phone = getPhone(subId); |
| 11827 | if (phone == null) return null; |
| 11828 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11829 | if (sst == null) return null; |
| 11830 | return sst.getLastKnownCellIdentity(); |
| 11831 | } finally { |
| 11832 | Binder.restoreCallingIdentity(identity); |
| 11833 | } |
| 11834 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11835 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11836 | /** |
| 11837 | * Sets the modem service class Name that Telephony will bind to. |
| 11838 | * |
| 11839 | * @param serviceName The class name of the modem service. |
| 11840 | * @return true if the operation is succeed, otherwise false. |
| 11841 | */ |
| 11842 | public boolean setModemService(String serviceName) { |
| 11843 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11844 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11846 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11847 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11848 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11849 | } |
| 11850 | |
| 11851 | /** |
| 11852 | * Return the class name of the currently bounded modem service. |
| 11853 | * |
| 11854 | * @return the class name of the modem service. |
| 11855 | */ |
| 11856 | public String getModemService() { |
| 11857 | String result; |
| 11858 | Log.d(LOG_TAG, "getModemService"); |
| 11859 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11860 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11861 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11862 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11863 | "getModemService"); |
| 11864 | result = mPhoneConfigurationManager.getModemService(); |
| 11865 | Log.d(LOG_TAG, "result = " + result); |
| 11866 | return result; |
| 11867 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11868 | |
| 11869 | @Override |
| 11870 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11871 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11872 | mApp.enforceCallingOrSelfPermission( |
| 11873 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11874 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11875 | |
| 11876 | final long identity = Binder.clearCallingIdentity(); |
| 11877 | try { |
| 11878 | Phone phone = getPhone(subId); |
| 11879 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11880 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11881 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11882 | phone.setVoiceServiceStateOverride(hasService); |
| 11883 | } finally { |
| 11884 | Binder.restoreCallingIdentity(identity); |
| 11885 | } |
| 11886 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11887 | |
| 11888 | /** |
| 11889 | * set removable eSIM as default eUICC. |
| 11890 | * |
| 11891 | * @hide |
| 11892 | */ |
| 11893 | @Override |
| 11894 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11895 | enforceModifyPermission(); |
| 11896 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11897 | |
| 11898 | final long identity = Binder.clearCallingIdentity(); |
| 11899 | try { |
| 11900 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11901 | } finally { |
| 11902 | Binder.restoreCallingIdentity(identity); |
| 11903 | } |
| 11904 | } |
| 11905 | |
| 11906 | /** |
| 11907 | * Returns whether the removable eSIM is default eUICC or not. |
| 11908 | * |
| 11909 | * @hide |
| 11910 | */ |
| 11911 | @Override |
| 11912 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11913 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11914 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11915 | |
| 11916 | final long identity = Binder.clearCallingIdentity(); |
| 11917 | try { |
| 11918 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11919 | } finally { |
| 11920 | Binder.restoreCallingIdentity(identity); |
| 11921 | } |
| 11922 | } |
| 11923 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11924 | /** |
| 11925 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11926 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11927 | * application currently configured for this user. |
| 11928 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11929 | * {@code null} if the functionality is not supported. |
| 11930 | * @hide |
| 11931 | */ |
| 11932 | @Override |
| 11933 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11934 | boolean updateIfNeeded) { |
| 11935 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11936 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11937 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11938 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11939 | UserHandle userHandle = null; |
| 11940 | final long identity = Binder.clearCallingIdentity(); |
| 11941 | try { |
| 11942 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11943 | } finally { |
| 11944 | Binder.restoreCallingIdentity(identity); |
| 11945 | } |
| 11946 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11947 | updateIfNeeded, userHandle); |
| 11948 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11949 | |
| 11950 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11951 | * Set whether the device is able to connect with null ciphering or integrity |
| 11952 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11953 | * and all new subscriptions after this. |
| 11954 | * |
| 11955 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11956 | * @hide |
| 11957 | */ |
| 11958 | @Override |
| 11959 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11960 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11961 | enforceModifyPermission(); |
| 11962 | checkForNullCipherAndIntegritySupport(); |
| 11963 | |
| 11964 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11965 | // for listening to these preference changes and applying them immediately. |
| 11966 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11967 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11968 | editor.apply(); |
| 11969 | |
| 11970 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11971 | phone.handleNullCipherEnabledChange(); |
| 11972 | } |
| 11973 | } |
| 11974 | |
| 11975 | |
| 11976 | /** |
| 11977 | * Get whether the device is able to connect with null ciphering or integrity |
| 11978 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11979 | * the state of the radio. |
| 11980 | * |
| 11981 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11982 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11983 | * version for this feature. |
| 11984 | * @hide |
| 11985 | */ |
| 11986 | @Override |
| 11987 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11988 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11989 | enforceReadPermission(); |
| 11990 | checkForNullCipherAndIntegritySupport(); |
| 11991 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11992 | } |
| 11993 | |
| 11994 | private void checkForNullCipherAndIntegritySupport() { |
| 11995 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11996 | throw new UnsupportedOperationException( |
| 11997 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11998 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11999 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12000 | throw new UnsupportedOperationException( |
| 12001 | "Null cipher and integrity operations unsupported by modem"); |
| 12002 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12003 | } |
| 12004 | |
| 12005 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12006 | * Get the SIM state for the slot index. |
| 12007 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12008 | * |
| 12009 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12010 | */ |
| 12011 | @Override |
| 12012 | @SimState |
| 12013 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12014 | IccCardConstants.State simState; |
| 12015 | if (slotIndex < 0) { |
| 12016 | simState = IccCardConstants.State.UNKNOWN; |
| 12017 | } else { |
| 12018 | Phone phone = null; |
| 12019 | try { |
| 12020 | phone = PhoneFactory.getPhone(slotIndex); |
| 12021 | } catch (IllegalStateException e) { |
| 12022 | // ignore |
| 12023 | } |
| 12024 | if (phone == null) { |
| 12025 | simState = IccCardConstants.State.UNKNOWN; |
| 12026 | } else { |
| 12027 | IccCard icc = phone.getIccCard(); |
| 12028 | if (icc == null) { |
| 12029 | simState = IccCardConstants.State.UNKNOWN; |
| 12030 | } else { |
| 12031 | simState = icc.getState(); |
| 12032 | } |
| 12033 | } |
| 12034 | } |
| 12035 | return simState.ordinal(); |
| 12036 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12037 | |
| 12038 | /** |
| 12039 | * Get current cell broadcast ranges. |
| 12040 | */ |
| 12041 | @Override |
| 12042 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12043 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12044 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12045 | "getCellBroadcastIdRanges"); |
| 12046 | final long identity = Binder.clearCallingIdentity(); |
| 12047 | try { |
| 12048 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12049 | } finally { |
| 12050 | Binder.restoreCallingIdentity(identity); |
| 12051 | } |
| 12052 | } |
| 12053 | |
| 12054 | /** |
| 12055 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12056 | * |
| 12057 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12058 | */ |
| 12059 | @Override |
| 12060 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12061 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12062 | @Nullable IIntegerConsumer callback) { |
| 12063 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12064 | "setCellBroadcastIdRanges"); |
| 12065 | final long identity = Binder.clearCallingIdentity(); |
| 12066 | try { |
| 12067 | Phone phone = getPhoneFromSubId(subId); |
| 12068 | if (DBG) { |
| 12069 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12070 | } |
| 12071 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12072 | if (callback != null) { |
| 12073 | try { |
| 12074 | callback.accept(result); |
| 12075 | } catch (RemoteException e) { |
| 12076 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12077 | } |
| 12078 | } |
| 12079 | }); |
| 12080 | } finally { |
| 12081 | Binder.restoreCallingIdentity(identity); |
| 12082 | } |
| 12083 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12084 | |
| 12085 | /** |
| 12086 | * Returns whether the device supports the domain selection service. |
| 12087 | * |
| 12088 | * @return {@code true} if the device supports the domain selection service. |
| 12089 | */ |
| 12090 | @Override |
| 12091 | public boolean isDomainSelectionSupported() { |
| 12092 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12093 | "isDomainSelectionSupported"); |
| 12094 | |
| 12095 | final long identity = Binder.clearCallingIdentity(); |
| 12096 | try { |
| 12097 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12098 | } finally { |
| 12099 | Binder.restoreCallingIdentity(identity); |
| 12100 | } |
| 12101 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12102 | |
| 12103 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12104 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12105 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12106 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12107 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12108 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12109 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12110 | * {@code false} to disable. |
| 12111 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12112 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12113 | * |
| 12114 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12115 | */ |
| 12116 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12117 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12118 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12119 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12120 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12121 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12122 | } |
| 12123 | |
| 12124 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12125 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12126 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12127 | * @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] | 12128 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12129 | * 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] | 12130 | * |
| 12131 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12132 | */ |
| 12133 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12134 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12135 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12136 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12137 | } |
| 12138 | |
| 12139 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12140 | * Request to get whether the satellite service demo mode is enabled. |
| 12141 | * |
| 12142 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12143 | * is enabled for. |
| 12144 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12145 | * if the request is successful or an error code if the request failed. |
| 12146 | * |
| 12147 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12148 | */ |
| 12149 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12150 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12151 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12152 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12153 | } |
| 12154 | |
| 12155 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12156 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12157 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12158 | * @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] | 12159 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12160 | * 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] | 12161 | */ |
| 12162 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12163 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12164 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12165 | } |
| 12166 | |
| 12167 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12168 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12169 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12170 | * @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] | 12171 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12172 | * 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] | 12173 | * |
| 12174 | * @throws SecurityException if the caller doesn't have required permission. |
| 12175 | */ |
| 12176 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12177 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12178 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12179 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12180 | } |
| 12181 | |
| 12182 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12183 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12184 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12185 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12186 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12187 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12188 | * @param resultCallback The callback to get the result of the request. |
| 12189 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12190 | * |
| 12191 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12192 | */ |
| 12193 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12194 | public void startSatelliteTransmissionUpdates(int subId, |
| 12195 | @NonNull IIntegerConsumer resultCallback, |
| 12196 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12197 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12198 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12199 | } |
| 12200 | |
| 12201 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12202 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12203 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12204 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12205 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12206 | * @param resultCallback The callback to get the result of the request. |
| 12207 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12208 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12209 | * |
| 12210 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12211 | */ |
| 12212 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12213 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12214 | @NonNull IIntegerConsumer resultCallback, |
| 12215 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12216 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12217 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12218 | } |
| 12219 | |
| 12220 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12221 | * Register the subscription with a satellite provider. |
| 12222 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12223 | * |
| 12224 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12225 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12226 | * gateway. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12227 | * @param regionId The region ID for the device's current location. |
| 12228 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12229 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12230 | * @return The signal transport used by the caller to cancel the provision request, |
| 12231 | * or {@code null} if the request failed. |
| 12232 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12233 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12234 | */ |
| 12235 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12236 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12237 | @NonNull String token, @NonNull String regionId, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12238 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12239 | return mSatelliteController.provisionSatelliteService(subId, token, regionId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12240 | } |
| 12241 | |
| 12242 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12243 | * Unregister the device/subscription with the satellite provider. |
| 12244 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12245 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12246 | * should report as deprovisioned. |
| 12247 | * |
| 12248 | * @param subId The subId of the subscription to be deprovisioned. |
| 12249 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12250 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12251 | * |
| 12252 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12253 | */ |
| 12254 | @Override |
| 12255 | public void deprovisionSatelliteService(int subId, |
| 12256 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12257 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12258 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12259 | } |
| 12260 | |
| 12261 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12262 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12263 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12264 | * @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] | 12265 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12266 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12267 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12268 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12269 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12270 | */ |
| 12271 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12272 | @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12273 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12274 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12275 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12276 | } |
| 12277 | |
| 12278 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12279 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12280 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12281 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12282 | * @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] | 12283 | * @param callback The callback that was passed to |
| 12284 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12285 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12286 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12287 | */ |
| 12288 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12289 | public void unregisterForSatelliteProvisionStateChanged( |
| 12290 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12291 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12292 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12293 | } |
| 12294 | |
| 12295 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12296 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12297 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12298 | * @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] | 12299 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12300 | * satellite provider if the request is successful or an error code if the |
| 12301 | * request failed. |
| 12302 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12303 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12304 | */ |
| 12305 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12306 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12307 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12308 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12309 | } |
| 12310 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12311 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12312 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12313 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12314 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12315 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12316 | * |
| 12317 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12318 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12319 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12320 | */ |
| 12321 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12322 | @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12323 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12324 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12325 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12326 | } |
| 12327 | |
| 12328 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12329 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12330 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12331 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12332 | * @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] | 12333 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12334 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12335 | * |
| 12336 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12337 | */ |
| 12338 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12339 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12340 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12341 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12342 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12343 | } |
| 12344 | |
| 12345 | /** |
| 12346 | * Register to receive incoming datagrams over satellite. |
| 12347 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12348 | * @param subId The subId of the subscription to register for incoming satellite datagrams. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12349 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12350 | * |
| 12351 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12352 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12353 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12354 | */ |
| 12355 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12356 | @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12357 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12358 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12359 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12360 | } |
| 12361 | |
| 12362 | /** |
| 12363 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12364 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12365 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12366 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12367 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame^] | 12368 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12369 | * |
| 12370 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12371 | */ |
| 12372 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12373 | public void unregisterForSatelliteDatagram(int subId, |
| 12374 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12375 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12376 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12377 | } |
| 12378 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12379 | /** |
| 12380 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12381 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12382 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12383 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12384 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12385 | * ILongConsumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12386 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12387 | * @param subId The subId of the subscription used for receiving datagrams. |
| 12388 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12389 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12390 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12391 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12392 | @Override |
| 12393 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12394 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12395 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12396 | } |
| 12397 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12398 | /** |
| 12399 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12400 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12401 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 12402 | * input to this method. Datagram received here will be passed down to modem without any |
| 12403 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12404 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12405 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 12406 | * @param datagramType datagram type indicating whether the datagram is of type |
| 12407 | * SOS_SMS or LOCATION_SHARING. |
| 12408 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 12409 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12410 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 12411 | * full screen mode. |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12412 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12413 | * |
| 12414 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12415 | */ |
| 12416 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12417 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 12418 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 12419 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12420 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12421 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 12422 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12423 | } |
| 12424 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12425 | /** |
| 12426 | * Request to get whether satellite communication is allowed for the current location. |
| 12427 | * |
| 12428 | * @param subId The subId of the subscription to check whether satellite communication is |
| 12429 | * allowed for the current location for. |
| 12430 | * @param result The result receiver that returns whether satellite communication is allowed |
| 12431 | * for the current location if the request is successful or an error code |
| 12432 | * if the request failed. |
| 12433 | * |
| 12434 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12435 | */ |
| 12436 | @Override |
| 12437 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 12438 | @NonNull ResultReceiver result) { |
| 12439 | enforceSatelliteCommunicationPermission( |
| 12440 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12441 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 12442 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12443 | } |
| 12444 | |
| 12445 | /** |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12446 | * Request to get the time after which the satellite will be visible |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12447 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12448 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12449 | * @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] | 12450 | * be visible if the request is successful or an error code if the request failed. |
| 12451 | * |
| 12452 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12453 | */ |
| 12454 | @Override |
| 12455 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 12456 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12457 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12458 | } |
| 12459 | |
| 12460 | private Phone getPhoneOrDefault(int subId, String caller) { |
| 12461 | Phone phone = getPhone(subId); |
| 12462 | if (phone == null) { |
| 12463 | loge(caller + " called with invalid subId: " + subId |
| 12464 | + ". Retrying with default phone."); |
| 12465 | phone = getDefaultPhone(); |
| 12466 | if (phone == null) { |
| 12467 | loge(caller + " failed with no phone object."); |
| 12468 | } |
| 12469 | } |
| 12470 | return phone; |
| 12471 | } |
| 12472 | |
| 12473 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12474 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12475 | * |
| 12476 | * <p>This method behaves in one of the following ways: |
| 12477 | * <ul> |
| 12478 | * <li>return true : if the calling package has the appop permission {@link |
| 12479 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12480 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12481 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12482 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12483 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12484 | * </ul> |
| 12485 | */ |
| 12486 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12487 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12488 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12489 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12490 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12491 | return true; |
| 12492 | } |
| 12493 | } |
| 12494 | return false; |
| 12495 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12496 | |
| 12497 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12498 | * @return The subscription manager service instance. |
| 12499 | */ |
| 12500 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12501 | return SubscriptionManagerService.getInstance(); |
| 12502 | } |
| 12503 | |
| 12504 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12505 | * Class binds the consumer[callback] and carrierId. |
| 12506 | */ |
| 12507 | private static class CallerCallbackInfo { |
| 12508 | private final Consumer<Integer> mConsumer; |
| 12509 | private final int mCarrierId; |
| 12510 | |
| 12511 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12512 | mConsumer = consumer; |
| 12513 | mCarrierId = carrierId; |
| 12514 | } |
| 12515 | |
| 12516 | public Consumer<Integer> getConsumer() { |
| 12517 | return mConsumer; |
| 12518 | } |
| 12519 | |
| 12520 | public int getCarrierId() { |
| 12521 | return mCarrierId; |
| 12522 | } |
| 12523 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12524 | } |